示例#1
0
 /**
  * Aktualizacja roli i jej uprawnień
  *
  * @param Base_Form_Abstract $form formularz z danymi do zapisania
  * @param integer $id id edytowanej roli
  * @return integer liczba zmienionych wierszy
  */
 public function updateRole($form, $id)
 {
     $roleModel = new Role();
     $roleGroupModel = new RoleGroup();
     $dane = $values = $form->getValues();
     $subForms = $form->getSubForms();
     foreach ($subForms as $subForm) {
         unset($dane[get_class($subForm)]);
     }
     $roleModel->getAdapter()->beginTransaction();
     try {
         $tmp = $roleModel->update($dane, 'id = ' . $id);
         $roleGroupModel->delete('id_role = ' . $id);
         foreach ($subForms as $subForm) {
             $groups = $values[get_class($subForm)];
             foreach ($groups['group'] as $group) {
                 $subValues['id_group'] = $group;
                 $subValues['id_role'] = $id;
                 $row = $roleGroupModel->createRow($subValues);
                 $row->save();
             }
         }
         $roleModel->getAdapter()->commit();
         $cm = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('cachemanager');
         $cache = $cm->getCache('rolecache');
         $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     } catch (Exception $e) {
         $roleModel->getAdapter()->rollBack();
         throw $e;
     }
     return $tmp;
 }
示例#2
0
 /**
  * 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;
 }
 /**
  * Exclude object from result
  *
  * @param     RoleGroup $roleGroup Object to remove from the list of results
  *
  * @return    RoleGroupQuery The current query, for fluid interface
  */
 public function prune($roleGroup = null)
 {
     if ($roleGroup) {
         $this->addUsingAlias(RoleGroupPeer::ID, $roleGroup->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
示例#4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      RoleGroup $value A RoleGroup object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(RoleGroup $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
示例#5
0
文件: User.php 项目: knatorski/SMS
 public function deleteRoleGroup($id_role)
 {
     $model = new RoleGroup();
     $data = $model->fetchToDelete($id_role);
     foreach ($data as $roleGroup) {
         $dataRoleGroup = $model->findOne($roleGroup['id']);
         $dataRoleGroup->setFromArray(array("ghost" => "TRUE"));
         $dataRoleGroup->save();
     }
 }