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


PHP CRM_Contact_BAO_Query::generatePermissionClause方法代码示例

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


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

示例1: apiQuery

 /**
  * These are stub comments as this function needs more explanation - particularly in terms of how it
  * relates to $this->searchQuery and why it replicates rather than calles $this->searchQuery.
  *
  * This function was originally written as a wrapper for the api query but is called from multiple places
  * in the core code directly so the name is misleading. This function does not use the searchQuery function
  * but it is unclear as to whehter that is historical or there is a reason
  *  CRM-11290 led to the permissioning action being extracted from searchQuery & shared with this function
  *
  * @param array $params
  * @param array $returnProperties
  * @param null $fields
  * @param string $sort
  * @param int $offset
  * @param int $row_count
  * @param bool $smartGroupCache
  *   ?? update smart group cache?.
  * @param bool $count
  *   Return count obnly.
  * @param bool $skipPermissions
  *   Should permissions be ignored or should the logged in user's permissions be applied.
  *
  *
  * @return array
  */
 public static function apiQuery($params = NULL, $returnProperties = NULL, $fields = NULL, $sort = NULL, $offset = 0, $row_count = 25, $smartGroupCache = TRUE, $count = FALSE, $skipPermissions = TRUE)
 {
     $query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, TRUE, FALSE, 1, $skipPermissions, TRUE, $smartGroupCache);
     //this should add a check for view deleted if permissions are enabled
     if ($skipPermissions) {
         $query->_skipDeleteClause = TRUE;
     }
     $query->generatePermissionClause(FALSE, $count);
     // note : this modifies _fromClause and _simpleFromClause
     $query->includePseudoFieldsJoin($sort);
     list($select, $from, $where, $having) = $query->query($count);
     $options = $query->_options;
     if (!empty($query->_permissionWhereClause)) {
         if (empty($where)) {
             $where = "WHERE {$query->_permissionWhereClause}";
         } else {
             $where = "{$where} AND {$query->_permissionWhereClause}";
         }
     }
     $sql = "{$select} {$from} {$where} {$having}";
     // add group by
     if ($query->_useGroupBy) {
         $sql .= ' GROUP BY contact_a.id';
     }
     if (!empty($sort)) {
         $sort = CRM_Utils_Type::escape($sort, 'String');
         $sql .= " ORDER BY {$sort} ";
     }
     if ($row_count > 0 && $offset >= 0) {
         $offset = CRM_Utils_Type::escape($offset, 'Int');
         $rowCount = CRM_Utils_Type::escape($row_count, 'Int');
         $sql .= " LIMIT {$offset}, {$row_count} ";
     }
     $dao = CRM_Core_DAO::executeQuery($sql);
     $values = array();
     while ($dao->fetch()) {
         if ($count) {
             $noRows = $dao->rowCount;
             $dao->free();
             return array($noRows, NULL);
         }
         $val = $query->store($dao);
         $convertedVals = $query->convertToPseudoNames($dao, TRUE);
         if (!empty($convertedVals)) {
             $val = array_replace_recursive($val, $convertedVals);
         }
         $values[$dao->contact_id] = $val;
     }
     $dao->free();
     return array($values, $options);
 }
开发者ID:hoegrammer,项目名称:civicrm-core,代码行数:76,代码来源:Query.php

示例2: civicrm_api3_contact_getstat

function civicrm_api3_contact_getstat ($params) {
 // mostly copy pasted from contact_get and the functions called by it
  $options = array();
  _civicrm_api3_contact_get_supportanomalies($params, $options);

  $contacts = _civicrm_api3_get_using_query_object('contact', $params, $options);
  $options = _civicrm_api3_get_options_from_params($params, TRUE);

  $inputParams = CRM_Utils_Array::value('input_params', $options, array());
  $returnProperties = CRM_Utils_Array::value('return', $options, array());

  if(!empty($params['check_permissions'])){
    // we will filter query object against getfields
    $fields = civicrm_api("contact", 'getfields', array('version' => 3, 'action' => 'get'));
    // we need to add this in as earlier in this function 'id' was unset in favour of $entity_id
    $fields['values'][$entity . '_id'] = array();
    $varsToFilter = array('returnProperties', 'inputParams');
    foreach ($varsToFilter as $varToFilter){
      if(!is_array($$varToFilter)){
        continue;
      }
      $$varToFilter = array_intersect_key($$varToFilter, $fields['values']);
    }
  }
//  $options = array_merge($options,$additional_options);
  $sort             = CRM_Utils_Array::value('sort', $options, NULL);
  $returnSQL        = CRM_Utils_Array::value('sql', $options, CRM_Utils_Array::value('options_sql', $options['input_params']));
  $smartGroupCache  = CRM_Utils_Array::value('smartGroupCache', $params);

  $newParams = CRM_Contact_BAO_Query::convertFormValues($inputParams);
  $skipPermissions = CRM_Utils_Array::value('check_permissions', $params)? 0 :1;

  $query = new CRM_Contact_BAO_Query(
    $params, $returnProperties,
    NULL, TRUE, FALSE, 1,
    $skipPermissions,
    TRUE, $smartGroupCache
  );

  //this should add a check for view deleted if permissions are enabled
  if ($skipPermissions){
    $query->_skipDeleteClause = TRUE;
  }
  $query->generatePermissionClause(FALSE, $count);
  list($select, $from, $where, $having) = $query->query($count);

  $options = $query->_options;
  if(!empty($query->_permissionWhereClause)){
    if (empty($where)) {
      $where = "WHERE $query->_permissionWhereClause";
    } else {
      $where = "$where AND $query->_permissionWhereClause";
    }
  }

  $sql = "$select $from $where $having";

  if (!empty($returnProperties)) {
    $extra = array();
    $sql = "SELECT count(*) AS total,". substr ($sql, 34,10000); //replace select contact_id, by select count(*)
    $sql .= " GROUP BY ". implode (",",array_keys($returnProperties)) ;
  } else {
    $sql = "SELECT count(*) AS total  $from $where $having";
    $extra = array ("tip"=>"if you need to group by a field, use the return param, eg return=contact_type,gender",
                    "warning"=> "use getcount, getstat without param might be blocked in the future"); 

    if (!empty($sort)) {
      $sql .= " ORDER BY $sort ";
    } else {
      $sql .= " ORDER BY total DESC ";
    }

  }

  if ($returnSQL) {
    return array("is_error"=>1,"sql"=>$sql,"from"=>$from,"where"=>$where,"having"=>$having);
  }
  $dao = CRM_Core_DAO::executeQuery($sql);
  $values = array();
  while ($dao->fetch()) {
    $values[] = $dao->toArray();
  }
  
  return civicrm_api3_create_success($values, $params, "contact", "getstat", $dao,$extra);
}
开发者ID:riyadennis,项目名称:my_civicrm,代码行数:85,代码来源:Getstat.php


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