*/
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);
+ $mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE;
+ $entity = 'contribution';
+ list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, $entity);
$contribution = array();
while ($dao->fetch()) {
* @access public
*/
function civicrm_api3_participant_get($params) {
+ $mode = CRM_Contact_BAO_Query::MODE_EVENT;
+ $entity = 'participant';
- $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);
+ list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, $entity);
$participant = array();
while ($dao->fetch()) {
$participant[$dao->participant_id] = $query->store($dao);
+ //@todo - is this required - contribution & pledge use the same query but don't self-retrieve custom data
_civicrm_api3_custom_data_get($participant[$dao->participant_id], 'Participant', $dao->participant_id, NULL);
}
* @access public
*/
function civicrm_api3_pledge_get($params) {
+ $mode = CRM_Contact_BAO_Query::MODE_PLEDGE;
+ $entity = 'pledge';
+
+ list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, $entity);
- $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);
* others that use the query object. Note that this function passes permission information in.
* The others don't
*
+ * * Ideally this would be merged with _civicrm_get_query_object but we need to resolve differences in what the
+ * 2 variants call
* @param $entity
* @param array $params as passed into api get or getcount function
* @param array $additional_options
return $entities;
}
+/**
+ * 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 CRM_Core_DAO query object
+ */
+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);
+ $query = new CRM_Contact_BAO_Query($newParams, $returnProperties, NULL,
+ FALSE, FALSE, $mode
+ );
+ 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);
+}
+
/**
* Function transfers the filters being passed into the DAO onto the params object
*/
public static function toBeSkipped_getlimit() {
$entitiesWithout = array(
'Case',//case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
- 'Contribution', //existing behaviour = fatal if 0 limit applied as offset of null is put in the query
'EntityTag', // non-standard api - has inappropriate mandatory fields & doesn't implement limit
'Event', // failed 'check that a 5 limit returns 5' - probably is_template field is wrong or something, or could be limit doesn't work right
'Extension', // can't handle creating 25
'MailingGroup', // no get call on MailingGroup
'Note', // fails on 5 limit - probably a set up problem
- 'Participant', //existing behaviour = fatal if 0 limit applied as null offset in sql
- 'Pledge', //existing behaviour = fatal if 0 limit applied as null offset in sql
'Setting', //a bit of a pseudoapi - keys by domain
-
);
return $entitiesWithout;
}