コード例 #1
0
ファイル: Getlist.php プロジェクト: nielosz/civicrm-core
/**
 * Generic api wrapper used for quicksearch and autocomplete.
 *
 * @param array $apiRequest
 *
 * @return mixed
 */
function civicrm_api3_generic_getList($apiRequest)
{
    $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']);
    $request = $apiRequest['params'];
    $meta = civicrm_api3_generic_getfields(array('action' => 'get') + $apiRequest, FALSE);
    // Hey api, would you like to provide default values?
    $fnName = "_civicrm_api3_{$entity}_getlist_defaults";
    $defaults = function_exists($fnName) ? $fnName($request) : array();
    _civicrm_api3_generic_getList_defaults($entity, $request, $defaults, $meta['values']);
    // Hey api, would you like to format the search params?
    $fnName = "_civicrm_api3_{$entity}_getlist_params";
    $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_params';
    $fnName($request);
    $request['params']['check_permissions'] = !empty($apiRequest['params']['check_permissions']);
    $result = civicrm_api3($entity, 'get', $request['params']);
    // Hey api, would you like to format the output?
    $fnName = "_civicrm_api3_{$entity}_getlist_output";
    $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_output';
    $values = $fnName($result, $request, $entity, $meta['values']);
    _civicrm_api3_generic_getlist_postprocess($result, $request, $values);
    $output = array('page_num' => $request['page_num']);
    // Limit is set for searching but not fetching by id
    if (!empty($request['params']['options']['limit'])) {
        // If we have an extra result then this is not the last page
        $last = $request['params']['options']['limit'] - 1;
        $output['more_results'] = isset($values[$last]);
        unset($values[$last]);
    }
    return civicrm_api3_create_success($values, $request['params'], $entity, 'getlist', CRM_Core_DAO::$_nullObject, $output);
}
コード例 #2
0
ファイル: Generic.php プロジェクト: nielosz/civicrm-core
/**
 * Provide metadata for this generic action
 *
 * @param $params
 * @param $apiRequest
 */
function _civicrm_api3_generic_getoptions_spec(&$params, $apiRequest)
{
    $params += array('field' => array('title' => 'Field name', 'api.required' => 1, 'type' => CRM_Utils_Type::T_STRING), 'context' => array('title' => 'Context', 'type' => CRM_Utils_Type::T_STRING, 'options' => CRM_Core_DAO::buildOptionsContext()));
    // Add available fields if requested
    if (array_intersect(array('all', 'field'), $apiRequest['params']['options']['get_options'])) {
        $fields = civicrm_api3_generic_getfields(array('entity' => $apiRequest['entity'], array('params' => array('action' => 'create'))));
        $params['field']['options'] = array();
        foreach ($fields['values'] as $name => $field) {
            if (isset($field['pseudoconstant']) || CRM_Utils_Array::value('type', $field) == CRM_Utils_Type::T_BOOLEAN) {
                $params['field']['options'][$name] = CRM_Utils_Array::value('title', $field, $name);
            }
        }
    }
}
コード例 #3
0
 /**
  * @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));
 }
コード例 #4
0
 /**
  * @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");
 }
コード例 #5
0
 /**
  * @inheritDoc
  */
 protected function getFields()
 {
     require_once 'api/v3/Generic.php';
     // Call this function directly instead of using the api wrapper to force unique field names off
     $apiSpec = \civicrm_api3_generic_getfields(array('entity' => $this->entity, 'version' => 3, 'params' => array('action' => 'get')), FALSE);
     return $apiSpec['values'];
 }