Merge branch '4.7.29-rc' of https://github.com/civicrm/civicrm-core into merge
[civicrm-core.git] / CRM / ACL / API.php
index c5ae1243cbf243bde82a2eef78f9ee166b3c8e1f..3337c4ab9b897c8846d2bcd028a46d2200e72ee1 100644 (file)
@@ -190,10 +190,8 @@ class CRM_ACL_API {
    * @param string $tableName
    * @param null $allGroups
    * @param null $includedGroups
-   * @param bool $flush
    *
-   * @return array
-   *   the ids of the groups for which the user has permissions
+   * @return bool
    */
   public static function groupPermission(
     $type,
@@ -201,39 +199,23 @@ class CRM_ACL_API {
     $contactID = NULL,
     $tableName = 'civicrm_saved_search',
     $allGroups = NULL,
-    $includedGroups = NULL,
-    $flush = FALSE
+    $includedGroups = NULL
   ) {
 
-    static $cache = array();
-    $groups = array();
-    //@todo this is pretty hacky!!!
-    //adding a way for unit tests to flush the cache
-    if ($flush) {
-      $cache = array();
-      return NULL;
+    if (!isset(Civi::$statics[__CLASS__]) || !isset(Civi::$statics[__CLASS__]['group_permission'])) {
+      Civi::$statics[__CLASS__]['group_permission'] = array();
     }
+
     if (!$contactID) {
-      $session = CRM_Core_Session::singleton();
-      $contactID = NULL;
-      if ($session->get('userID')) {
-        $contactID = $session->get('userID');
-      }
+      $contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
     }
 
     $key = "{$tableName}_{$type}_{$contactID}";
-    if (array_key_exists($key, $cache)) {
-      $groups = &$cache[$key];
-    }
-    else {
-      $groups = self::group($type, $contactID, $tableName, $allGroups, $includedGroups);
-      $cache[$key] = $groups;
-    }
-    if (empty($groups)) {
-      return FALSE;
+    if (!array_key_exists($key, Civi::$statics[__CLASS__]['group_permission'])) {
+      Civi::$statics[__CLASS__]['group_permission'][$key] = self::group($type, $contactID, $tableName, $allGroups, $includedGroups);
     }
 
-    return in_array($groupID, $groups) ? TRUE : FALSE;
+    return in_array($groupID, Civi::$statics[__CLASS__]['group_permission'][$key]);
   }
 
 }