/** * @param string $bao_name * Name of BAO * @param array $params * As passed into api get function. * @param bool $isFillUniqueFields * Do we need to ensure unique fields continue to be populated for this api? (backward compatibility). */ public function __construct($bao_name, $params, $isFillUniqueFields) { $this->bao = new $bao_name(); $this->entity = _civicrm_api_get_entity_name_from_dao($this->bao); $this->params = $params; $this->isFillUniqueFields = $isFillUniqueFields; $this->checkPermissions = \CRM_Utils_Array::value('check_permissions', $this->params, FALSE); $this->options = _civicrm_api3_get_options_from_params($this->params); $this->entityFieldNames = _civicrm_api3_field_names(_civicrm_api3_build_fields_array($this->bao)); // Call this function directly instead of using the api wrapper to force unique field names off require_once 'api/v3/Generic.php'; $apiSpec = \civicrm_api3_generic_getfields(array('entity' => $this->entity, 'version' => 3, 'params' => array('action' => 'get')), FALSE); $this->apiFieldSpec = $apiSpec['values']; $this->query = \CRM_Utils_SQL_Select::from($this->bao->tableName() . " a"); }
/** * @param string $baoName * Name of BAO * @param array $params * As passed into api get function. * @param bool $isFillUniqueFields * Do we need to ensure unique fields continue to be populated for this api? (backward compatibility). */ public function __construct($baoName, $params, $isFillUniqueFields) { $bao = new $baoName(); $this->entity = _civicrm_api_get_entity_name_from_dao($bao); $this->params = $params; $this->isFillUniqueFields = $isFillUniqueFields; $this->checkPermissions = \CRM_Utils_Array::value('check_permissions', $this->params, FALSE); $this->options = _civicrm_api3_get_options_from_params($this->params); $this->entityFieldNames = _civicrm_api3_field_names(_civicrm_api3_build_fields_array($bao)); // Call this function directly instead of using the api wrapper to force unique field names off require_once 'api/v3/Generic.php'; $apiSpec = \civicrm_api3_generic_getfields(array('entity' => $this->entity, 'version' => 3, 'params' => array('action' => 'get')), FALSE); $this->apiFieldSpec = $apiSpec['values']; $this->query = \CRM_Utils_SQL_Select::from($bao->tableName() . ' ' . self::MAIN_TABLE_ALIAS); $bao->free(); // Add ACLs first to avoid redundant subclauses $this->query->where($this->getAclClause(self::MAIN_TABLE_ALIAS, $baoName)); }
function _civicrm_api3_build_fields_array(&$bao, $unique = TRUE) { $fields = $bao->fields(); if ($unique) { if (!CRM_Utils_Array::value('id', $fields)) { $entity = _civicrm_api_get_entity_name_from_dao($bao); $fields['id'] = $fields[$entity . '_id']; unset($fields[$entity . '_id']); } return $fields; } foreach ($fields as $field) { $dbFields[$field['name']] = $field; } return $dbFields; }
/** * Build fields array. * * This is the array of fields as it relates to the given DAO * returns unique fields as keys by default but if set but can return by DB fields * * @param CRM_Core_DAO $bao * @param bool $unique * * @return array */ function _civicrm_api3_build_fields_array(&$bao, $unique = TRUE) { $fields = $bao->fields(); if ($unique) { if (empty($fields['id'])) { $lowercase_entity = _civicrm_api_get_entity_name_from_camel(_civicrm_api_get_entity_name_from_dao($bao)); $fields['id'] = $fields[$lowercase_entity . '_id']; unset($fields[$lowercase_entity . '_id']); } return $fields; } foreach ($fields as $field) { $dbFields[$field['name']] = $field; } return $dbFields; }
/** * @param string|CRM_Core_DAO $entity * @param array $clauses * @return mixed */ public static function selectWhereClause($entity, &$clauses) { $entityName = is_object($entity) ? _civicrm_api_get_entity_name_from_dao($entity) : $entity; return self::singleton()->invoke(2, $entityName, $clauses, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_selectWhereClause'); }