From 2bcd3d5462b0be70cb5edc0abe1d310081fffca8 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 7 Apr 2011 15:38:28 +0200 Subject: ACL beschleunigt, nur 2 SQL Abfragen, keine Schleife und Cache implementiert --- library/Pbs/Acl.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'library') diff --git a/library/Pbs/Acl.php b/library/Pbs/Acl.php index f3ed08e..798c5e5 100644 --- a/library/Pbs/Acl.php +++ b/library/Pbs/Acl.php @@ -2,18 +2,25 @@ class Pbs_Acl { + protected $cache; public static function checkRight($rightShortcut) { $userIDsNamespace = Zend_Session::namespaceGet('userIDs'); $roleID = $userIDsNamespace['roleID']; - $rightRolesMapper = new Application_Model_RightRolesMapper(); - $rightroles = $rightRolesMapper->findBy(array('roleID' => $roleID),true); + if(isset($this->cache[$roleID][$rightShortcut])) + return $this->cache[$roleID][$rightShortcut]; + $rightMapper = new Application_Model_RightMapper(); - foreach($rightroles as $rightrole) { - $right = $rightMapper->find($rightrole['rightID']); - if($right->getShortcut() == $rightShortcut) { - return true; - } + $element = $rightMapper->findBy(array('shortcut',$rightshortcut)); + if($element == null) + return false; + + $rightRolesMapper = new Application_Model_RightRolesMapper(); + $rightroles = $rightRolesMapper->findBy(array('roleID' => $roleID,'rightID',$element->getID())); + if(count($rightroles) >=1){ + $this->cache[$roleID][$rightShortcut] = true; + return true; } + $this->cache[$roleID][$rightShortcut] = false; return false; } -- cgit v1.2.3-55-g7522