[geeklog-cvs] Geeklog-2/system/Propel/Geeklog-2 Gl2User.php,1.1.1.1,1.2 Gl2Item.php,1.1.1.1,1.2

vinny at iowaoutdoors.org vinny at iowaoutdoors.org
Wed Dec 29 00:09:59 EST 2004


Update of /var/cvs/Geeklog-2/system/Propel/Geeklog-2
In directory www:/tmp/cvs-serv15010

Modified Files:
	Gl2User.php Gl2Item.php 
Log Message:
Added $item->hasAccess method and supporting $user->getGroups method


Index: Gl2User.php
===================================================================
RCS file: /var/cvs/Geeklog-2/system/Propel/Geeklog-2/Gl2User.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Gl2User.php	17 Dec 2004 23:35:47 -0000	1.1.1.1
--- Gl2User.php	29 Dec 2004 05:09:57 -0000	1.2
***************
*** 15,17 ****
--- 15,59 ----
  class Gl2User extends BaseGl2User {
  
+     /**
+      * used by getGroups to store all user's grups
+      */
+     private var $_groups;
+ 
+     /**
+      * Function fetches all groups to which $this belongs including nested groups
+      *
+      * @author Vincent Furia <vinny01 at users.sf.net>
+      * @param User $user user object
+      */
+     function getGroups($force = false) {
+ 
+         // Don't do any work if the value is already cached
+         if ( empty($this->_groups) || $force == true ) {
+             //get user's base group assignments
+             $groups = $this->getGl2GroupAssignments();
+             //Get the group ids for the fetched groups
+             foreach ($groups as $group) {
+                 $this->_groups[] = $group->getMainGroupId();
+                 $ngroups[] = $group->getMainGroupId();
+             }
+ 
+             //Fetch subgroups recursively
+             while ( sizeof($ngroups) > 0 ) ) {
+                 //Get the subgroups of the current group list
+                 $c = new Criteria();
+                 $c->add(Gl2GroupAssignmentPeer::ASSIGNED_GROUP_ID, $ngroups, Criteria::IN);
+                 $groups = Gl2GroupAssignmentPeer::doSelect($c);
+                 //Get the group ids for the fetched groups
+                 foreach ($groups as $group) {
+                     if ( !in_array( $group->getMainGroupId() ) ) {
+                         $this->_groups[] = $group->getMainGroupId();
+                         $ngroups[] = $group->getMainGroupId();
+                     }
+                 }
+             }
+         }
+ 
+         return $this->_groups;
+     }
+ 
  }

Index: Gl2Item.php
===================================================================
RCS file: /var/cvs/Geeklog-2/system/Propel/Geeklog-2/Gl2Item.php,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Gl2Item.php	17 Dec 2004 23:35:47 -0000	1.1.1.1
--- Gl2Item.php	29 Dec 2004 05:09:57 -0000	1.2
***************
*** 15,17 ****
--- 15,53 ----
  class Gl2Item extends BaseGl2Item {
  
+     /**
+      * Function to determine a user's access level to $this
+      *
+      * @author Vincent Furia <vinny01 at users.sf.net>
+      * @param User $user user object
+      */
+     function hasAccess($user = '') {
+         
+         // Default rights
+         $rights = 0;
+         
+         // Make sure we are checking access for a user
+         if ( !is_a($user, 'User') ) {
+             // FIXME: get the current user object (from the session?)
+         }
+ 
+         // Get the Full ACL for $this 
+         $acls = $this->getGl2ItemAcls();
+         
+         // Check (and apply as necessary) each access control row in the list
+         foreach ($acls as $acl) {
+             // Check for $user access level
+             if ( $acl->getUserId() == $user->getUserId() ) {
+                 $rights |= $acl->getRights();
+             }
+ 
+             // Check for $user's groups access level
+             if ( $acl->getGroupId() != null && 
+                  in_array($acl->getGroupId(), $this->getGroups()) ) {
+                 $rights |= $acl->getRights();
+             }
+         }
+ 
+         return $rights;
+     }
+ 
  }




More information about the geeklog-cvs mailing list