X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FGroup.php;h=cb56c7317810f0a19796b42644888945718499d7;hb=bee6039a9e7d03a9aa639db45d4098720f90c5fa;hp=75332c0c9f005378d8afa7311ff08f5a25deaa50;hpb=57550a570f4f538d3cc40939b678d9122156973c;p=civicrm-core.git diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 75332c0c9f..cb56c73178 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -1,7 +1,7 @@ copyValues($params); if ($group->find(TRUE)) { @@ -67,17 +66,16 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } /** - * Function to delete the group and all the object that connect to + * Delete the group and all the object that connect to * this group. Incredibly destructive * * @param int $id group id * * @return null - * @access public * @static * */ - static function discard($id) { + public static function discard($id) { CRM_Utils_Hook::pre('delete', 'Group', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); @@ -145,7 +143,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * Returns an array of the contacts in the given group. * */ - static function getGroupContacts($id) { + public static function getGroupContacts($id) { $params = array(array('group', 'IN', array($id => 1), 0, 0)); list($contacts, $_) = CRM_Contact_BAO_Query::apiQuery($params, array('contact_id')); return $contacts; @@ -160,9 +158,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @param bool $countChildGroups * * @return int count of members in the group with above status - * @access public */ - static function memberCount($id, $status = 'Added', $countChildGroups = FALSE) { + public static function memberCount($id, $status = 'Added', $countChildGroups = FALSE) { $groupContact = new CRM_Contact_DAO_GroupContact(); $groupIds = array($id); if ($countChildGroups) { @@ -201,16 +198,13 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { /** * Get the list of member for a group id * - * @param $groupID + * @param int $groupID * @param bool $useCache * - * @internal param int $lngGroupId this is group id - * - * @return array $aMembers this arrray contains the list of members for this group id - * @access public + * @return array $aMembers this array contains the list of members for this group id * @static */ - static function &getMember($groupID, $useCache = TRUE) { + public static function &getMember($groupID, $useCache = TRUE) { $params = array(array('group', 'IN', array($groupID => 1), 0, 0)); $returnProperties = array('contact_id'); list($contacts, $_) = CRM_Contact_BAO_Query::apiQuery($params, $returnProperties, NULL, NULL, 0, 0, $useCache); @@ -226,7 +220,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { /** * Returns array of group object(s) matching a set of one or Group properties. * - * @param null $params + * @param array $params Limits the set of groups returned. * @param array $returnProperties Which properties should be included in the returned group objects. * (member_count should be last element.) * @@ -234,11 +228,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @param null $offset * @param null $rowCount * - * @internal param array $param Array of one or more valid property_name=>value pairs. - * Limits the set of groups returned. - * @return An array of group objects. + * @return array of group objects. * - * @access public * * @todo other BAO functions that use returnProperties (e.g. Query Objects) receive the array flipped & filled with 1s and * add in essential fields (e.g. id). This should follow a regular pattern like the others @@ -307,15 +298,14 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } /** - * make sure that the user has permission to access this group + * Make sure that the user has permission to access this group * * @param int $id the id of the object * * @return string the permission that the user has (or null) - * @access public * @static */ - static function checkPermission($id) { + public static function checkPermission($id) { $allGroups = CRM_Core_PseudoConstant::allGroup(); $permissions = NULL; @@ -351,7 +341,6 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @param array $params Associative array of parameters * * @return object|null The new group BAO (if created) - * @access public * @static */ public static function &create(&$params) { @@ -507,10 +496,10 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } /** - * given a saved search compute the clause and the tables + * Given a saved search compute the clause and the tables * and store it for future use */ - function buildClause() { + public function buildClause() { $params = array(array('group', 'IN', array($this->id => 1), 0, 0)); if (!empty($params)) { @@ -533,7 +522,6 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @param array $params Associative array of parameters * * @return object|null The new group BAO (if created) - * @access public * @static */ public static function createSmartGroup(&$params) { @@ -556,7 +544,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } /** - * update the is_active flag in the db + * Update the is_active flag in the db * * @param int $id id of the database record * @param boolean $isActive value we want to set the is_active field @@ -564,12 +552,12 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @return Object DAO object on sucess, null otherwise * @static */ - static function setIsActive($id, $isActive) { + public static function setIsActive($id, $isActive) { return CRM_Core_DAO::setFieldValue('CRM_Contact_DAO_Group', $id, 'is_active', $isActive); } /** - * build the condition to retrieve groups. + * Build the condition to retrieve groups. * * @param string $groupType type of group(Access/Mailing) OR the key of the group * @param bool|\boolen $excludeHidden exclude hidden groups. @@ -577,7 +565,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @return string $condition * @static */ - static function groupTypeCondition($groupType = NULL, $excludeHidden = TRUE) { + public static function groupTypeCondition($groupType = NULL, $excludeHidden = TRUE) { $value = NULL; if ($groupType == 'Mailing') { $value = CRM_Core_DAO::VALUE_SEPARATOR . '2' . CRM_Core_DAO::VALUE_SEPARATOR; @@ -608,13 +596,9 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } /** - * get permission relevant clauses + * Get permission relevant clauses * CRM-12209 * - * @internal param $existingClauses - * - * @internal param $clauses - * * @param bool $force * * @return array @@ -651,10 +635,9 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @param array $params ( reference ) an assoc array of name/value pairs * * @return array ( smartGroupId, ssId ) smart group id and saved search id - * @access public * @static */ - static function createHiddenSmartGroup($params) { + public static function createHiddenSmartGroup($params) { $ssId = CRM_Utils_Array::value('saved_search_id', $params); //add mapping record only for search builder saved search @@ -725,7 +708,6 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * -page= offset * @todo there seems little reason for the small number of functions that call this to pass in * params that then need to be translated in this function since they are coding them when calling - * @access public */ static public function getGroupListSelector(&$params) { // format the params @@ -790,9 +772,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @param array $params associated array for params * * @return array - * @access public */ - static function getGroupList(&$params) { + public static function getGroupList(&$params) { $config = CRM_Core_Config::singleton(); $whereClause = self::whereClause($params, FALSE); @@ -831,12 +812,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } $query = " - SELECT groups.*, createdBy.sort_name as created_by, IF(groups.saved_search_id, COUNT(smart_contacts.id), COUNT(contacts.id)) as `count` {$select} + SELECT groups.*, createdBy.sort_name as created_by {$select} FROM civicrm_group groups - LEFT JOIN civicrm_group_contact contacts - ON contacts.group_id = groups.id AND contacts.status = 'Added' - LEFT JOIN civicrm_group_contact_cache smart_contacts - ON smart_contacts.group_id = groups.id LEFT JOIN civicrm_contact createdBy ON createdBy.id = groups.created_id {$from} @@ -861,7 +838,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { $links = self::actionLinks(); $allTypes = CRM_Core_OptionGroup::values('group_type'); - $values = array(); + $values = $groupsToCount = array(); $visibility = CRM_Core_SelectValues::ufVisibility(); @@ -873,7 +850,10 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { if ($permission) { $newLinks = $links; - $values[$object->id] = array('class' => array()); + $values[$object->id] = array( + 'class' => array(), + 'count' => '0', + ); CRM_Core_DAO::storeValues($object, $values[$object->id]); if ($object->saved_search_id) { $values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')'; @@ -917,7 +897,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { $values[$object->id]['visibility'] = $visibility[$values[$object->id]['visibility']]; - $values[$object->id]['count'] = $object->count; + $groupsToCount[$object->saved_search_id ? 'civicrm_group_contact_cache' : 'civicrm_group_contact'][] = $object->id; if (isset($values[$object->id]['group_type'])) { $groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, @@ -973,6 +953,18 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { } } + // Get group counts + foreach ($groupsToCount as $table => $groups) { + $where = "group_id IN (" . implode(',', $groups) . ")"; + if ($table == 'civicrm_group_contact') { + $where .= " AND status = 'Added'"; + } + $dao = CRM_Core_DAO::executeQuery("SELECT group_id, COUNT(id) as `count` FROM $table WHERE $where GROUP BY group_id"); + while($dao->fetch()) { + $values[$dao->group_id]['count'] = $dao->count; + } + } + return $values; } @@ -986,7 +978,6 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { * @param bool $titleOnly * * @return array - * @access public */ static function getGroupsHierarchy( $groupIDs, @@ -1112,11 +1103,11 @@ WHERE id IN $groupIdString } /** - * @param $params + * @param array $params * * @return null|string */ - static function getGroupCount(&$params) { + public static function getGroupCount(&$params) { $whereClause = self::whereClause($params, FALSE); $query = "SELECT COUNT(*) FROM civicrm_group groups"; @@ -1132,13 +1123,13 @@ WHERE {$whereClause}"; /** * Generate permissioned where clause for group search - * @param $params + * @param array $params * @param bool $sortBy * @param bool $excludeHidden * * @return string */ - static function whereClause(&$params, $sortBy = TRUE, $excludeHidden = TRUE) { + public static function whereClause(&$params, $sortBy = TRUE, $excludeHidden = TRUE) { $values = array(); $title = CRM_Utils_Array::value('title', $params); if ($title) { @@ -1223,12 +1214,11 @@ WHERE {$whereClause}"; } /** - * Function to define action links + * Define action links * * @return array $links array of action links - * @access public */ - static function actionLinks() { + public static function actionLinks() { $links = array( CRM_Core_Action::VIEW => array( 'name' => ts('Contacts'), @@ -1265,11 +1255,11 @@ WHERE {$whereClause}"; /** * @param $whereClause - * @param $whereParams + * @param array $whereParams * * @return string */ - function pagerAtoZ($whereClause, $whereParams) { + public function pagerAtoZ($whereClause, $whereParams) { $query = " SELECT DISTINCT UPPER(LEFT(groups.title, 1)) as sort_name FROM civicrm_group groups @@ -1281,4 +1271,3 @@ WHERE {$whereClause}"; return CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE); } } -