/** * Creates a new acceso */ public function createAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "acceso", "action" => "index")); } $acceso = new Acceso(); $acceso->setRolId($this->request->getPost("rol_id")); $acceso->setPaginaId($this->request->getPost("pagina_id")); if (!$acceso->save()) { foreach ($acceso->getMessages() as $message) { $this->flash->error($message); } return $this->dispatcher->forward(array("controller" => "acceso", "action" => "new")); } $this->flash->success("acceso was created successfully"); return $this->dispatcher->forward(array("controller" => "acceso", "action" => "index")); }
/** * Creates a new acceso */ public function createAction() { if (!$this->request->isPost()) { return $this->dispatcher->forward(array("controller" => "acceso", "action" => "index")); } $acceso = new Acceso(); $usuario = $this->request->getPost("idusuario"); $usuario = Usuario::findFirstBydpi($usuario); $acceso->idusuario = $usuario->idusuario; $acceso->time = $this->request->getPost("time"); $log = Acceso::findByidusuario($acceso->idusuario); $ultimo = count($log); $tipo = $log[$ultimo - 1]->tipo == 0 ? 1 : 0; $acceso->tipo = $tipo; if (!$acceso->save()) { foreach ($acceso->getMessages() as $message) { $this->flash->error('<div class="alert alert-danger" role="alert"> El Usuario no existe </div>'); } return $this->dispatcher->forward(array("controller" => "acceso", "action" => "new")); } $msg_tipo = $tipo == 0 ? '<div class="alert alert-success" role="alert">Se Registro una Salida</div>' : '<div class="alert alert-info" role="alert">Se Registro un Entrada</div>'; $this->flash->success($msg_tipo); return $this->dispatcher->forward(array("controller" => "acceso", "action" => "new")); }