Пример #1
0
/**
 * Retrieve a set of pledges, given a set of input params
 *
 * @param  array   $params           (reference ) input parameters. Use interogate for possible fields
 *
 * @return array (reference )        array of pledges, if error an array with an error id and error message
 * {@getfields pledge_get}
 * @example PledgeGet.php
 * @access public
 */
function civicrm_api3_pledge_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'pledge', 'get');
    if (empty($options['return'])) {
        $options['return'] = CRM_Pledge_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_PLEDGE);
    } else {
        $options['return']['pledge_id'] = 1;
    }
    $newParams = CRM_Contact_BAO_Query::convertFormValues($options['input_params']);
    $query = new CRM_Contact_BAO_Query($newParams, $options['return'], NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_PLEDGE);
    list($select, $from, $where) = $query->query();
    $sql = "{$select} {$from} {$where}";
    if (!empty($options['sort'])) {
        $sql .= " ORDER BY " . $options['sort'];
    }
    $sql .= " LIMIT " . $options['offset'] . " , " . $options['limit'];
    $dao = CRM_Core_DAO::executeQuery($sql);
    $pledge = array();
    while ($dao->fetch()) {
        $pledge[$dao->pledge_id] = $query->store($dao);
    }
    return civicrm_api3_create_success($pledge, $params, 'pledge', 'get', $dao);
}
Пример #2
0
/**
 * Retrieve a set of pledges, given a set of input params
 *
 * @param  array   $params           (reference ) input parameters. Use interogate for possible fields
 *
 * @return array (reference )        array of pledges, if error an array with an error id and error message
 * @static void
 * @access public
 */
function &civicrm_pledge_get(&$params)
{
    _civicrm_initialize();
    if (!is_array($params)) {
        return civicrm_create_error('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);
    } else {
        $returnProperties['pledge_id'] = 1;
    }
    $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()) {
        if ($params['sequential']) {
            $pledge[] = $query->store($dao);
        } else {
            $pledge[$dao->pledge_id] = $query->store($dao);
        }
    }
    $dao->free();
    return $pledge;
}