/** * Get all groups from database, filtered by permissions * for this user * * @param string $groupType type of group(Access/Mailing) * @param boolen $excludeHidden exclude hidden groups. * * @access public * @static * * @return array - array reference of all groups. * */ public static function &group($groupType = null, $excludeHidden = true) { if (!isset(self::$_viewPermissionedGroups)) { self::$_viewPermissionedGroups = self::$_editPermissionedGroups = array(); $groups =& CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden); if (self::check('edit all contacts')) { // this is the most powerful permission, so we return // immediately rather than dilute it further self::$_editAdminUser = self::$_viewAdminUser = true; self::$_editPermission = self::$_viewPermission = true; self::$_editPermissionedGroups = $groups; self::$_viewPermissionedGroups = $groups; return self::$_viewPermissionedGroups; } else { if (self::check('view all contacts')) { self::$_viewAdminUser = true; self::$_viewPermission = true; self::$_viewPermissionedGroups = $groups; } } require_once 'CRM/ACL/API.php'; $ids = CRM_ACL_API::group(CRM_Core_Permission::VIEW, null, 'civicrm_saved_search', $groups); foreach (array_values($ids) as $id) { $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'title'); self::$_viewPermissionedGroups[$id] = $title; self::$_viewPermission = true; } $ids = CRM_ACL_API::group(CRM_Core_Permission::EDIT, null, 'civicrm_saved_search', $groups); foreach (array_values($ids) as $id) { $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $id, 'title'); self::$_editPermissionedGroups[$id] = $title; self::$_viewPermissionedGroups[$id] = $title; self::$_editPermission = true; self::$_viewPermission = true; } } return self::$_viewPermissionedGroups; }
/** * Get the permissioned where clause for the user * * @param int $type the type of permission needed * @param array $tables (reference ) add the tables that are needed for the select clause * @param array $whereTables (reference ) add the tables that are needed for the where clause * * @return string the group where clause for this user * @access public */ function whereClause($type, &$tables, &$whereTables) { CRM_Core_Permission_Drupal::group(); return CRM_Core_Permission_Drupal::groupClause($type, $tables, $whereTables); }