public function __construct($options = null) { $rolaModel = new Role(); $grupaModel = new Group(); $this->roles = $rolaModel->fetchAll(array('ghost = false', 'is_system = false'))->toArray(); $this->groups = $grupaModel->fetchAll(array('ghost = false', 'is_system = false'), 'group_name asc')->toArray(); parent::__construct($options); }
/** * Pobranie wszystkich grup z dziedziczeniem * * @return array */ public function getGroups() { $groupModel = new Group(); $groupParentsModel = new GroupGroup(); $groups = $groupModel->fetchAll("ghost = false ", 'priority asc')->toArray(); $groupParents = $groupParentsModel->fetchAll()->toArray(); $groupsArray = array(); foreach ($groups as $group) { $group['parents']['role'] = array(); $groupsArray[$group['id']] = $group; } foreach ($groupParents as $parent) { if (isset($groupsArray[$parent['id_group']])) { $groupsArray[$parent['id_group']]['parents']['group'][] = $parent['id_parent']; } } return $groupsArray; }
/** * Pobranie wszystkich ról z dziedziczeniem oraz z przypisanymi groupmi * uprawnień, przyczym jeśli profil jest obecny, zwraca tylko role dla * profilu. Wykorzystywane przy inicjowaniu rów w resource ACL (co poprawia * działanie $acl->hasRole('role'). * * @param $profiel mixed null | Row_Profile * @return array * */ public function getRoles($profile = null) { $roleModel = new Role(); $groupModel = new Group(); $roleParentsModel = new RoleRole(); $roleGroupsModel = new RoleGroup(); $db = Zend_Db_Table::getDefaultAdapter(); $cm = $this->getBootstrap()->getResource('cachemanager'); $cache = $cm->getCache('rolecache'); if ($profile && $profile->id) { $cache_id = 'getRoleProfileWithID' . $profile->id; if (!($found = $cache->load($cache_id))) { $sql = $db->quoteInto('WITH RECURSIVE Roles (id, priority, child_id) AS ( SELECT id, priority, null::bigint as child_id FROM "role" WHERE id IN (select r.id from profile_role pr left join "role" r on r.id = pr.id_role where pr.id_profile = ?) UNION ALL SELECT r.id, r.priority, p.id as child_id FROM "role" r INNER JOIN role_role as rr ON r.id = rr.id_parent INNER JOIN Roles p ON rr.id_role = p.id ) SELECT * FROM Roles ORDER BY priority;', $profile->id); $found = $db->fetchAll($sql); $cache->save($found, $cache_id); } } else { $cache_id = 'getRoleProfileNoID'; if (!($found = $cache->load($cache_id))) { $sql = 'WITH RECURSIVE Roles (id, priority, child_id) AS ( SELECT id, priority, null::bigint as child_id FROM "role" UNION ALL SELECT r.id, r.priority, p.id as child_id FROM "role" r INNER JOIN role_role as rr ON r.id = rr.id_role INNER JOIN Roles p ON rr.id_parent = p.id ) SELECT * FROM Roles ORDER BY priority;'; $found = $db->fetchAll($sql); $cache->save($found, $cache_id); } // $roles = $roleModel->fetchAll("ghost = false ", 'priority asc')->toArray(); } $roles = $found; $cache_id = 'roleGroupsCache'; if (!($roleGroups = $cache->load($cache_id))) { $roleGroups = $roleGroupsModel->fetchAll()->toArray(); $cache->save($roleGroups, $cache_id); } $cache_id = 'roleParentsCache'; if (!($roleParents = $cache->load($cache_id))) { $roleParents = $roleParentsModel->fetchAll()->toArray(); $cache->save($roleParents, $cache_id); } $cache_id = 'groupsArrayCache'; if (!($groupsArray = $cache->load($cache_id))) { $groupsArray = $groupModel->fetchAll()->toArray(); $cache->save($groupsArray, $cache_id); } $groups = array(); foreach ($groupsArray as $groupFromArray) { $groupFromArray['priority'] = (int) $groupFromArray['priority']; $groups[$groupFromArray['id']] = $groupFromArray; } $rolesArray = array(); foreach ($roles as $role) { $role['parents']['group'] = array(); $role['parents']['role'] = array(); $rolesArray[$role['id']] = $role; } foreach ($roleParents as $parent) { if (isset($rolesArray[$parent['id_role']])) { $rolesArray[$parent['id_role']]['parents']['role'][$parent['id_parent']] = array('id' => $parent['id_parent'], 'priority' => $rolesArray[$parent['id_parent']]['priority']); } } foreach ($roleGroups as $group) { if (isset($rolesArray[$group['id_role']])) { $rolesArray[$group['id_role']]['parents']['group'][$group['id_group']] = array('id' => $group['id_group'], 'priority' => $groups[$group['id_group']]['priority']); } } return $rolesArray; }
public function getDataToUserReport() { $profileModel = new Profile(); $select = $profileModel->select()->order('id_user'); $profileDataArray = $profileModel->fetchAll($select)->toArray(); $groupModel = new Group(); $select = $groupModel->select(); $groupDataArray = $groupModel->fetchAll($select)->toArray(); foreach ($groupDataArray as $key => $value) { $tmp[$value['id']] = $value; } $groupDataArray = $tmp; unset($tmp); $branchModel = new Branch(); $select = $branchModel->select(); $branchDataArray = $branchModel->fetchAll($select)->toArray(); foreach ($branchDataArray as $key => $value) { $tmp[$value['id']] = $value; } $branchDataArray = $tmp; unset($tmp); $userModel = new User(); $select = $userModel->select(); $userDataArray = $userModel->fetchAll($select)->toArray(); foreach ($userDataArray as $key => $value) { $tmp[$value['id']] = $value; } $userDataArray = $tmp; unset($tmp); $roleModel = new Role(); $select = $roleModel->select(); $roleDataArray = $roleModel->fetchAll($select)->toArray(); foreach ($roleDataArray as $key => $value) { $tmp[$value['id']] = $value; } $roleDataArray = $tmp; unset($tmp); $groupArray = array(); foreach ($profileDataArray as $key => $value) { $data = $this->getAuthorizationsForProfile($value['id']); foreach ($data as $key2 => $values) { foreach ($values as $key3 => $privs) { /* if ($privs['ghost'] === true) { unset($data[$key2][$key3]); continue; } */ $tmp = array('login' => '', 'surname' => '', 'first_name' => '', 'group' => '', 'role' => '', 'branch' => '', 'ghost' => ''); if ($key2 === 'group') { $tmp['group'] = $groupDataArray[$privs['id_group']]['group_name']; } if ($key2 === 'role') { $tmp['role'] = $roleDataArray[$privs['id_role']]['description']; } $tmp['login'] = $userDataArray[$value['id_user']]['login']; $tmp['surname'] = $userDataArray[$value['id_user']]['surname']; $tmp['first_name'] = $userDataArray[$value['id_user']]['first_name']; $tmp['branch'] = $branchDataArray[$value['id_branch']]['branch_name']; $tmp['ghost'] = $userDataArray['ghost'] ? 'NIEAKTYWNY' : 'AKTYWNY'; $groupArray[] = $tmp; } } } return $groupArray; }
public function __construct($options = null) { $grupaModel = new Group(); $this->groups = $grupaModel->fetchAll(array('ghost = false', 'is_system = false'), array('id_group_parent ASC', 'group_name ASC', 'priority ASC'))->toArray(); parent::__construct($options); }