Example #1
0
 public function addAction()
 {
     //check if the auth user has acces to this modul
     //		if(!Needs_Tools::hasAccess(Zend_Registry::get('user')->getRoleId(),'adaugare_rol')){
     //			$this->_redirect('/');
     //		}
     $id = $this->getRequest()->getParam('id');
     if ($id == null) {
         //default id is the logged in user id
         $id = Zend_Registry::get('user')->getIdRole();
     }
     //check if user can edit this  (if it's his child)
     $parentModel = new Default_Model_Role();
     if (!$parentModel->find(Zend_Registry::get('user')->getIdRole())) {
         $this->_redirect('/');
     }
     $graph = new Needs_Graph($parentModel, true, array('idParent', 'id'), 'array');
     if (!$graph->ifSubchild($id)) {
         $this->_redirect('/');
     }
     $modelParent = new Default_Model_Role();
     if (!$modelParent->find($id)) {
         $this->_redirect('/role');
     }
     $form = new Default_Form_Role();
     $form->parentName->setValue($modelParent->getName());
     $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/role/adaugare.phtml'))));
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         //BEGIN:Uniqe validation per Tenancy
         if ($this->getRequest()->getParam('tenancyId')) {
             $where = "deleted = '0'";
             $wheres = array('role', 'name', $where);
             $form->nume->addValidator('Db_NoRecordExists', true, $wheres);
         }
         //END:Uniqe validation per Tenancy
         if ($form->isValid($this->getRequest()->getPost())) {
             //save
             $model = new Default_Model_Role();
             $model->setOptions($form->getValues());
             $model->setIdParent($id);
             $model->setIsAdmin(0);
             $idRole = $model->save();
             if ($idRole) {
                 //if is Admin role, give all the resources
                 $this->_flashMessenger->addMessage("<div class='success canhide'><p>Rolul a fost adaugat cu succes.</p><a href='javascript:;'></a></div>");
             } else {
                 $this->_flashMessenger->addMessage("<div class='failure canhide'><p>S-a produs o eroare. Rolul nu a fost adaugat.</p><a href='javascript:;'></a></div>");
             }
             $this->_redirect('/role');
         }
     }
 }
Example #2
0
File: Role.php Project: valizr/MMA
 public function fetchRow($select, Default_Model_Role $model)
 {
     $result = $this->getDbTable()->fetchRow($select);
     if (0 == count($result)) {
         return;
     }
     $model->setOptions($result->toArray());
     return $model;
 }