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


PHP CRM_Core_Permission::whereClause方法代码示例

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


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

示例1: getGroupContacts

 /**
  * Returns array of contacts who are members of the specified group.
  *
  * @param CRM_Contact $group                A valid group object (passed by reference)
  * @param array       $returnProperties     Which properties
  *                    should be included in the returned Contact object(s). If NULL,
  *                    the default set of contact properties will be
  *                    included. group_contact properties (such as 'status',
  * '                  in_date', etc.) are included automatically.Note:Do not inclue
  *                    Id releted properties.  
  * @param text        $status               A valid status value ('Added', 'Pending', 'Removed').
  * @param text        $sort                 Associative array of
  *                    one or more "property_name"=>"sort direction"
  *                    pairs which will control order of Contact objects returned.
  * @param Int         $offset               Starting row index.
  * @param Int         $row_count            Maximum number of rows to returns.
  *
  *
  * @return            $contactArray         Array of contacts who are members of the specified group
  *
  * @access public
  */
 static function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null, $includeChildGroups = false)
 {
     $groupDAO =& new CRM_Contact_DAO_Group();
     $groupDAO->id = $group->id;
     if (!$groupDAO->find(true)) {
         return CRM_Core_Error::createError("Could not locate group with id: {$id}");
     }
     // make sure user has got permission to view this group
     require_once 'CRM/Contact/BAO/Group.php';
     if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
         return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
     }
     $query = '';
     if (empty($returnProperties)) {
         $query = "SELECT contact_a.id as contact_id,\n                      civicrm_email.email as email";
     } else {
         $query = "SELECT contact_a.id as contact_id , {$grpStatus} as status,";
         $query .= implode(',', $returnProperties);
     }
     $params = array();
     if ($includeChildGroups) {
         require_once 'CRM/Contact/BAO/GroupNesting.php';
         $groupIds = CRM_Contact_BAO_GroupNesting::getDescendentGroupIds(array($group->id));
     } else {
         $groupIds = array($group->id);
     }
     foreach ($groupIds as $groupId) {
         $params[] = array('group', 'IN', array($group->id => true), 0, 0);
     }
     require_once 'CRM/Core/BAO/Email.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $tables = array(CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true);
     $inner = array();
     $whereTables = array();
     $where = CRM_Contact_BAO_Query::getWhereClause($params, null, $tables, $whereTables);
     $permission = CRM_Core_Permission::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables);
     $from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
     $query .= " {$from} WHERE {$permission} AND {$where} ";
     if ($sort != null) {
         $order = array();
         foreach ($sort as $key => $direction) {
             $order[] = " {$key} {$direction} ";
         }
         $query .= " ORDER BY " . implode(',', $order);
     }
     if (!is_null($offset) && !is_null($row_count)) {
         $query .= " LIMIT {$offset}, {$row_count}";
     }
     $dao =& new CRM_Contact_DAO_Contact();
     $dao->query($query);
     // this is quite inefficient, we need to change the return
     // values in docs
     $contactArray = array();
     while ($dao->fetch()) {
         $contactArray[] = clone $dao;
     }
     return $contactArray;
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:80,代码来源:GroupContact.php

示例2: searchQuery

 /**
  * create and query the db for an contact search
  *
  * @param int      $offset   the offset for the query
  * @param int      $rowCount the number of rows to return
  * @param string   $sort     the order by string
  * @param boolean  $count    is this a count only query ?
  * @param boolean  $includeContactIds should we include contact ids?
  * @param boolean  $sortByChar if true returns the distinct array of first characters for search results
  * @param boolean  $groupContacts if true, use a single mysql group_concat statement to get the contact ids
  * @param boolean  $returnQuery   should we return the query as a string
  * @param string   $additionalWhereClause if the caller wants to further restrict the search (used in contributions)
  *
  * @return CRM_Contact_DAO_Contact 
  * @access public
  */
 function searchQuery($offset = 0, $rowCount = 0, $sort = null, $count = false, $includeContactIds = false, $sortByChar = false, $groupContacts = false, $returnQuery = false, $additionalWhereClause = null)
 {
     require_once 'CRM/Core/Permission.php';
     if ($includeContactIds) {
         $this->_includeContactIds = true;
         $this->includeContactIds();
     }
     // hack for now, add permission only if we are in search
     $permission = ' ( 1 ) ';
     if ($this->_search) {
         $permission = CRM_Core_Permission::whereClause(CRM_CORE_PERMISSION_VIEW, $this->_tables, $this->_whereTables);
         // regenerate fromClause since permission might have added tables
         if ($permission) {
             $this->_fromClause = CRM_Contact_BAO_Query::fromClause($this->_tables, null, null, $this->_primaryLocation, $this->_mode);
             $this->_simpleFromClause = CRM_Contact_BAO_Query::fromClause($this->_whereTables, null, null, $this->_primaryLocation, $this->_mode);
         }
     }
     list($select, $from, $where) = $this->query($count, $sortByChar, $groupContacts);
     if (empty($where)) {
         $where = 'WHERE ' . $permission;
     } else {
         $where = $where . ' AND ' . $permission;
     }
     if ($additionalWhereClause) {
         $where = $where . ' AND ' . $additionalWhereClause;
     }
     $order = $limit = '';
     if (!$count) {
         if ($sort) {
             $orderBy = trim($sort->orderBy());
             if (!empty($orderBy)) {
                 $order = " ORDER BY {$orderBy}";
             }
         } else {
             if ($sortByChar) {
                 $order = " ORDER BY LEFT(civicrm_contact.sort_name, 1) ";
             }
         }
         if ($rowCount > 0 && $offset >= 0) {
             $limit = " LIMIT {$offset}, {$rowCount} ";
         }
     }
     // building the query string
     $query = "{$select} {$from} {$where} {$order} {$limit}";
     //CRM_Core_Error::debug( 'q', $query );
     if ($returnQuery) {
         return $query;
     }
     if ($count) {
         return CRM_Core_DAO::singleValueQuery($query);
     }
     // CRM_Core_Error::debug( 'q', $query );
     $dao =& CRM_Core_DAO::executeQuery($query);
     if ($groupContacts) {
         $ids = array();
         while ($dao->fetch()) {
             $ids[] = $dao->id;
         }
         return implode(',', $ids);
     }
     return $dao;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:78,代码来源:Query.php

示例3: getGroupContacts

 /**
  * Returns array of contacts who are members of the specified group.
  *
  * @param CRM_Contact $group                A valid group object (passed by reference)
  * @param array       $returnProperties     Which properties
  *                    should be included in the returned Contact object(s). If NULL,
  *                    the default set of contact properties will be
  *                    included. group_contact properties (such as 'status',
  * '                  in_date', etc.) are included automatically.Note:Do not inclue
  *                    Id releted properties.  
  * @param text        $status               A valid status value ('Added', 'Pending', 'Removed').
  * @param text        $sort                 Associative array of
  *                    one or more "property_name"=>"sort direction"
  *                    pairs which will control order of Contact objects returned.
  * @param Int         $offset               Starting row index.
  * @param Int         $row_count            Maximum number of rows to returns.
  *
  *
  * @return            $contactArray         Array of contacts who are members of the specified group
  *
  * @access public
  */
 function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null)
 {
     $query = "SELECT * FROM civicrm_group WHERE id = " . CRM_Utils_Type::escape($group->id, 'Integer');
     $groupDAO =& new CRM_Contact_DAO_Group();
     $groupDAO->id = $group->id;
     if (!$groupDAO->find(true)) {
         return CRM_Core_Error::createError("Could not locate group with id: {$id}");
     }
     // make sure user has got permission to view this group
     if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
         return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
     }
     $query = '';
     if (empty($returnProperties)) {
         $query = "SELECT civicrm_contact.id as contact_id,\n                      civicrm_email.email as email";
         //$query = "SELECT *,civicrm_contact.id as contact_id, (talk to lobo before re-enabling this)
         //civicrm_email.email as email";
     } else {
         $query = "SELECT civicrm_contact.id as contact_id ,";
         $query .= implode(',', $returnProperties);
     }
     $fv = array('group' => array($group->id => true));
     if ($status) {
         $fv['group_contact_status'] = array($status => true);
     } else {
         $fv['group_contact_status'] = array('Added' => true, 'Removed' => true, 'Pending' => true);
     }
     $tables = array(CRM_Contact_BAO_GroupContact::getTableName() => true, CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true, CRM_Contact_BAO_Group::getTableName() => true);
     $inner = array();
     $whereTables = array();
     $where = CRM_Contact_BAO_Query::getWhereClause($fv, null, $tables, $whereTables);
     $permission = CRM_Core_Permission::whereClause(CRM_CORE_PERMISSION_VIEW, $tables, $whereTables);
     $from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
     $query .= " {$from} WHERE {$permission} AND {$where} ";
     if ($sort != null) {
         $order = array();
         foreach ($sort as $key => $direction) {
             $order[] = " {$key} {$direction} ";
         }
         $query .= " ORDER BY " . implode(',', $order);
     }
     if ($offset != null && $row_count != null) {
         $query .= " LIMIT {$offset}, {$row_count}";
     }
     // CRM_Core_Error::debug( 'q', $query );
     $dao =& new CRM_Contact_DAO_Contact();
     $dao->query($query);
     // this is quite inefficient, we need to change the return
     // values in docs
     $contactArray = array();
     while ($dao->fetch()) {
         $contactArray[] = clone $dao;
     }
     return $contactArray;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:77,代码来源:GroupContact.php

示例4: permissionedContact

 /**
  * check if the logged in user has permissions for the operation type
  *
  * @param int    $id   contact id
  * @param string $type the type of operation (view|edit)
  *
  * @return boolean true if the user has permission, false otherwise
  * @access public
  * @static
  */
 function permissionedContact($id, $type = CRM_CORE_PERMISSION_VIEW)
 {
     $tables = array();
     $temp = array();
     $permission = CRM_Core_Permission::whereClause($type, $tables, $temp);
     $from = CRM_Contact_BAO_Query::fromClause($tables);
     $query = "\nSELECT count(DISTINCT civicrm_contact.id) \n       {$from}\nWHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer') . " AND {$permission}";
     return CRM_Core_DAO::singleValueQuery($query) > 0 ? true : false;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:19,代码来源:Contact.php


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