/**
* Wrapper Function for civicrm_verify_mandatory to make it simple to pass either / or fields for checking
*
- * @param array $params array of fields to check
+ * @param array $params array of fields to checkl
* @param array $daoName string DAO to check for required fields (create functions only)
* @param array $keyoptions
*
*
* @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'])) {
*
* @return array $result
*/
-function civicrm_api3_create_success($values = 1, $params = array(
- ), $entity = NULL, $action = NULL, &$dao = NULL, $extraReturnValues = array()) {
+function civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL, &$dao = NULL, $extraReturnValues = array()) {
$result = array();
$result['is_error'] = 0;
//lets set the ['id'] field if it's not set & we know what the entity is
else {
$result['values'] = $values;
}
-
+ if(!empty($params['options']['metadata'])) {
+ // we've made metadata an array but only supporting 'fields' atm
+ if(in_array('fields', $params['options']['metadata'])) {
+ $fields = civicrm_api3($entity, 'getfields', array('action' => substr($action, 0, 3) == 'get' ? 'get' : 'create'));
+ $result['metadata']['fields'] = $fields['values'];
+ }
+ }
return array_merge($result, $extraReturnValues);
}
$dao->selectAdd($allfields[$uniqueVal]);
}
}
+ $dao->setApiFilter($params);
}
/**
* @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();
}
*/
function _civicrm_api3_basic_get($bao_name, &$params, $returnAsSuccess = TRUE, $entity = "") {
$bao = new $bao_name();
- _civicrm_api3_dao_set_filter($bao, $params, TRUE,$entity);
+ _civicrm_api3_dao_set_filter($bao, $params, TRUE, $entity);
if ($returnAsSuccess) {
- return civicrm_api3_create_success(_civicrm_api3_dao_to_array($bao, $params, FALSE, $entity), $params, $entity);
+ return civicrm_api3_create_success(_civicrm_api3_dao_to_array($bao, $params, FALSE, $entity), $params, $entity, 'get');
}
else {
return _civicrm_api3_dao_to_array($bao, $params, FALSE, $entity);
*
* @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