コード例 #1
0
/**
 * Retrieve a set of contributions.
 *
 * @param array $params
 *  Input parameters.
 *
 * @return array
 *   Array of contributions, if error an array with an error id and error message
 */
function civicrm_api3_contribution_get($params)
{
    $mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
    $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode);
    $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, array(), NULL, $mode, $returnProperties);
    foreach ($contributions as $id => $contribution) {
        $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id, TRUE);
        $contributions[$id] = array_merge($contribution, $softContribution);
        // format soft credit for backward compatibility
        _civicrm_api3_format_soft_credit($contributions[$id]);
    }
    return civicrm_api3_create_success($contributions, $params, 'Contribution', 'get');
}
コード例 #2
0
ファイル: Batch.php プロジェクト: kcristiano/civicrm-core
 /**
  * Retrieve financial items assigned for a batch.
  *
  * @param int $entityID
  * @param array $returnValues
  * @param bool $notPresent
  * @param array $params
  * @param bool $getCount
  *
  * @return CRM_Core_DAO
  */
 public static function getBatchFinancialItems($entityID, $returnValues, $notPresent = NULL, $params = NULL, $getCount = FALSE)
 {
     if (!$getCount) {
         if (!empty($params['rowCount']) && $params['rowCount'] > 0) {
             $limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
         }
     }
     // action is taken depending upon the mode
     $select = 'civicrm_financial_trxn.id ';
     if (!empty($returnValues)) {
         $select .= " , " . implode(' , ', $returnValues);
     }
     $orderBy = " ORDER BY civicrm_financial_trxn.id";
     if (!empty($params['sort'])) {
         $orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String');
     }
     $from = "civicrm_financial_trxn\nLEFT JOIN civicrm_entity_financial_trxn ON civicrm_entity_financial_trxn.financial_trxn_id = civicrm_financial_trxn.id\nLEFT JOIN civicrm_entity_batch ON civicrm_entity_batch.entity_table = 'civicrm_financial_trxn'\nAND civicrm_entity_batch.entity_id = civicrm_financial_trxn.id\nLEFT JOIN civicrm_contribution ON civicrm_contribution.id = civicrm_entity_financial_trxn.entity_id\nLEFT JOIN civicrm_financial_type ON civicrm_financial_type.id = civicrm_contribution.financial_type_id\nLEFT JOIN civicrm_contact contact_a ON contact_a.id = civicrm_contribution.contact_id\nLEFT JOIN civicrm_contribution_soft ON civicrm_contribution_soft.contribution_id = civicrm_contribution.id\n";
     $searchFields = array('sort_name', 'financial_type_id', 'contribution_page_id', 'payment_instrument_id', 'contribution_trxn_id', 'contribution_source', 'contribution_currency_type', 'contribution_pay_later', 'contribution_recurring', 'contribution_test', 'contribution_thankyou_date_is_not_null', 'contribution_receipt_date_is_not_null', 'contribution_pcp_made_through_id', 'contribution_pcp_display_in_roll', 'contribution_date_relative', 'contribution_amount_low', 'contribution_amount_high', 'contribution_in_honor_of', 'contact_tags', 'group', 'contribution_date_relative', 'contribution_date_high', 'contribution_date_low', 'contribution_check_number', 'contribution_status_id');
     $values = array();
     foreach ($searchFields as $field) {
         if (isset($params[$field])) {
             $values[$field] = $params[$field];
             if ($field == 'sort_name') {
                 $from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id\n          LEFT JOIN civicrm_email ON contact_b.id = civicrm_email.contact_id";
             }
             if ($field == 'contribution_in_honor_of') {
                 $from .= " LEFT JOIN civicrm_contact contact_b ON contact_b.id = civicrm_contribution.contact_id";
             }
             if ($field == 'contact_tags') {
                 $from .= " LEFT JOIN civicrm_entity_tag `civicrm_entity_tag-{$params[$field]}` ON `civicrm_entity_tag-{$params[$field]}`.entity_id = contact_a.id";
             }
             if ($field == 'group') {
                 $from .= " LEFT JOIN civicrm_group_contact `civicrm_group_contact-{$params[$field]}` ON contact_a.id = `civicrm_group_contact-{$params[$field]}`.contact_id ";
             }
             if ($field == 'contribution_date_relative') {
                 $relativeDate = explode('.', $params[$field]);
                 $date = CRM_Utils_Date::relativeToAbsolute($relativeDate[0], $relativeDate[1]);
                 $values['contribution_date_low'] = $date['from'];
                 $values['contribution_date_high'] = $date['to'];
             }
             $searchParams = CRM_Contact_BAO_Query::convertFormValues($values);
             $query = new CRM_Contact_BAO_Query($searchParams, CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, FALSE), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
             if ($field == 'contribution_date_high' || $field == 'contribution_date_low') {
                 $query->dateQueryBuilder($params[$field], 'civicrm_contribution', 'contribution_date', 'receive_date', 'Contribution Date');
             }
         }
     }
     if (!empty($query->_where[0])) {
         $where = implode(' AND ', $query->_where[0]) . " AND civicrm_entity_batch.batch_id IS NULL\n         AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution'";
         $where = str_replace('civicrm_contribution.payment_instrument_id', 'civicrm_financial_trxn.payment_instrument_id', $where);
         $searchValue = TRUE;
     } else {
         $searchValue = FALSE;
     }
     if (!$searchValue) {
         if (!$notPresent) {
             $where = " ( civicrm_entity_batch.batch_id = {$entityID}\n        AND civicrm_entity_batch.entity_table = 'civicrm_financial_trxn'\n        AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution') ";
         } else {
             $where = " ( civicrm_entity_batch.batch_id IS NULL\n        AND civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution')";
         }
     }
     $sql = "\nSELECT {$select}\nFROM   {$from}\nWHERE  {$where}\n       {$orderBy}\n";
     if (isset($limit)) {
         $sql .= "{$limit}";
     }
     $result = CRM_Core_DAO::executeQuery($sql);
     return $result;
 }
コード例 #3
0
ファイル: Search.php プロジェクト: FundingWorks/civicrm-core
 /**
  * Class constructor.
  *
  * @param array $queryParams
  *   Array of parameters for query.
  * @param \const|int $action - action of search basic or advanced.
  * @param string $contributionClause
  *   If the caller wants to further restrict the search (used in contributions).
  * @param bool $single
  *   Are we dealing only with one contact?.
  * @param int $limit
  *   How many contributions do we want returned.
  *
  * @param string $context
  * @param null $compContext
  *
  * @return \CRM_Contribute_Selector_Search
  */
 public function __construct(&$queryParams, $action = CRM_Core_Action::NONE, $contributionClause = NULL, $single = FALSE, $limit = NULL, $context = 'search', $compContext = NULL)
 {
     // submitted form values
     $this->_queryParams =& $queryParams;
     $this->_single = $single;
     $this->_limit = $limit;
     $this->_context = $context;
     $this->_compContext = $compContext;
     $this->_contributionClause = $contributionClause;
     // type of selector
     $this->_action = $action;
     $this->_includeSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($this->_queryParams);
     $this->_query = new CRM_Contact_BAO_Query($this->_queryParams, CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, FALSE), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
     // @todo the function CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled should handle this
     // can we remove? if not why not?
     if ($this->_includeSoftCredits) {
         $this->_query->_rowCountClause = " count(civicrm_contribution.id)";
         $this->_query->_groupByComponentClause = " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
     } else {
         $this->_query->_distinctComponentClause = " civicrm_contribution.id";
         $this->_query->_groupByComponentClause = " GROUP BY civicrm_contribution.id ";
     }
 }
コード例 #4
0
ファイル: utils.php プロジェクト: sugan2111/Drupal_code
/**
 * Get dao query object based on input params.
 *
 * Ideally this would be merged with _civicrm_get_using_query_object but we need to resolve differences in what the
 * 2 variants call
 *
 * @param array $params
 * @param string $mode
 * @param string $entity
 *
 * @return array
 *   [CRM_Core_DAO|CRM_Contact_BAO_Query]
 */
function _civicrm_api3_get_query_object($params, $mode, $entity)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, $entity, 'get');
    $sort = CRM_Utils_Array::value('sort', $options, NULL);
    $offset = CRM_Utils_Array::value('offset', $options);
    $rowCount = CRM_Utils_Array::value('limit', $options);
    $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($mode);
    }
    $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams, 0, FALSE, $entity);
    $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL, FALSE, FALSE, $mode, empty($params['check_permissions']));
    list($select, $from, $where, $having) = $query->query();
    $sql = "{$select} {$from} {$where} {$having}";
    if (!empty($sort)) {
        $sql .= " ORDER BY {$sort} ";
    }
    if (!empty($rowCount)) {
        $sql .= " LIMIT {$offset}, {$rowCount} ";
    }
    $dao = CRM_Core_DAO::executeQuery($sql);
    return array($dao, $query);
}
コード例 #5
0
ファイル: Search.php プロジェクト: hguru/224Civi
 /**
  * Class constructor
  *
  * @param array $queryParams array of parameters for query
  * @param int   $action - action of search basic or advanced.
  * @param string   $contributionClause if the caller wants to further restrict the search (used in contributions)
  * @param boolean $single are we dealing only with one contact?
  * @param int     $limit  how many contributions do we want returned
  *
  * @return CRM_Contact_Selector
  * @access public
  */
 function __construct(&$queryParams, $action = CRM_Core_Action::NONE, $contributionClause = NULL, $single = FALSE, $limit = NULL, $context = 'search', $compContext = NULL)
 {
     // submitted form values
     $this->_queryParams =& $queryParams;
     $this->_single = $single;
     $this->_limit = $limit;
     $this->_context = $context;
     $this->_compContext = $compContext;
     $this->_contributionClause = $contributionClause;
     // type of selector
     $this->_action = $action;
     $this->_query = new CRM_Contact_BAO_Query($this->_queryParams, CRM_Contribute_BAO_Query::defaultReturnProperties(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, FALSE), NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE);
     $this->_query->_distinctComponentClause = " civicrm_contribution.id";
     $this->_query->_groupByComponentClause = " GROUP BY civicrm_contribution.id ";
 }
コード例 #6
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
 * {@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);
}
コード例 #7
0
ファイル: Contribute.php プロジェクト: ksecor/civicrm
/**
 * 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();
    $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;
}