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) »
  • API Issue
Pages: [1]

Author Topic: API Issue  (Read 1977 times)

FredJones

  • Guest
API Issue
January 08, 2008, 11:30:27 am
I have code like this:

Code: [Select]
$params = array(
'title'                    => $node->title,
// 'summary'                  => $node->field_event_summary[0]['value'],
'description'              => $node->body,
'event_type_id'            => '3',
'is_public'                => '1',
'start_date'               =>  $start_date,
'end_date'                 =>  $end_date,
'is_online_registration'   => '0',
'registration_link_text'   => 'link',
// 'max_participants'         => '150',
'event_full_text'          => 'Sorry, this event is full',
'is_monetary'              => '0',
'contribution_type_id'     => 'NULL',
'payment_processor_id'     => '1',
'fee_label'                => 'Event Fee(s)',
'domain_id'                => '1',
'is_active'                => (int)$node->status
);
$newEvent = & crm_create_event( $params );

and it works 90%. The event goes into the DB and I can then edit it via CiviCRM, BUT if I go to mysite.com/civicrm/event/info?reset=1&id=xx where xx is the id of this newly created event then it fails. I looked into this for some time and discovered that if I edit the event via the web interface, then that URL will work. After more debugging and looking at how the DB changes when I edit the event I found a solution. I found that even if I just open the 'Event Fees' page and leave the 'No' checked and submit, that suddenly the URL above works.

So I found that if I add these two lines:

Code: [Select]
$civicrm_event_id = $newEvent['id'];
require_once 'CRM/Core/DAO.php';
$dao =& CRM_Core_DAO::executeQuery( "insert into `civicrm_event_page`( `event_id` ) values (  '$civicrm_event_id' ); ");

and thereby manually create a record in civicrm_event_page then the URL works.

Is this expected behavior? I am unable to reproduce this on demo as I don't have any way (AFAIK) to access the API there.

I also see that when I call:

Code: [Select]
$civicrm_event_id = & crm_delete_event( $civicrm_event_id );

that the record in civicrm_event_page is indeed deleted. So it would appear to me (in my limited logic) that such a record should be created when I insert via API also.
« Last Edit: January 08, 2008, 11:38:21 am by FredJones »

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: API Issue
January 08, 2008, 11:36:04 pm
Currently Event api "crm_create_event" supports only creation Events and not Online Event Registration pages.

So it makes entry only in civicrm_event table.

civicrm_event_page table stores details related to online page.

HTH

kurund
Found this reply helpful? Support CiviCRM

FredJones

  • Guest
Re: API Issue
January 09, 2008, 08:45:06 am
Quote from: Kurund Jalmi on January 08, 2008, 11:36:04 pm
Currently Event api "crm_create_event" supports only creation Events and not Online Event Registration pages.

So it makes entry only in civicrm_event table.

Well, this seems odd to me b/c creating an event using the regular web interface automatically creates the Event page. Note that in my case I have no user registration, so I am not talking about an actual REGISTRATION page, just the page to view the information about the event--THAT page is made available automatically when I make an event via the browser, but not via the API. I do think this is a bug.

But now I am finding another issue. I use these params

Code: [Select]
Array
(
    [title] => 23
    [description] =>
    [event_type_id] => 3
    [is_public] => 1
    [start_date] => 20080101
    [end_date] => 20080131
    [is_online_registration] => 0
    [registration_link_text] => link
    [event_full_text] => Sorry, this event is full
    [is_monetary] => 0
    [contribution_type_id] => NULL
    [payment_processor_id] => 1
    [fee_label] => Event Fee(s)
    [domain_id] => 1
    [is_active] => 1
)

to create an event via:

Code: [Select]
$newEvent = & crm_create_event( $params );

Then I use these:

Code: [Select]
Array
(
    [title] => b
    [description] =>
    [event_type_id] => 3
    [is_public] => 1
    [start_date] => 20080110
    [end_date] => 20080115
    [is_online_registration] => 0
    [registration_link_text] => link
    [event_full_text] => Sorry, this event is full
    [is_monetary] => 0
    [contribution_type_id] => NULL
    [payment_processor_id] => 1
    [fee_label] => Event Fee(s)
    [domain_id] => 1
    [is_active] => 1
    [id] => 70
)

to update that event via:

Code: [Select]
$civicrm_event_id = & crm_update_event( $params );

But when I do the update, the dates are lost in CiviCRM and the URL /civicrm/event/info?reset=1&id=73 shows "When       0th, 0 12:00 AM    through    10:37 AM" which is quite odd. For events when I create yet don't update it shows "When       February 2nd, 2008 2:45 PM    through    April 2nd, 2008 2:45 PM" which is expected (if those were the dates inputted).

I also see now that I was using

Code: [Select]
require_once 'api/v2/Event.php';

but it seems that the API calls I am making are actually not v2, they are v1. Mine start with crm_ not civicrm_. I see that if I use:

Code: [Select]
require_once 'api/Event.php';

instead the results for both create and update are the same as described above. I am actually mildly confused because I was including v2 yet using v1 and the v1 calls worked. I think I am missing something here. As far as I can see the v2 file doesn't actually have an update method.

I used this page http://fisheye.civicrm.org/browse/CiviCRM/trunk/test/CRM/api/v2/Event.php?r=9724 as a sample for my code.

I am using version "1.9.11960 Drupal PHP5".

Thanks.

FredJones

  • Guest
Re: API Issue
January 10, 2008, 07:16:12 am
No further thoughts on these issues? I think I will just use an SQL update instead of the API as it doesn't appear to be working.

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: API Issue
January 10, 2008, 10:28:25 pm
In v2 civicrm_create_event api is used for both creation of new event  and updating existing event, when you pass id in params.

kurund
Found this reply helpful? Support CiviCRM

FredJones

  • Guest
Re: API Issue
January 11, 2008, 01:08:53 am
aha. I see. OK, I may switch and try this but anyhow when I tried to set the time and not just the calendar date for event start/end, it didn't seem to work in the API so I have already setup the SQL to do this manually--that works. :)

Thanks.

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

This forum was archived on 2017-11-26.