当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Array::filterColumns方法代码示例

本文整理汇总了PHP中CRM_Utils_Array::filterColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Array::filterColumns方法的具体用法?PHP CRM_Utils_Array::filterColumns怎么用?PHP CRM_Utils_Array::filterColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Array的用法示例。


在下文中一共展示了CRM_Utils_Array::filterColumns方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: filter

 /**
  * Ensure that the return values comply with the whitelist's
  * "fields" policy.
  *
  * Most API's follow a convention where the result includes
  * a 'values' array (which in turn is a list of records). Unfortunately,
  * some don't. If the API result doesn't meet our expectation,
  * then we probably don't know what's going on, so we abort the
  * request.
  *
  * This will probably break some of the layered-sugar APIs (like
  * getsingle, getvalue). Just use the meat-and-potatoes API instead.
  * Or craft a suitably targeted patch.
  *
  * @param array $apiRequest
  *   API request.
  * @param array $apiResult
  *   API result.
  * @return array
  *   Modified API result.
  * @throws \API_Exception
  */
 public function filter($apiRequest, $apiResult)
 {
     if ($this->fields === '*') {
         return $apiResult;
     }
     if (isset($apiResult['values']) && empty($apiResult['values'])) {
         // No data; filtering doesn't matter.
         return $apiResult;
     }
     if (is_array($apiResult['values'])) {
         $firstRow = \CRM_Utils_Array::first($apiResult['values']);
         if (is_array($firstRow)) {
             $fields = $this->filterFields(array_keys($firstRow));
             $apiResult['values'] = \CRM_Utils_Array::filterColumns($apiResult['values'], $fields);
             return $apiResult;
         }
     }
     throw new \API_Exception(sprintf('Filtering failed for %s.%s. Unrecognized result format.', $apiRequest['entity'], $apiRequest['action']));
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:41,代码来源:WhitelistRule.php

示例2: _civicrm_api3_basic_array_get

/**
 * A generic "get" API based on simple array data. This is comparable to
 * _civicrm_api3_basic_get but does not use DAO/BAO. This is useful for
 * small/mid-size data loaded from external JSON or XML documents.
 *
 * @param array $params
 *   API parameters.
 * @param array $records
 *   List of all records.
 * @param string $idCol
 *   The property which defines the ID of a record
 * @param array $fields
 *   List of filterable fields.
 * @return array
 */
function _civicrm_api3_basic_array_get($entity, $params, $records, $idCol, $fields)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, $entity, 'get');
    // TODO // $sort = CRM_Utils_Array::value('sort', $options, NULL);
    $offset = CRM_Utils_Array::value('offset', $options);
    $limit = CRM_Utils_Array::value('limit', $options);
    $matches = array();
    $currentOffset = 0;
    foreach ($records as $record) {
        if ($idCol != 'id') {
            $record['id'] = $record[$idCol];
        }
        $match = TRUE;
        foreach ($params as $k => $v) {
            if ($k == 'id') {
                $k = $idCol;
            }
            if (in_array($k, $fields) && $record[$k] != $v) {
                $match = FALSE;
                break;
            }
        }
        if ($match) {
            if ($currentOffset >= $offset) {
                $matches[$record[$idCol]] = $record;
            }
            if ($limit && count($matches) >= $limit) {
                break;
            }
            $currentOffset++;
        }
    }
    $return = CRM_Utils_Array::value('return', $options, array());
    if (!empty($return)) {
        $return['id'] = 1;
        $matches = CRM_Utils_Array::filterColumns($matches, array_keys($return));
    }
    return civicrm_api3_create_success($matches, $params);
}
开发者ID:sugan2111,项目名称:Drupal_code,代码行数:54,代码来源:utils.php


注:本文中的CRM_Utils_Array::filterColumns方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。