*
* @todo see notes on _civicrm_api3_check_required_fields regarding removing $daoName param
*/
-function civicrm_api3_verify_mandatory($params, $daoName = NULL, $keys = array(
- ), $verifyDAO = TRUE) {
+function civicrm_api3_verify_mandatory($params, $daoName = NULL, $keys = array(), $verifyDAO = TRUE) {
$unmatched = array();
if ($daoName != NULL && $verifyDAO && empty($params['id'])) {
* 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
*/
$options = _civicrm_api3_get_options_from_params($params,FALSE,$entity);
if(!$options['is_count']) {
- $dao->limit((int)$options['offset'], (int)$options['limit']);
+ if(!empty($options['limit'])) {
+ $dao->limit((int)$options['offset'], (int)$options['limit']);
+ }
if (!empty($options['sort'])) {
$dao->orderBy($options['sort']);
}
* @static void
* @access public
*/
-function _civicrm_api3_dao_to_array($dao, $params = NULL, $uniqueFields = TRUE, $entity = "") {
+function _civicrm_api3_dao_to_array($dao, $params = NULL, $uniqueFields = TRUE, $entity = "", $autoFind = TRUE) {
$result = array();
if(isset($params['options']) && !empty($params['options']['is_count'])) {
return $dao->count();
}
- if (empty($dao) || !$dao->find()) {
+ if (empty($dao)) {
+ return array();
+ }
+ if ($autoFind && !$dao->find()) {
return array();
}
*
* @return array
*/
-function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array(
- )) {
+function _civicrm_api_get_fields($entity, $unique = FALSE, &$params = array()) {
$unsetIfEmpty = array('dataPattern', 'headerPattern', 'default', 'export', 'import');
$dao = _civicrm_api3_get_DAO($entity);
if (empty($dao)) {
throw new Exception("Currency not a valid code: $value");
}
}
- if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || !empty($fieldInfo['enumValues'])) {
+ if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options'])) {
_civicrm_api3_api_match_pseudoconstant($params, $entity, $fieldName, $fieldInfo);
}
// Check our field length