/** * Returns a new RolmoduloQuery object. * * @param string $modelAlias The alias of a model in the query * @param RolmoduloQuery|Criteria $criteria Optional Criteria to build the query from * * @return RolmoduloQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof RolmoduloQuery) { return $criteria; } $query = new RolmoduloQuery(null, null, $modelAlias); if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
public function loginAction() { //Verficamos si existe ya una session activa if (!SessionManager::sessionExist()) { $this->layout('layout/layout_auth'); //Almacenamos la ruta redirect //$reditect_url = $this->params()->fromRoute('redirect_url') && $this->params()->fromRoute('redirect_url')!='/login ' ? $this->params()->fromRoute('redirect_url') : '/'; $message = null; //Instanciamos nuestro loginForm $loginForm = new LoginForm(); $request = $this->getRequest(); if ($request->isPost()) { //Instanciamos nuestro filtro $loginFilter = new LoginFilter(); $loginForm->setInputFilter($loginFilter->getInputFilter()); $loginForm->setData($request->getPost()); if ($loginForm->isValid()) { $empleadoQuery = new EmpleadoQuery(); //Si los datos del formulario son correctos ahora hacemos la busqueda a la db $credentialIsValid = $empleadoQuery->filterByEmpleadoNombreusuario($loginForm->get('empleado_nombreusuario')->getValue())->filterByEmpleadoPassword(md5($loginForm->get('empleado_password')->getValue()))->exists(); if ($credentialIsValid) { //Creamos la sesion //Obtenemos el objeto empleado $empleado = $empleadoQuery->findOneByEmpleadoNombreusuario($loginForm->get('empleado_nombreusuario')->getValue()); //El rol $empleado_rol = $empleado->getRol()->getRolNombre(); //El Acl $empleado_aclCollection = \RolmoduloQuery::create()->filterByIdrol($empleado->getIdRol())->find(); $empleado_acl = array(); foreach ($empleado_aclCollection as $modulo) { $moduloNombre = \ModuloQuery::create()->findOneByIdmodulo($modulo->getIdModulo())->getModuloNombre(); array_push($empleado_acl, $moduloNombre); } $empleadoArray = $empleado->toArray(\BasePeer::TYPE_FIELDNAME); //Removemos idrol y password ya que son datos que no necesitamos en la session unset($empleadoArray['idrol']); unset($empleadoArray['empleado_password']); $empleado_session = array('empleado_info' => $empleadoArray, 'empleado_rol' => $empleado_rol, 'empleado_acl' => $empleado_acl); SessionManager::init($empleado_session); return $this->redirect()->toUrl('/'); } else { $message = "Nombre de usuario y/o contraseña incorrecta"; } } } return new ViewModel(array('form' => $loginForm, 'message' => $message)); } else { return $this->redirect()->toUrl('/'); } }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(RolmoduloPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = RolmoduloQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this Rol is new, it will return * an empty collection; or if this Rol has previously * been saved, it will retrieve related Rolmodulos from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in Rol. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelObjectCollection|Rolmodulo[] List of Rolmodulo objects */ public function getRolmodulosJoinModulo($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = RolmoduloQuery::create(null, $criteria); $query->joinWith('Modulo', $join_behavior); return $this->getRolmodulos($query, $con); }
public function editarAction() { //Cachamos el valor desde nuestro params $id = (int) $this->params()->fromRoute('id'); //Verificamos que el Id articulo que se quiere modificar exista if (!\RolQuery::create()->filterByIdrol($id)->exists()) { $id = 0; } //Si es incorrecto redireccionavos al action nuevo if (!$id) { return $this->redirect()->toRoute('empleados-roles', array('action' => 'nuevo')); } $request = $this->getRequest(); $rol = \RolQuery::create()->findPk($id); //Modulos disponibles $modulosCollection = \ModuloQuery::create()->find(); $all_modulos = array(); foreach ($modulosCollection as $modulo) { $all_modulos[$modulo->getIdmodulo()] = $modulo->getModuloNombre(); } $modulos = $rol->getRolmodulos()->toArray(); $form = new \Empleados\Form\RolForm(); //Le ponemos los datos de nuestro articulo a nuestro formulario $form->setData($rol->toArray(\BasePeer::TYPE_FIELDNAME)); if ($request->isPost()) { //Si hicieron POST $post_data = $request->getPost(); $filter = new \Empleados\Filter\RolFilter(); $form->setInputFilter($filter->getInputFilter()); //Le ponemos los datos a nuestro formulario $form->setData($request->getPost()); //Validamos nuestro formulario de articulo if ($form->isValid()) { //Recorremos nuestro formulario y seteamos los valores a nuestro objeto Articulo foreach ($form->getData() as $key => $value) { $rol->setByName($key, $value, \BasePeer::TYPE_FIELDNAME); } $rol->save(); //Los modulos los eliminamos foreach ($modulos as $modulo) { $rolmodulo = \RolmoduloQuery::create()->findPk($modulo['Idrolmodulo']); $rolmodulo->delete(); } if (isset($post_data["modulos"])) { foreach ($post_data["modulos"] as $idmodulo) { $rolmodulo = new \Rolmodulo(); $rolmodulo->setIdrol($rol->getIdrol()); $rolmodulo->setIdmodulo($idmodulo); $rolmodulo->save(); } } //Agregamos un mensaje $this->flashMessenger()->addMessage('Rol modifcado exitosamente!'); //Redireccionamos a nuestro list $this->redirect()->toRoute('empleados-roles'); } } return new ViewModel(array('id' => $id, 'form' => $form, 'modulos' => json_encode($modulos), 'all_modulos' => $all_modulos)); }