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 Joomla Extensions (Moderator: lcdweb) »
  • Help with API civicrm_event_get
Pages: [1]

Author Topic: Help with API civicrm_event_get  (Read 2956 times)

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Help with API civicrm_event_get
March 22, 2010, 09:36:30 am
New to civiCRM, but experienced with Joomla! and Community Builder.  Have a new project where I think civiCRM (Joomla! component) may be a good fit for most of the functionality.  Still trying to figure out the APIs, hooks, etc.  So excuse me if this answered somewhere else.  I am exploring the APIs as I would like to expose some of the functionality that is in civiCRM but locked away in the permissions for Joomla! (Event Dashboard, etc.) as well as add some new functionality.

I have figured out how to load the API by loading each of the following:
   civicrm.settings.php
   CRM/Core/Config.php
   CRM/Core/DAO.php
   CRM/Core/Error.php
   CRM/Core/Invoke.php

Then set the userFrameworkFrontend as appropriate
(sound right??)

I have a few other questions regarding use of this API, based on the examples on this site.

If I pass:
Code: [Select]
$params = array ('id' >= 6 );
$result = civicrm_event_get( $params );

I get a return like using(print_r):
Code: [Select]
Array( [id]=>6 [custom_1_5]=>1 [custom_2_5]=>1 [custom_3_5]=>1 [is_error]=>0 )
but no other event data as the example indicates...

If I change $params to the following:
Code: [Select]
$params = array( 'return.*' => 0, 'id' => 6 );
then I get the custom properties as well as the other filled in event data... so seems to work just not as documented... 

1) Does this sound right?

2) I can manually map the custom properties but was wondering how to programmatically map the custom values...  Why are some [custom_1_5], some [custom_1_3], [custom_1_-1], etc.?  How do I know or predict the last number?

3) Is there an automatic way to map [custom_1_5] to the table and field it pertains to?

4) When trying to test out the 'duplicate event' procedure found, combining civicrm_event_get, unset 'id', the use civicrm_event_create, I found most of the info transferred... except the custom fields...  How can I get it to set the custom fields as well...

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Help with API civicrm_event_get
March 22, 2010, 10:30:46 am
Quote from: geeffland on March 22, 2010, 09:36:30 am
1) Does this sound right?

Yes, would be great if you can improve the wiki documentation to make this more clear so other people can benefit

Quote from: geeffland on March 22, 2010, 09:36:30 am
2) I can manually map the custom properties but was wondering how to programmatically map the custom values...  Why are some [custom_1_5], some [custom_1_3], [custom_1_-1], etc.?  How do I know or predict the last number?

you can ignore the last number. If the custom field has a value , than the last number is the id in the custom value table (makes it easier on the ajax calls). If the number if -1, it basically means insert a new value (instead of an update)

Quote from: geeffland on March 22, 2010, 09:36:30 am
3) Is there an automatic way to map [custom_1_5] to the table and field it pertains to?

CRM_Core_BAO_CustomField::getTableColumnGroup( $fieldID );

Quote from: geeffland on March 22, 2010, 09:36:30 am
4) When trying to test out the 'duplicate event' procedure found, combining civicrm_event_get, unset 'id', the use civicrm_event_create, I found most of the info transferred... except the custom fields...  How can I get it to set the custom fields as well...

hmm, i suspect u'll need to do independently from the API's. You can potentially use:

CRM_Core_BAO_CustomValueTable::setValues

to set the custom fields for an event

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Re: Help with API civicrm_event_get
March 22, 2010, 10:52:30 am
Is the best way to use
Quote
CRM_Core_BAO_CustomField::getTableColumnGroup( $fieldID );
to include CRM/Core/BAO/CustomField.php ??

Also... for $fieldID do I send 'custom_1_5' (from previous example)?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Help with API civicrm_event_get
March 22, 2010, 12:22:17 pm

1. yes

2. u can use preg_match function to extract the second number from that string to get the fieldID

        if (preg_match('/^custom_(\d+)_?(-?\d+)?$/', $key, $match)) {
           // $match[1] holds the fieldID
        }

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

TravelingPharaoh

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
    • Traveling journey of a developer
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 7
Re: Help with API civicrm_event_get
March 22, 2010, 10:44:15 pm
I develop in a windows box, and deploy to a linux box.  The behavior on Windows was as expected, without setting the return.* parameter in the get it would return all values, but when deployed to linux it would only return the event_id as shown on the original post.  Once I added the return.* then it worked correctly.

Quote from: geeffland on March 22, 2010, 09:36:30 am
New to civiCRM, but experienced with Joomla! and Community Builder.  Have a new project where I think civiCRM (Joomla! component) may be a good fit for most of the functionality.  Still trying to figure out the APIs, hooks, etc.  So excuse me if this answered somewhere else.  I am exploring the APIs as I would like to expose some of the functionality that is in civiCRM but locked away in the permissions for Joomla! (Event Dashboard, etc.) as well as add some new functionality.

I have figured out how to load the API by loading each of the following:
   civicrm.settings.php
   CRM/Core/Config.php
   CRM/Core/DAO.php
   CRM/Core/Error.php
   CRM/Core/Invoke.php

Then set the userFrameworkFrontend as appropriate
(sound right??)

I have a few other questions regarding use of this API, based on the examples on this site.

If I pass:
Code: [Select]
$params = array ('id' >= 6 );
$result = civicrm_event_get( $params );

I get a return like using(print_r):
Code: [Select]
Array( [id]=>6 [custom_1_5]=>1 [custom_2_5]=>1 [custom_3_5]=>1 [is_error]=>0 )
but no other event data as the example indicates...

If I change $params to the following:
Code: [Select]
$params = array( 'return.*' => 0, 'id' => 6 );
then I get the custom properties as well as the other filled in event data... so seems to work just not as documented... 

1) Does this sound right?

2) I can manually map the custom properties but was wondering how to programmatically map the custom values...  Why are some [custom_1_5], some [custom_1_3], [custom_1_-1], etc.?  How do I know or predict the last number?

3) Is there an automatic way to map [custom_1_5] to the table and field it pertains to?

4) When trying to test out the 'duplicate event' procedure found, combining civicrm_event_get, unset 'id', the use civicrm_event_create, I found most of the info transferred... except the custom fields...  How can I get it to set the custom fields as well...

geeffland

  • I’m new here
  • *
  • Posts: 29
  • Karma: 0
Re: Help with API civicrm_event_get
March 23, 2010, 08:34:29 am
Interesting note.  I develop on a Windows box as well... except I recently dumped IIS off and installed WAMP Server because I was needing to update MySql to a newer version (5.x) for both civiCRM testing and Joomla! 1.6 testing.  I had used WAMP Server before and found that it was much easier to setup for multiple versions of MySql and PHP.  I ended up scrapping a bunch of other test sites in the process but was needing to upgrade so I bit the bullet.

So I don't really have a IIS box to test on at the moment.  I do have a Joomla! and Drupal civiCRM test setup but mainly use the Drupal site for seeing what I am missing on the Joomla! side.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Joomla Extensions (Moderator: lcdweb) »
  • Help with API civicrm_event_get

This forum was archived on 2017-11-26.