diff --git a/application/modules/auth/models/GroupModel.php b/application/modules/auth/models/GroupModel.php index 5e38ef74b542f3cff322c3b4185d4b2196487394..9dbf37017d0087c1a08e5f21ce5320583ba2a8a6 100644 --- a/application/modules/auth/models/GroupModel.php +++ b/application/modules/auth/models/GroupModel.php @@ -6,7 +6,7 @@ class Auth_GroupModel extends Unl_Model { $db = Zend_Registry::get('db'); $select = new Zend_Db_Select($db); - + // get userId as a string or array from the user object(s) if (Unl_Util::isArray($user)) { $userId = array(); @@ -16,7 +16,7 @@ class Auth_GroupModel extends Unl_Model } else { $userId = $user->getId(); } - + // find the group(s) that the user(s) is a "primary" member of $select = new Zend_Db_Select($db); $select->from(array('u' => 'creqUsers'), array('userId')); @@ -26,15 +26,22 @@ class Auth_GroupModel extends Unl_Model } else { $select->where('u.userId = ?', $userId); } - + $records = $select->query()->fetchAll(); - $objects = $objects = new Unl_Model_Collection('Auth_GroupModel'); + $objects = array(); + if (Unl_Util::isArray($user)) { + foreach ($user as $aUser) { + $objects[$aUser->getId()] = new Unl_Model_Collection(__CLASS__); + } + } else { + $objects[$user->getId()] = new Unl_Model_Collection(__CLASS__); + } foreach ($records as $record) { $recordUserId = $record['userId']; unset($record['userId']); $objects[$recordUserId][] = Unl_Model_Registry::getInstance()->getOrAdd(new self($record)); } - + // find any groups that the user(s) is a "non-primary" member of $select = new Zend_Db_Select($db); $select->from(array('u' => 'creqUsers'), array('userId')); @@ -45,14 +52,14 @@ class Auth_GroupModel extends Unl_Model } else { $select->where('u.userId = ?', $userId); } - + $records = $select->query()->fetchAll(); foreach ($records as $record) { $recordUserId = $record['userId']; unset($record['userId']); $objects[$recordUserId][] = Unl_Model_Registry::getInstance()->getOrAdd(new self($record)); } - + // if we were passed an array of users, return an array for each user if (Unl_Util::isArray($userId)) { return $objects; @@ -61,4 +68,9 @@ class Auth_GroupModel extends Unl_Model return $objects[$userId]; } } + + public function getId() + { + return $this->_data['groupId']; + } }