CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • importing events
Pages: [1]

Author Topic: importing events  (Read 1726 times)

josue

  • I post occasionally
  • **
  • Posts: 81
  • Karma: 7
    • PTP
  • CiviCRM version: 3.4.4, 4.1.1
  • CMS version: Drupal 6.24, Drupal 7.12
  • MySQL version: 5.0
  • PHP version: 5.2
importing events
March 03, 2010, 02:14:11 pm
hey folks,

struggling mightily to import a lot of events in civicrm.

i found http://wiki.civicrm.org/confluence/display/CRMDOC/Importing+Events, which is all i could find on importing events. and trying to implement this has been quite painful.

the process, according to above link, is to create an address record, a location id bloc for said address and then create the event. i can do the address and the location bloc. how do i create the event?

when i do:
Code: [Select]
$newEvent = civicrm_event_create( $params );

if (civicrm_error ( $newEvent )) {
        return $newEvent['error_message'];
} else {
echo "newEvent = " . $newEvent; }

i do not get an error message. i do get an array with 2 entries, but both are blank. i seem to be accessing the function, but nothing happens.

any thoughts? what am i missing?

josue

  • I post occasionally
  • **
  • Posts: 81
  • Karma: 7
    • PTP
  • CiviCRM version: 3.4.4, 4.1.1
  • CMS version: Drupal 6.24, Drupal 7.12
  • MySQL version: 5.0
  • PHP version: 5.2
Re: importing events
March 03, 2010, 03:12:39 pm
here is the full module:

Code: [Select]
<?php

function importevents_menu() {
        
$items['importevents'] = array(
                        
'title' => 'importevents',
                        
'description' => 'Import events.',
                        
'type' => MENU_NORMAL_ITEM,
                        
'page callback' => 'importevents_do',
                        
'access arguments' => array('administer site configuration'),
        );
return 
$items;
}


function 
importevents_do() {

        
civicrm_initialize(TRUE );
        require_once 
'CRM/Core/DAO.php';
        require_once 
'api/v2/Event.php';

        
$row = 1;
        
ini_set('auto_detect_line_endings',TRUE);

        
/*
        this is the name of the file to import; set it to your own file;
        */

if (($handle = fopen("name_of_file.csv", "r")) !== FALSE) {
    while ((
$data = fgetcsv($handle, 1000, ",")) !== FALSE) {

        
//seed the event type with a default in case it's not found in DB
        
$theType = 4; //this is type: meeting

        /* now create the location record: */
        /* deal w/ State/Province: */

        
$state_id = 0;
                
$sql_state = "select id from civicrm_state_province where abbreviation = '" . $data[6] . "' and country_id = 1228 ";
                
$params1 = array();
                
$state_id = 0;
                
$dao_state =& CRM_Core_DAO::executeQuery( $sql_state, $params1 );
                while ( 
$dao_state->fetch( ) ) {
                        
$state_id = $dao_state->id;
                }

        
/* now create the address record: */
        
$theSql = "INSERT INTO civicrm_address (location_type_id, is_primary, street_address, city , state_province_id, postal_code, country_id) values (1, 1, '$data[4]','$data[5]',$state_id, '$data[7]', 1228)";
        
$theAddressId = 0;
         
mysql_query($theSql);
         
$theAddressId = mysql_insert_id();

        
/* now insert the loc_block record */
        
$theSql = "INSERT INTO civicrm_loc_block (address_id) values ($theAddressId)";
                echo 
$theSql;
        
$theLocBlockId = 0;
                
mysql_query($theSql);
                
$theLocBlockId = mysql_insert_id();
                        echo 
"Location Block ID = " . $theLocBlockId;

        
/* now create the event */
        
$params = array(
                
'title'                    => $data[0],
                
'description'              => $data[1],
                
'event_type_id'            => $theType,
                
'is_public'                => '0',
                
'start_date'               =>  $data[2],
                
'end_date'                 => $data[3],
                
'is_online_registration'   => '0',
                
'event_full_text'          => 'Sorry, this event is full',
                
'is_monetary'              => '0',
                
'contribution_type_id'     => '0',
                
'loc_block_id'                  => $theLocBlockId,
                
'is_active'                     => '1',
                
'is_show_location'              => '1',
                
'default_role_id'               => '1',
                
'is_email_confirm'              => '0',
                
'is_pay_later'                  => '0',
                
'created_id'                    => '1'
        
);

        
/* now create the actual event. yay */

        
$newEvent = civicrm_event_create( $params );

fclose($handle);
}
}
}

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: importing events
March 03, 2010, 09:26:59 pm
Josue - haven't tried that module but might help you to review the unit test for the event api's:
http://svn.civicrm.org/civicrm/branches/v3.1/tests/phpunit/api/v2/EventTest.php
Protect your investment in CiviCRM by  becoming a Member!

josue

  • I post occasionally
  • **
  • Posts: 81
  • Karma: 7
    • PTP
  • CiviCRM version: 3.4.4, 4.1.1
  • CMS version: Drupal 6.24, Drupal 7.12
  • MySQL version: 5.0
  • PHP version: 5.2
Re: importing events
March 03, 2010, 09:58:46 pm
this is what the working module looks like. not sure what i was doing wrong but when i took the parameters from the unit test it worked!

Code: [Select]
<?php

function importevents_menu() {
        
$items['importevents'] = array(
                        
'title' => 'importevents',
                        
'description' => 'Import events.',
                        
'type' => MENU_NORMAL_ITEM,
                        
'page callback' => 'importevents_do',
                        
'access arguments' => array('administer site configuration'),
        );
return 
$items;
}


function 
importevents_do() {

        
civicrm_initialize(TRUE );
        require_once 
'CRM/Core/DAO.php';
        require_once 
'api/v2/Event.php';

        
$row = 1;
        
ini_set('auto_detect_line_endings',TRUE);

        
/*
        this is the name of the file to import; set it to your own file;
        */
if (($handle = fopen("/test_event.csv", "r")) !== FALSE) {
    while ((
$data = fgetcsv($handle, 1000, ",")) !== FALSE) {

        
//seed the event type with a default in case it's not found in DB
        
$theType = 4; //change to the event type id of your choice

        /* now create the location record: */
        /* deal w/ State/Province: */

        
$state_id = 0;
                
$sql_state = "select id from civicrm_state_province where abbreviation = '" . $data[6] . "' and country_id = 1228 ";
                
$params1 = array();
                
$state_id = 0;
                
$dao_state =& CRM_Core_DAO::executeQuery( $sql_state, $params1 );
                while ( 
$dao_state->fetch( ) ) {
                        
$state_id = $dao_state->id;
                }

        
/* now create the address record: */
        
$theSql = "INSERT INTO civicrm_address (location_type_id, is_primary, street_address, city , state_province_id, postal_code, country_id) values (1, 1, '$data[4]','$data[5]',$state_id, '$data[7]', 1228)";
        
$theAddressId = 0;
                
mysql_query($theSql);
                
$theAddressId = mysql_insert_id();

        
/* now insert the loc_block record; we will update this below w/ the event id */
        
$theSql = "INSERT INTO civicrm_loc_block (address_id) values ($theAddressId)";
        
$theLocBlockId = 0;
                
mysql_query($theSql);
                
$theLocBlockId = mysql_insert_id();

        
/* now create the event */
    
$params = array(
                    
'title'                   => $data[0],
                    
//'summary'                 => 'If you have any CiviCRM related issues ,Sign Up Now!!',
                    
'description'             => $data[1],
                    
'event_type_id'           => 4,
                    
'is_public'               => 0,
                    
'start_date'              => $data[2],
                    
'end_date'                => $data[3],
                    
'is_online_registration'  => 0,
                    
//'registration_start_date' => 20080601,
                    //'registration_end_date'   => 20081015,
                    //'max_participants'        => 100,
                    
'event_full_text'         => 'Sorry! We are already full',
                    
'is_monetory'             => 0,
                    
'is_active'               => 1,
                    
'is_show_location'        => 1,
                    
'loc_block_id'            => $theLocBlockId,
                    );
    
$result = civicrm_event_create( $params );
    if ( 
civicrm_error( $result )) {
        return 
$result['error_message'];
    } else {
        
print_r($result);
    }

}
fclose($handle);
}
}

i put this module in the civicrm/drupal/module forlder. enabled it in the drupal admin section and went to the url: http://mysite.org/importevents and it created a whole bunch of events. yay!

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: importing events
September 01, 2011, 09:14:36 pm
Hi Josue - just wondering if anything has changed with regard to this before we give it a whirl - or if the module is available in a repository?

Just exploring options for D7/C4 Thanks
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: importing events
September 01, 2011, 10:48:54 pm
@peterdnz, obviously, needs to upgrade to api v3 ;) The code is also quite us centric (eg. when fetching the state), and now you can avoid most of the sql and use the ... did I mention the api already?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: importing events
September 01, 2011, 10:52:25 pm
yes you mentioned the api - now is there anyone around here who knows anything about the api
 ::)
umm nope
also for 90 events where most are using same location it is looking more like something to pass to a needy student ;-)
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: importing events
September 01, 2011, 11:30:54 pm
Can put you in touch with a smart women in NZ that seems to know a thing or two about API ;)

I haven't tried with events & addresses, but bin/csv/import.php might do the trick.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • importing events

This forum was archived on 2017-11-26.