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) »
  • How do you use api for ajax?
Pages: [1]

Author Topic: How do you use api for ajax?  (Read 866 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
How do you use api for ajax?
April 05, 2011, 05:46:16 am
I'm looking at adding event as a cck field for events & it partially works.

I was hoping to use the api for the autocomplete but it would require a WHERE 'title' LIKE '%$string%' for it to work which doesn't seem possible - and yet I'm sure Xavier has used the API for just this sort of thing?

The code for contact is:

Code: [Select]
 
 function civicrm_cck_autocomplete($field_name, $string = '') {
  $references = _civicrm_cck_potential_references($field, $string);


    foreach ($references as $id => $row) {
        // Add a class wrapper for a few required CSS overrides.
        $matches["{$row['title']} [cid:{$id}]"] = '<div class="reference-autocomplete">'. $row['rendered'] . '</div>';
    }

}
    drupal_json($matches);

_civicrm_cck_potential_references calls a long drawn out search effort (and contact is a more complicated entity) so I was hoping there was a simpler api-v3-way

Code: [Select]
if ($field['type'] == 'civicrm_cck_event'){
  require_once 'api/api.php';
  $result = civicrm_api('Event','Get',array('version' => 3,'title' => '%' . $string . '%', 'return.title' => 1, ) );
  if ($result['is_error']==0){
    $references= $result['values'];
    $references['rendered'] = $references['title'];
  }
    foreach ($references as $id => $row) {
        // Add a class wrapper for a few required CSS overrides.
        $matches["{$row['title']} [cid:{$id}]"] = '<div class="reference-autocomplete">'. $row['title'] . '</div>';
    }
drupal_json($matches);

 // nb the function civicrm_error() is a v2 function so I didn't use it - we should probably move it into api.php as it is generic?
« Last Edit: April 05, 2011, 05:48:15 am by Eileen »
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

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: How do you use api for ajax?
April 05, 2011, 06:36:10 am
Hi

Code: [Select]
[quote]/civicrm/ajax/rest?json=1&debug=1&version=3&entity=Event&action=get&title=Fall Fundraiser Dinner
[/quote]

Seems that it does a = not a like

@civicrew, could


    $eventDAO->copyValues( $inputParams );

take into account a wildchar easily?

(ie. if you have title=*ttt* or title=%ttt% then it's a like instead of an equal ?)

X+

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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: How do you use api for ajax?
April 09, 2011, 05:01:02 am
Hey, any response on this?

I want to extend the (cck) field integration module to cover other data types using the api for autocomplete fields. I really want to be able to do LIKE '%str%' against the api in order for this to work (and I think the api should support searching).

If this isn't an approach we can make progress on I'll probably drop the idea of extending cck / rules integration & just do a custom bit of code for the specific use case but it feels like that would be a shame as I was making progress on using Rules integration to get Civi interacting better with organic groups.
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

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: How do you use api for ajax?
April 09, 2011, 11:24:06 am
I took a brief look at the relevant DB_DO code and its not supported in the code right now. I dont think its trivial to add (its probably not too complex either)

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • How do you use api for ajax?

This forum was archived on 2017-11-26.