Exemplo n.º 1
0
 public function saveResourceAction()
 {
     //check if the auth user has acces to this modul
     //		if(!Needs_Tools::hasAccess($myUser = Zend_Registry::get('user')->getRoleId(),'setare_drept_rol')){
     //			die('No access!');
     //		}
     $resourceId = $this->getRequest()->getParam('resourceId');
     $roleId = $this->getRequest()->getParam('roleId');
     $actions = $this->getRequest()->getParam('actions');
     $return = 'Error occured';
     //BEGIN:save or delete
     if ($actions == 'add') {
         $modelRR = new Default_Model_ResourceRole();
         $select3 = $modelRR->getMapper()->getDbTable()->select()->where('idResource = ?', $resourceId)->where('idRole = ?', $roleId);
         $modelRR->fetchRow($select3);
         if ($modelRR->getId() == NULL) {
             $model = new Default_Model_ResourceRole();
             $model->setIdResource($resourceId);
             $model->setIdRole($roleId);
             if ($model->save()) {
                 $return = 'Successfully added';
             }
         } else {
             $return = 'Already in database';
         }
     } elseif ($actions == 'remove') {
         $model = new Default_Model_ResourceRole();
         $select3 = $model->getMapper()->getDbTable()->select()->where('idResource = ?', $resourceId)->where('idRole = ?', $roleId);
         $model->fetchRow($select3);
         if ($model->getId() != NULL) {
             if ($model->delete()) {
                 //remove the resource from all child elements
                 $role = new Default_Model_Role();
                 $role->find($roleId);
                 $graph = new Needs_Graph($role, false, array('idParent', 'id'), 'array');
                 $childRoles = $graph->getTree();
                 foreach ($childRoles as $value) {
                     $condition = array('idRole = ?' => $value['id'], 'idResource = ?' => $resourceId);
                     $this->db->delete('resource_role', $condition);
                 }
                 $return = 'Successfully deleted';
             }
         }
     }
     echo Zend_Json_Encoder::encode($return);
     //END:save or delete
 }
Exemplo n.º 2
0
Arquivo: Roles.php Projeto: valizr/MMA
 public static function checkIfSubRole($id, $childId, $allowMe = false)
 {
     if ($allowMe == true && $id == $childId) {
         return true;
     }
     //check if child element
     $role = new Default_Model_Role();
     $role->find($id);
     $graph = new Needs_Graph($role, false, array('parentId', 'id'), 'array');
     if ($graph->ifSubchild($childId)) {
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 public function deleteAction()
 {
     //		//check if the auth user has acces to this modul
     //		if(!Needs_Tools::hasAccess(Zend_Registry::get('user')->getRoleId(),'stergere_rol')){
     //			$this->_redirect('/');
     //		}
     //
     $id = $this->getRequest()->getParam('id');
     //		//check if user can delete this role (if it's his role child role)
     //		if(!Needs_Tools::checkIfSubRole(Zend_Registry::get('user')->getRoleId(),$id)){
     //			$this->_redirect('/');
     //		}
     $model = new Default_Model_Role();
     if ($model->find($id)) {
         //all sub childs goes a level up
         $parentId = $model->getIdParent();
         $graph = new Needs_Graph($model, false, array('idParent', 'id'), 'array', true);
         if ($graph->moveChildren($parentId)) {
             //TODO:fallback if couldn't delete children
         }
         if ($model->delete()) {
             $this->_flashMessenger->addMessage("<div class='success canhide'><p>Rolul a fost sters cu succes.</p><a href='javascript:;'></a></div>");
         } else {
             $this->_flashMessenger->addMessage("<div class='failure canhide'><p>S-a produs o eroare in stergerea rolului. Nu s-a efectuat nici o modificare</p><a href='javascript:;'></a></div>");
         }
     }
     $this->_redirect(WEBROOT . 'role');
 }