X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FBAO%2FGroup.php;h=6885eec95e27debc69a79b4200fe4128a9f562f4;hb=6d054a8eae93955781108227e06d2d885a334a08;hp=a238a16dd1b109eaf7fcc55c182364fb66156237;hpb=e1879d34c98fad404278b1611e4c02bed2332eab;p=civicrm-core.git
diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php
index a238a16dd1..6885eec95e 100644
--- a/CRM/Contact/BAO/Group.php
+++ b/CRM/Contact/BAO/Group.php
@@ -468,7 +468,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
CRM_Contact_BAO_GroupOrganization::add($groupOrg);
}
- CRM_Utils_System::flushCache();
+ self::flushCaches();
CRM_Contact_BAO_GroupContactCache::add($group->id);
if (!empty($params['id'])) {
@@ -631,6 +631,25 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
return $clause;
}
+ /**
+ * Flush caches that hold group data.
+ *
+ * (Actually probably some overkill at the moment.)
+ */
+ protected static function flushCaches() {
+ CRM_Utils_System::flushCache();
+ $staticCaches = array(
+ 'CRM_Core_PseudoConstant' => 'groups',
+ 'CRM_ACL_API' => 'group_permission',
+ 'CRM_ACL_BAO_ACL' => 'permissioned_groups',
+ );
+ foreach ($staticCaches as $class => $key) {
+ if (isset(Civi::$statics[$class][$key])) {
+ unset(Civi::$statics[$class][$key]);
+ }
+ }
+ }
+
/**
* @return string
*/
@@ -826,12 +845,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
* @return array
*/
public static function getGroupList(&$params) {
- $config = CRM_Core_Config::singleton();
-
$whereClause = self::whereClause($params, FALSE);
- //$this->pagerAToZ( $whereClause, $params );
-
$limit = "";
if (!empty($params['rowCount']) &&
$params['rowCount'] > 0
@@ -900,115 +915,108 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
$visibility = CRM_Core_SelectValues::ufVisibility();
while ($object->fetch()) {
- $permission = CRM_Contact_BAO_Group::checkPermission($object->id, $object->title);
- //@todo CRM-12209 introduced an ACL check in the whereClause function
- // it may be that this checking is now obsolete - or that what remains
- // should be removed to the whereClause (which is also accessed by getCount)
-
- if ($permission) {
- $newLinks = $links;
- $values[$object->id] = array(
- 'class' => array(),
- 'count' => '0',
+ $newLinks = $links;
+ $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') . ')';
+ // check if custom search, if so fix view link
+ $customSearchID = CRM_Core_DAO::getFieldValue(
+ 'CRM_Contact_DAO_SavedSearch',
+ $object->saved_search_id,
+ 'search_custom_id'
);
- CRM_Core_DAO::storeValues($object, $values[$object->id]);
-
- if ($object->saved_search_id) {
- $values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
- // check if custom search, if so fix view link
- $customSearchID = CRM_Core_DAO::getFieldValue(
- 'CRM_Contact_DAO_SavedSearch',
- $object->saved_search_id,
- 'search_custom_id'
- );
-
- if ($customSearchID) {
- $newLinks[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/search/custom';
- $newLinks[CRM_Core_Action::VIEW]['qs'] = "reset=1&force=1&ssID={$object->saved_search_id}";
- }
+
+ if ($customSearchID) {
+ $newLinks[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/search/custom';
+ $newLinks[CRM_Core_Action::VIEW]['qs'] = "reset=1&force=1&ssID={$object->saved_search_id}";
}
+ }
- $action = array_sum(array_keys($newLinks));
+ $action = array_sum(array_keys($newLinks));
- // CRM-9936
- if (array_key_exists('is_reserved', $object)) {
- //if group is reserved and I don't have reserved permission, suppress delete/edit
- if ($object->is_reserved && !$reservedPermission) {
- $action -= CRM_Core_Action::DELETE;
- $action -= CRM_Core_Action::UPDATE;
- $action -= CRM_Core_Action::DISABLE;
- }
+ // CRM-9936
+ if (array_key_exists('is_reserved', $object)) {
+ //if group is reserved and I don't have reserved permission, suppress delete/edit
+ if ($object->is_reserved && !$reservedPermission) {
+ $action -= CRM_Core_Action::DELETE;
+ $action -= CRM_Core_Action::UPDATE;
+ $action -= CRM_Core_Action::DISABLE;
}
+ }
- if (array_key_exists('is_active', $object)) {
- if ($object->is_active) {
- $action -= CRM_Core_Action::ENABLE;
- }
- else {
- $values[$object->id]['class'][] = 'disabled';
- $action -= CRM_Core_Action::VIEW;
- $action -= CRM_Core_Action::DISABLE;
- }
+ if (array_key_exists('is_active', $object)) {
+ if ($object->is_active) {
+ $action -= CRM_Core_Action::ENABLE;
}
+ else {
+ $values[$object->id]['class'][] = 'disabled';
+ $action -= CRM_Core_Action::VIEW;
+ $action -= CRM_Core_Action::DISABLE;
+ }
+ }
- $action = $action & CRM_Core_Action::mask($groupPermissions);
+ $action = $action & CRM_Core_Action::mask($groupPermissions);
- $values[$object->id]['visibility'] = $visibility[$values[$object->id]['visibility']];
+ $values[$object->id]['visibility'] = $visibility[$values[$object->id]['visibility']];
- $groupsToCount[$object->saved_search_id ? 'civicrm_group_contact_cache' : 'civicrm_group_contact'][] = $object->id;
+ $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,
- substr($values[$object->id]['group_type'], 1, -1)
- );
- $types = array();
- foreach ($groupTypes as $type) {
- $types[] = CRM_Utils_Array::value($type, $allTypes);
- }
- $values[$object->id]['group_type'] = implode(', ', $types);
- }
- $values[$object->id]['action'] = CRM_Core_Action::formLink($newLinks,
- $action,
- array(
- 'id' => $object->id,
- 'ssid' => $object->saved_search_id,
- ),
- ts('more'),
- FALSE,
- 'group.selector.row',
- 'Group',
- $object->id
+ if (isset($values[$object->id]['group_type'])) {
+ $groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR,
+ substr($values[$object->id]['group_type'], 1, -1)
);
-
- // If group has children, add class for link to view children
- $values[$object->id]['is_parent'] = FALSE;
- if (array_key_exists('children', $values[$object->id])) {
- $values[$object->id]['class'][] = "crm-group-parent";
- $values[$object->id]['is_parent'] = TRUE;
+ $types = array();
+ foreach ($groupTypes as $type) {
+ $types[] = CRM_Utils_Array::value($type, $allTypes);
}
+ $values[$object->id]['group_type'] = implode(', ', $types);
+ }
+ $values[$object->id]['action'] = CRM_Core_Action::formLink($newLinks,
+ $action,
+ array(
+ 'id' => $object->id,
+ 'ssid' => $object->saved_search_id,
+ ),
+ ts('more'),
+ FALSE,
+ 'group.selector.row',
+ 'Group',
+ $object->id
+ );
- // If group is a child, add child class
- if (array_key_exists('parents', $values[$object->id])) {
- $values[$object->id]['class'][] = "crm-group-child";
- }
+ // If group has children, add class for link to view children
+ $values[$object->id]['is_parent'] = FALSE;
+ if (array_key_exists('children', $values[$object->id])) {
+ $values[$object->id]['class'][] = "crm-group-parent";
+ $values[$object->id]['is_parent'] = TRUE;
+ }
- if ($groupOrg) {
- if ($object->org_id) {
- $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->org_id}");
- $values[$object->id]['org_info'] = "{$object->org_name}";
- }
- else {
- $values[$object->id]['org_info'] = ''; // Empty cell
- }
+ // If group is a child, add child class
+ if (array_key_exists('parents', $values[$object->id])) {
+ $values[$object->id]['class'][] = "crm-group-child";
+ }
+
+ if ($groupOrg) {
+ if ($object->org_id) {
+ $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->org_id}");
+ $values[$object->id]['org_info'] = "{$object->org_name}";
}
else {
- $values[$object->id]['org_info'] = NULL; // Collapsed column if all cells are NULL
- }
- if ($object->created_id) {
- $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->created_id}");
- $values[$object->id]['created_by'] = "{$object->created_by}";
+ $values[$object->id]['org_info'] = ''; // Empty cell
}
}
+ else {
+ $values[$object->id]['org_info'] = NULL; // Collapsed column if all cells are NULL
+ }
+ if ($object->created_id) {
+ $contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->created_id}");
+ $values[$object->id]['created_by'] = "{$object->created_by}";
+ }
}
// Get group counts - executes one query for regular groups and another for smart groups
@@ -1019,7 +1027,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group {
}
// Exclude deleted contacts
$where .= " and c.id = g.contact_id AND c.is_deleted = 0";
- $dao = CRM_Core_DAO::executeQuery("SELECT g.group_id, COUNT(g.id) as `count` FROM $table g, civicrm_contact c WHERE $where GROUP BY g.group_id");
+ $dao = CRM_Core_DAO::executeQuery("SELECT g.group_id, COUNT(*) as `count` FROM $table g, civicrm_contact c WHERE $where GROUP BY g.group_id");
while ($dao->fetch()) {
$values[$dao->group_id]['count'] = $dao->count;
}
@@ -1155,7 +1163,7 @@ WHERE id IN $groupIdString
// Changing to a for loop execustion takes around 0.02 seconds (20 ms).
if (isset($tree[$group['id']]) && is_array($tree[$group['id']])) {
for ($i = 0; $i < count($tree[$group['id']]); $i++) {
- self::buildGroupHierarchy($hierarchy, $tree[$group['id'][$i]], $tree, $titleOnly, $spacer, $level + 1);
+ self::buildGroupHierarchy($hierarchy, $tree[$group['id']][$i], $tree, $titleOnly, $spacer, $level + 1);
}
}
}