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) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Group API
Pages: [1]

Author Topic: Group API  (Read 603 times)

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Group API
April 15, 2014, 01:57:17 am
Hey,

I have an extension with some generic stuff for my client. One of the things I usually do in this kind of extension is to create the custom fields, relationship types etc....

One of the things which should be created by this generic extensions are some smart groups. Now I can see from the Group API that I have the contents for the smart group and create them on enabling of my extension. However I see that the selectTables and the whereTables are returned as a serialized string which seems to be an array of string when you unserialize them. I would assume that in the return value of the API is not a serialized one but a JSON array.

Below an example of the returned Group from the API

Code: [Select]
{
"id":"2",
"name":"import",
"title":"import",
"description":"De contacten in deze groep komen van de oude CRM.",
"source":"",
"saved_search_id":"",
"is_active":"1",
"visibility":"User and User Admin Only",
"where_clause":" ( `civicrm_group_contact-2`.group_id IN ( 2 ) AND `civicrm_group_contact-2`.status IN (\"Added\") ) ",
"select_tables":"a:8:{s:15:\"civicrm_contact\";i:1;s:15:\"civicrm_address\";i:1;s:15:\"civicrm_country\";i:1;s:13:\"civicrm_email\";i:1;s:13:\"civicrm_phone\";i:1;s:10:\"civicrm_im\";i:1;s:19:\"civicrm_worldregion\";i:1;s:25:\"`civicrm_group_contact-2`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-2` ON ( contact_a.id = `civicrm_group_contact-2`.contact_id AND `civicrm_group_contact-2`.group_id IN ( 2 ) )\";}",
"where_tables":"a:2:{s:15:\"civicrm_contact\";i:1;s:25:\"`civicrm_group_contact-2`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-2` ON ( contact_a.id = `civicrm_group_contact-2`.contact_id AND `civicrm_group_contact-2`.group_id IN ( 2 ) )\";}",
"group_type":"",
"cache_date":"",
"refresh_date":"",
"parents":"",
"children":"",
"is_hidden":"0",
"is_reserved":"0",
"created_id":""
},
Developer at Edeveloper / CiviCoop

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Group API
April 15, 2014, 02:44:09 pm
CiviCRM has 'always' stored arrays as serialized strings. More recently I think we have added a small number of fields where they are stored as json - but certainly not retro-actively
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Re: Group API
April 16, 2014, 12:13:39 am
Ok. So what should be the standard here? The josn encode return (or xml) or the php serialized one?
I would argue the first one.

I can understand the API works like that from historic perspective, i am also happy to report this as an issue and provide a patch for it.
Developer at Edeveloper / CiviCoop

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Group API
April 16, 2014, 12:28:49 am
People who are happy to provide patches are always welcome  ;D
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Group API
April 16, 2014, 01:00:52 am
It makes sense to me that the api should unpack this to an array (which will wind up as an array to php users & json to Rest users). The DB storage mechanism would be uncoupled from the api format in a way that seems consistent with other places
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Re: Group API
June 04, 2014, 08:27:19 am
I have discovered that the group api doesn't return the search criteria on which the smart group is build. It returns instead an ID to the saved search. But there is no api on the saved search side.
Developer at Edeveloper / CiviCoop

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Group API

This forum was archived on 2017-11-26.