public function getAcl() { $profil = $this->getCurrentProfile(); $aclProfileId = $profil ? $profil->id : 'none'; $cm = $this->getBootstrap()->getResource('cachemanager'); $cache = $cm->getCache('rolecache'); $front = Zend_Controller_Front::getInstance(); $pluginAcl = $front->getPlugin('Base_Controller_Plugin_Acl'); $branch_name = is_numeric(ODDZIAL_ID) && ODDZIAL_ID > 0 ? '_' . ODDZIAL_ID : ''; $this->acl = $cache->load('vacl_profile_' . $aclProfileId . $branch_name); if (!$this->acl) { $this->acl = new Base_Acl(); $this->_groups = $all_groups = $grupy = $this->getGroups(); $this->_roles = $all_roles = $role = $this->getRoles($profil); foreach ($grupy as $grupa) { $this->addAclRole($grupa, 'group'); } foreach ($role as $rola) { $this->addAclRole($rola, 'role'); } $uprawnienia = new Logic_Privileges(); $rupModel = new GroupVirtualResource(); $rup = $rupModel->fetchAll()->toArray(); $tmp = $uprawnienia->getResources(array('vresource')); $up = $tmp['vresource']->toArray(); $upArray = array(); /** * Dla każdego zasobu dodajemy do acl'ki resource */ foreach ($up as $u) { $upArray[$u['id']] = $u; $resource = $u['resource_name']; if (!$this->acl->has($resource)) { $this->acl->add(new Zend_Acl_Resource($resource)); } } /** * Dodawanie resource'ów do ról/grup */ foreach ($rup as $r) { $resource = $upArray[$r['id_resource']]['resource_name']; $role = 'group_' . (int) $all_groups[$r['id_group']]['priority'] . "_" . $r['id_group']; $this->acl->allow($role, $resource); } $identity = Zend_Auth::getInstance()->getIdentity(); /** * Budowanie uprawnień dla danego profilu, jeśli istnieje. * Jeśli nie istnieje ustawienie roli na domyślną (ustawioną w configu). */ $data = array(); $data['roles'] = array(); $roles = array(); if (!$identity) { $defaultRole = $this->getDefaultRole(); $data['roles'][] = $defaultRole; } else { $data = $cache->load('user_data_' . $identity->id . '_profile_' . $aclProfileId . $branch_name); if (!$data) { if ($profil->id) { $profil = $profil->toArray(); $profil['parents']['role'] = array(); $profil['parents']['group'] = array(); $profilRola = new ProfileRole(); $ru = $profilRola->fetchAll("id_profile = {$profil['id']}")->toArray(); foreach ($ru as $r) { $roles[] = 'role_' . $r['id_role']; $profil['parents']['role'][] = array('id' => $r['id_role'], 'priority' => (int) $all_roles[$r['id_role']]['priority']); } $profilGrupa = new ProfileGroup(); $gu = $profilGrupa->fetchAll("id_profile = {$profil['id']}")->toArray(); foreach ($gu as $g) { $roles[] = 'group_' . $g['id_group']; $profil['parents']['group'][] = array('id' => $g['id_group'], 'priority' => (int) $all_groups[$g['id_group']]['priority']); } $this->addAclRole($profil, 'profile'); $pluginAcl->setRole(new Zend_Acl_Role('profile_' . $profil['id'])); $identity->profile_id = $profil['id']; } else { $pluginAcl->setRole(new Zend_Acl_Role($defaultRole)); } $data['roles'] = $roles; $data['profil'] = $profil; $cache->save($data, 'user_data_' . $identity->id . '_profile_' . $aclProfileId . $branch_name); } else { // FROM CACHE if ($data['profil']['id']) { $this->addAclRole($data['profil'], 'profile'); $pluginAcl->setRole(new Zend_Acl_Role('profile_' . $data['profil']['id'])); $identity->profile_id = $data['profil']['id']; } else { $pluginAcl->setRole(new Zend_Acl_Role($defaultRole)); } } } $cache->save($this->acl, 'vacl_profile_' . $aclProfileId . $branch_name); } return $this->acl; }
public function showAction() { $request = $this->getRequest(); $id = $request->getParam('id'); $id = $this->_helper->IdConvert->hexToStr($id); $logic = new Logic_Privileges(); $data = array(); try { $data = $logic->showRole($id); } catch (Logic_Komunikat_Exception $e) { $this->_helper->messenger('error', MSG_ERROR, $e); $this->_helper->redirector('index'); return; } $this->view->data = $data; }