/**
  * wrapper for a api search query
  *
  * @param array  $params
  * @param array  $returnProperties
  * @param string $sort
  * @param int    $offset
  * @param int    $row_count
  *
  * @return void
  * @access public
  */
 static function apiQuery($params = NULL, $returnProperties = NULL, $fields = NULL, $sort = NULL, $offset = 0, $row_count = 25, $smartGroupCache = TRUE)
 {
     $query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, TRUE, FALSE, 1, FALSE, TRUE, $smartGroupCache);
     list($select, $from, $where, $having) = $query->query();
     $options = $query->_options;
     $sql = "{$select} {$from} {$where} {$having}";
     // add group by
     if ($query->_useGroupBy) {
         $sql .= ' GROUP BY contact_a.id';
     }
     if (!empty($sort)) {
         $sql .= " ORDER BY {$sort} ";
     }
     if ($row_count > 0 && $offset >= 0) {
         $sql .= " LIMIT {$offset}, {$row_count} ";
     }
     $dao = CRM_Core_DAO::executeQuery($sql);
     $values = array();
     while ($dao->fetch()) {
         $values[$dao->contact_id] = $query->store($dao);
     }
     $dao->free();
     return array($values, $options);
 }
示例#2
0
 /**
  * wrapper for a api search query
  *
  * @param array  $params
  * @param array  $returnProperties
  * @param string $sort
  * @param int    $offset
  * @param int    $row_count
  *
  * @return void 
  * @access public 
  */
 function apiQuery($params = null, $returnProperties = null, $options = null, $sort = null, $offset = 0, $row_count = 25)
 {
     $query = new CRM_Contact_BAO_Query($params, $returnProperties, null);
     list($select, $from, $where) = $query->query();
     $options = $query->_options;
     $sql = "{$select} {$from} {$where}";
     if (!empty($sort)) {
         $sql .= " ORDER BY {$sort} ";
     }
     if ($row_count > 0 && $offset >= 0) {
         $sql .= " LIMIT {$offset}, {$row_count} ";
     }
     $dao =& CRM_Core_DAO::executeQuery($sql);
     $values = array();
     while ($dao->fetch()) {
         $values[$dao->contact_id] = $query->store($dao);
     }
     return array($values, $options);
 }
示例#3
0
 /**
  * These are stub comments as this function needs more explanation - particularly in terms of how it
  * relates to $this->searchQuery and why it replicates rather than calles $this->searchQuery.
  *
  * This function was originally written as a wrapper for the api query but is called from multiple places
  * in the core code directly so the name is misleading. This function does not use the searchQuery function
  * but it is unclear as to whehter that is historical or there is a reason
  *  CRM-11290 led to the permissioning action being extracted from searchQuery & shared with this function
  *
  * @param array $params
  * @param array $returnProperties
  * @param null $fields
  * @param string $sort
  * @param int $offset
  * @param int $row_count
  * @param bool $smartGroupCache
  *   ?? update smart group cache?.
  * @param bool $count
  *   Return count obnly.
  * @param bool $skipPermissions
  *   Should permissions be ignored or should the logged in user's permissions be applied.
  *
  *
  * @return array
  */
 public static function apiQuery($params = NULL, $returnProperties = NULL, $fields = NULL, $sort = NULL, $offset = 0, $row_count = 25, $smartGroupCache = TRUE, $count = FALSE, $skipPermissions = TRUE)
 {
     $query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, TRUE, FALSE, 1, $skipPermissions, TRUE, $smartGroupCache);
     //this should add a check for view deleted if permissions are enabled
     if ($skipPermissions) {
         $query->_skipDeleteClause = TRUE;
     }
     $query->generatePermissionClause(FALSE, $count);
     // note : this modifies _fromClause and _simpleFromClause
     $query->includePseudoFieldsJoin($sort);
     list($select, $from, $where, $having) = $query->query($count);
     $options = $query->_options;
     if (!empty($query->_permissionWhereClause)) {
         if (empty($where)) {
             $where = "WHERE {$query->_permissionWhereClause}";
         } else {
             $where = "{$where} AND {$query->_permissionWhereClause}";
         }
     }
     $sql = "{$select} {$from} {$where} {$having}";
     // add group by
     if ($query->_useGroupBy) {
         $sql .= ' GROUP BY contact_a.id';
     }
     if (!empty($sort)) {
         $sort = CRM_Utils_Type::escape($sort, 'String');
         $sql .= " ORDER BY {$sort} ";
     }
     if ($row_count > 0 && $offset >= 0) {
         $offset = CRM_Utils_Type::escape($offset, 'Int');
         $rowCount = CRM_Utils_Type::escape($row_count, 'Int');
         $sql .= " LIMIT {$offset}, {$row_count} ";
     }
     $dao = CRM_Core_DAO::executeQuery($sql);
     $values = array();
     while ($dao->fetch()) {
         if ($count) {
             $noRows = $dao->rowCount;
             $dao->free();
             return array($noRows, NULL);
         }
         $val = $query->store($dao);
         $convertedVals = $query->convertToPseudoNames($dao, TRUE);
         if (!empty($convertedVals)) {
             $val = array_replace_recursive($val, $convertedVals);
         }
         $values[$dao->contact_id] = $val;
     }
     $dao->free();
     return array($values, $options);
 }
/**
 * 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;
}
示例#5
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);
}
示例#6
0
function &civicrm_contributionsoft_search( &$params ) {

    if( ! is_array($params) ) {
        return civicrm_create_error( 'Params need to be of type 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;
        }
    }

    require_once 'CRM/Contribute/BAO/Query.php';
    require_once 'CRM/Contact/BAO/Query.php'; 
    
	if ( empty( $returnProperties ) ) {
		//CRM_Contribute_BAO_Query::defaultReturnProperties( CRM_Contact_BAO_Query::MODE_CONTRIBUTIONPAGE );
		$returnProperties = array ( 
								'id' 					=> 1,
								'contribution_id' 		=> 1,
								'contact_id' 			=> 1,
								'amount'				=> 1,
								'pcp_id'				=> 1,
								'pcp_display_in_roll'	=> 1,
								'pcp_roll_nickname'		=> 1,
								'pcp_personal_note'		=> 1,
								'currency'				=> 1
							);
	}

    $newParams =& CRM_Contact_BAO_Query::convertFormValues( $params );
    $query = new CRM_Contact_BAO_Query( $newParams, $returnProperties, null );
	
	// I'm having a problem understanding how this part works, so I'm just working around it for now...
	/*
    list( $select, $from, $where ) = $query->query( );
    
    $sql = "$select $from $where";  
	*/
	$query->_element = array_merge($query->_element, $returnProperties);
	
	
	$sql = "select * from civicrm_contribution_soft";
	$extra = '';
	
	$possible = array('id', 'contribution_id', 'contact_id', 'pcp_id');
	foreach($possible as $key) {
		if ( CRM_Utils_Array::value( $key , $params) ) {
			$extra .= " and $key='" . mysql_real_escape_string($params[$key]) . "'";
		}
	}
	
	if (!empty($extra)) {
		$extra = substr($extra, 4);
		$sql .= " where $extra";
	}
	// end work around
	
	if ( ! empty( $sort ) ) {
        $sql .= " ORDER BY $sort ";
    }

    $sql .= " LIMIT $offset, $rowCount ";
    $dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
    
    $contributionPage = array( );
    while ( $dao->fetch( ) ) {
		$contributionSoft[$dao->id] = $query->store( $dao );
    }

    $dao->free( );

    return $contributionSoft;

}
示例#7
0
function &civicrm_contributionpage_search( &$params ) {

    if( ! is_array($params) ) {
        return civicrm_create_error( 'Params need to be of type 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;
        }
    }

    require_once 'CRM/Contribute/BAO/Query.php';
    require_once 'CRM/Contact/BAO/Query.php'; 
    
	if ( empty( $returnProperties ) ) {
		$returnProperties = array(
                                'id'                        => 1,
                                'title'                     => 1,
                                'intro_text'                => 1,
                                'contribution_type_id'      => 1,
                                'payment_processor_id'      => 1,
                                'is_credit_card_only'       => 1,
                                'is_monetary'               => 1,
                                'is_recur'                  => 1,
                                'recur_requency_unit'       => 1,
                                'is_recur_interval'         => 1,
                                'is_pay_later'              => 1,
                                'pay_later_text'            => 1,
                                'pay_later_receipt'         => 1,
                                'is_allow_other_amount'     => 1,
                                'default_amount_id'         => 1,
                                'min_amount'                => 1,
                                'max_amount'                => 1,
                                'goal_amount'               => 1,
                                'thankyou_title'            => 1,
                                'thankyou_footer'           => 1,
                                'is_for_organization'       => 1,
                                'is_email_receipt'          => 1,
                                'receipt_from_name'         => 1,
                                'receipt_from_email'        => 1,
                                'cc_receipt'                => 1,
                                'bcc_receipt'               => 1,
                                'receipt_text'              => 1,
                                'is_active'                 => 1,
                                'footer_text'               => 1,
                                'amount_block_is_active'    => 1,
                                'honor_block_is_active'     => 1,
                                'honor_block_title'         => 1,
                                'honor_block_text'          => 1,
                                'start_date'                => 1,
                                'end_date'                  => 1,
                                'created_id'                => 1,
                                'created_date'              => 1,
                                'currency'                  => 1
                            );
	}

    $newParams =& CRM_Contact_BAO_Query::convertFormValues( $params);
    $query = new CRM_Contact_BAO_Query( $newParams, $returnProperties, null );
	
	// I'm having a problem understanding how this part works, so I'm just working around it for now...
	/*
    list( $select, $from, $where ) = $query->query( );
    
    $sql = "$select $from $where";  
	*/
	$query->_element = array_merge($query->_element, $returnProperties);
	
	
	$sql = "select * from civicrm_contribution_page";
	if( CRM_Utils_Array::value( 'id', $params) ) {
		$sql .= " where id=" . mysql_real_escape_string($params['id']);
	}
	// end work around
	
	if ( ! empty( $sort ) ) {
        $sql .= " ORDER BY $sort ";
    }

    $sql .= " LIMIT $offset, $rowCount ";
    $dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
    
    $contributionPage = array( );
    while ( $dao->fetch( ) ) {
		$contributionPage[$dao->id] = $query->store( $dao );
    }

    $dao->free( );

    return $contributionPage;

}
/**
 * Retrieve a set of contributions, given a set of input params
 *
 * @param  array   $params           (reference ) input parameters
 * @param array    $returnProperties Which properties should be included in the
 * returned Contribution object. If NULL, the default
 * set of properties will be included.
 *
 * @return array (reference )        array of contributions, if error an array with an error id and error message
 * @static void
 * @access public
 * {@getfields Contribution_get}
 * @example ContributionGet.php
 */
function civicrm_api3_contribution_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'contribution', 'get');
    $sort = CRM_Utils_Array::value('sort', $options, NULL);
    $offset = CRM_Utils_Array::value('offset', $options);
    $rowCount = CRM_Utils_Array::value('limit', $options);
    $smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params);
    $inputParams = CRM_Utils_Array::value('input_params', $options, array());
    $returnProperties = CRM_Utils_Array::value('return', $options, NULL);
    if (empty($returnProperties)) {
        $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
    }
    $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
    $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
    list($select, $from, $where, $having) = $query->query();
    $sql = "{$select} {$from} {$where} {$having}";
    if (!empty($sort)) {
        $sql .= " ORDER BY {$sort} ";
    }
    $sql .= " LIMIT {$offset}, {$rowCount} ";
    $dao = CRM_Core_DAO::executeQuery($sql);
    $contribution = array();
    while ($dao->fetch()) {
        //CRM-8662
        $contribution_details = $query->store($dao);
        $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dao->contribution_id, TRUE);
        $contribution[$dao->contribution_id] = array_merge($contribution_details, $softContribution);
        if (isset($contribution[$dao->contribution_id]['financial_type_id'])) {
            $contribution[$dao->contribution_id]['financial_type_id'] = $contribution[$dao->contribution_id]['financial_type_id'];
        }
        // format soft credit for backward compatibility
        _civicrm_api3_format_soft_credit($contribution[$dao->contribution_id]);
    }
    return civicrm_api3_create_success($contribution, $params, 'contribution', 'get', $dao);
}
/**
 * Retrieve a specific participant, given a set of input params
 * If more than one matching participant exists, return an error, unless
 * the client has requested to return the first found contact
 *
 * @param  array   $params           (reference ) input parameters
 *
 * @return array (reference )        array of properties, if error an array with an error id and error message
 * {@getfields participant_get}
 * @access public
 */
function civicrm_api3_participant_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'participant', 'get');
    $sort = CRM_Utils_Array::value('sort', $options, NULL);
    $offset = CRM_Utils_Array::value('offset', $options);
    $rowCount = CRM_Utils_Array::value('limit', $options);
    $smartGroupCache = CRM_Utils_Array::value('smartGroupCache', $params);
    $inputParams = CRM_Utils_Array::value('input_params', $options, array());
    $returnProperties = CRM_Utils_Array::value('return', $options, NULL);
    if (empty($returnProperties)) {
        $returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
    }
    $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
    $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT);
    list($select, $from, $where, $having) = $query->query();
    $sql = "{$select} {$from} {$where} {$having}";
    if (!empty($sort)) {
        $sql .= " ORDER BY {$sort} ";
    }
    $sql .= " LIMIT {$offset}, {$rowCount} ";
    $dao = CRM_Core_DAO::executeQuery($sql);
    $participant = array();
    while ($dao->fetch()) {
        $participant[$dao->participant_id] = $query->store($dao);
        _civicrm_api3_custom_data_get($participant[$dao->participant_id], 'Participant', $dao->participant_id, NULL);
    }
    return civicrm_api3_create_success($participant, $params, 'participant', 'get', $dao);
}
/**
 * Get contact participant record.
 *
 * This api is used for finding an existing participant record.
 *
 * @param  array  $params     an associative array of name/value property values of civicrm_participant
 *
 * @return  participant property values.
 * @access public
 */
function &civicrm_participant_search(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error('Params need to be of type 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('participant_test', $inputParams)) {
        $inputParams['participant_test'] = 0;
    }
    require_once 'CRM/Contact/BAO/Query.php';
    require_once 'CRM/Event/BAO/Query.php';
    if (empty($returnProperties)) {
        $returnProperties = CRM_Event_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_EVENT);
    }
    $newParams = CRM_Contact_BAO_Query::convertFormValues($params);
    $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL);
    list($select, $from, $where, $having) = $query->query();
    $sql = "{$select} {$from} {$where} {$having}";
    if (!empty($sort)) {
        $sql .= " ORDER BY {$sort} ";
    }
    $sql .= " LIMIT {$offset}, {$rowCount} ";
    $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
    $participant = array();
    while ($dao->fetch()) {
        $participant[$dao->participant_id] = $query->store($dao);
    }
    $dao->free();
    return $participant;
}
示例#11
0
function &civicrm_pcp_search( &$params ) {

    if( ! is_array($params) ) {
        return civicrm_create_error( 'Params need to be of type 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;
        }
    }

    $pcpBlock = CRM_Utils_Array::value( 'pcpBlock', $params, TRUE );
	
    require_once 'CRM/Contribute/BAO/Query.php';
    require_once 'CRM/Contact/BAO/Query.php'; 
    
	if ( empty( $returnProperties ) ) {
		if ( $pcpBlock ) {
			$returnProperties = array(
									'id' 					=> 1,
									'entity_table'  		=> 1,
									'supporter_profile_id'  => 1,
									'is_approval_needed'    => 1,
									'is_tellfriend_enabled' => 1,
									'tellfriend_limit'      => 1,
									'link_text'             => 1,
									'is_active'             => 1,
									'notify_email'          => 1
								);			
		} else {
			$returnProperties = array(  
									'id'                    => 1,
									'contact_id'            => 1,
									'title'                 => 1,
									'intro_text'            => 1,
									'page_text'             => 1,
									'donate_link_text'      => 1,
									'contribution_page_id'  => 1,
									'is_thermometer'        => 1,
									'is_honor_roll'         => 1,
									'goal_amount'           => 1,
									'referer'               => 1,
									'is_active'             => 1,
									'currency'              => 1
								);			
		}
	}

    $newParams =& CRM_Contact_BAO_Query::convertFormValues( $params);
    $query = new CRM_Contact_BAO_Query( $newParams, $returnProperties, null );
	
	// I'm having a problem understanding how this part works, so I'm just working around it for now...
	/*
    list( $select, $from, $where ) = $query->query( );
    
    $sql = "$select $from $where";  
	*/
	$where = '';
	
	$query->_element = array_merge($query->_element, $returnProperties);
	if ( !$pcpBlock ) {
		$key = 'id';
		$sql = "select * from civicrm_pcp";
		
/*
		if( CRM_Utils_Array::value( 'id', $params) ) {
			$sql .= " where id=" . mysql_real_escape_string($params['id']);
		}
*/
		foreach($params as $tmp_key => $value) {
			if(isset($returnProperties[$tmp_key])) {
				$where.= sprintf(" and %s='%s'", mysql_real_escape_string($tmp_key), mysql_real_escape_string($value));
			}
		}
	} else {
		$key = 'entity_id';
		$sql = "select * from civicrm_pcp_block";
		if( CRM_Utils_Array::value( 'entity_id', $params) ) {
			$sql .= " where entity_id=" . mysql_real_escape_string($params['entity_id']);
		}
	}
	if(!empty($where)) {
		$sql .= " where " . substr($where, 4);
	}
	// end work around
	
	if ( ! empty( $sort ) ) {
        $sql .= " ORDER BY $sort ";
    }

    $sql .= " LIMIT $offset, $rowCount ";
    $dao =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
    
    $pcp = array( );
    while ( $dao->fetch( ) ) {
		$pcp[$dao->$key] = $query->store( $dao );
    }

    $dao->free( );

    return $pcp;

}
示例#12
0
/**
 * Retrieve a set of contributions, given a set of input params
 *
 * @param  array   $params           (reference ) input parameters
 * @param array    $returnProperties Which properties should be included in the
 *                                   returned Contribution object. If NULL, the default
 *                                   set of properties will be included.
 *
 * @return array (reference )        array of contributions, if error an array with an error id and error message
 * @static void
 * @access public
 */
function &civicrm_contribution_search( &$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( 'contribution_test', $inputParams ) ) {
        $inputParams['contribution_test'] = 0;
    }

    require_once 'CRM/Contribute/BAO/Query.php';
    require_once 'CRM/Contact/BAO/Query.php';
    if ( empty( $returnProperties ) ) {
        $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties( CRM_Contact_BAO_Query::MODE_CONTRIBUTE );
    }
    
    $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 );
    
    $contribution = array( );
    while ( $dao->fetch( ) ) {
        $contribution[$dao->contribution_id] = $query->store( $dao );
    }
    $dao->free( );
    
    return $contribution;
}