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

Author Topic: API Get Operators  (Read 853 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
API Get Operators
September 21, 2010, 03:20:46 am
Is it currently possible to use criteria other than '=' for a get api?

On my (still in BETA) pledge api I tried

Code: [Select]
      require_once 'api/v2/Pledge.php';
        $pledgeparams = array('contact_id' => $params['contact_id'],
                            'version' => '3.0',
                            'pledge_status_id' = 2
     
       
        );
      $results = civicrm_pledge_get($pledgeparams);

All good

But I could find any evidence of how to get the pledges with status IN(2,5,6) or the equivalent for any existing api.

The code I have been working with here is based heavily on the contribute api so it's not much different to the existing apis


Code: [Select]
function &civicrm_pledge_get( &$params ) {
    _civicrm_initialize( );
    if ( ! is_array( $params ) ) {
        return civicrm_create_error( ts( 'Input parameters is not an array' ) );
    }

    $inputParams      = array( );
    $returnProperties = array( );
    $otherVars = array( 'sort', 'offset', 'rowCount' );
   
    $sort     = null;
    $offset   = 0;
    $rowCount = 25;
    foreach ( $params as $n => $v ) {
        if ( substr( $n, 0, 7 ) == 'return.' ) {
            $returnProperties[ substr( $n, 7 ) ] = $v;
        } elseif ( in_array( $n, $otherVars ) ) {
            $$n = $v;
        } else {
            $inputParams[$n] = $v;
        }
    }
   
    // add is_test to the clause if not present
    if ( ! array_key_exists( 'pledge_test', $inputParams ) ) {
        $inputParams['pledge_test'] = 0;
    }

    require_once 'CRM/Pledge/BAO/Query.php';
    require_once 'CRM/Contact/BAO/Query.php';
    if ( empty( $returnProperties ) ) {
        $returnProperties = CRM_Pledge_BAO_Query::defaultReturnProperties( CRM_Contact_BAO_Query::MODE_PLEDGE );
    }
   
    $newParams =& CRM_Contact_BAO_Query::convertFormValues( $inputParams );

    $query = new CRM_Contact_BAO_Query( $newParams, $returnProperties, null );
    list( $select, $from, $where ) = $query->query( );
   
    $sql = "$select $from $where"; 

    if ( ! empty( $sort ) ) {
        $sql .= " ORDER BY $sort ";
    }
    $sql .= " LIMIT $offset, $rowCount ";
    $dao =& CRM_Core_DAO::executeQuery( $sql );
   
    $pledge = array( );
    while ( $dao->fetch( ) ) {
        $pledge[$dao->pledge_id] = $query->store( $dao );
    }
    $dao->free( );
   
    return $pledge;
}
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: API Get Operators
September 21, 2010, 04:10:24 am
Have you tried with the contact get ? pretty sure tags & groups can be arrays

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: API Get Operators
September 21, 2010, 04:11:28 am
Ah - OK - will try an array - didn't think of that or find it in any examples
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

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: API Get Operators
September 21, 2010, 04:31:41 am
On that note - can you pass arrays through REST?
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

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: API Get Operators
September 21, 2010, 04:40:43 am
I know you can receive arrays through REST, but I am not sure if you can send them. In my project I tend to bring them down to a single entity. So rather than using a location_createwith possibly a number of arrays I have created a specific phone_create, email_create and address_create.
Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

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

This forum was archived on 2017-11-26.