Пример #1
0
 public function save(Rol $rol)
 {
     $data = array('name' => $rol->getName(), 'description' => $rol->getDescription());
     $id = (int) $rol->getId();
     $params = array();
     $params['table'] = $this->tableGateway->getTableName();
     $params['operation'] = 1;
     $params['data'] = json_encode($data);
     if ($id == 0) {
         $this->tableGateway->insert($data);
         $id = $this->tableGateway->getLastInsertValue();
         if ($id) {
             $params['id'] = $id;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             return $id;
         } else {
             return false;
         }
     } else {
         if ($this->get($id)) {
             $params['id'] = $id;
             $params['operation'] = 2;
             $this->featureSet->getEventManager()->trigger("log.save", $this, $params);
             $this->tableGateway->update($data, array('id' => $id));
             return $id;
         } else {
             return false;
         }
     }
 }
Пример #2
0
 public function addAction()
 {
     $this->getAuthenticateValidate();
     $form = new RolForm();
     $resources = $this->config['resources'];
     $request = $this->getRequest();
     if ($request->isPost()) {
         $rol = new Rol();
         $form->setInputFilter($rol->getInputFilter());
         $resources = $request->getPost('resources');
         $form->setData($request->getPost());
         if ($form->isValid() && count($resources)) {
             $rol->exchangeArray($form->getData());
             $rolId = $this->getRolTable()->save($rol);
             $this->getModuleRolTable()->save($rolId, $resources);
             return $this->redirect()->toRoute('security/rol');
         } else {
             $form->get("resources")->setMessages(array('resources' => "para crear un rol debe asignar permisos"));
         }
     }
     return array('form' => $form, 'resources' => $resources, 'config' => $this->config);
 }