Example #1
0
 public function nuevoAction()
 {
     $form = new \Empleados\Form\RolForm();
     //Modulos disponibles
     $modulosCollection = \ModuloQuery::create()->find();
     $modulos = array();
     foreach ($modulosCollection as $modulo) {
         $modulos[$modulo->getIdmodulo()] = $modulo->getModuloNombre();
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         //Si hicieron POST
         $post_data = $request->getPost();
         //filtro
         $filer = new \Empleados\Filter\RolFilter();
         $form->setInputFilter($filer->getInputFilter());
         //Le ponemos los datos a nuestro formulario
         $form->setData($request->getPost());
         //Validamos nuestro formulario de articulo
         if ($form->isValid()) {
             $rol = new \Rol();
             //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();
             if (!$rol->isPrimaryKeyNull()) {
                 //Ya se guardo y por lo tanto tiene un pk
                 //Si asignaron modulos
                 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 guardado exitosamente!');
                 //Redireccionamos a nuestro list
                 $this->redirect()->toRoute('empleados-roles');
             }
         }
     }
     return new ViewModel(array('form' => $form, 'modulos' => $modulos));
 }
Example #2
0
 /**
  * Exclude object from result
  *
  * @param   Rol $rol Object to remove from the list of results
  *
  * @return RolQuery The current query, for fluid interface
  */
 public function prune($rol = null)
 {
     if ($rol) {
         $this->addUsingAlias(RolPeer::IDROL, $rol->getIdrol(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #3
0
 /**
  * Filter the query by a related Rol object
  *
  * @param   Rol|PropelObjectCollection $rol The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 EmpleadoQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterByRol($rol, $comparison = null)
 {
     if ($rol instanceof Rol) {
         return $this->addUsingAlias(EmpleadoPeer::IDROL, $rol->getIdrol(), $comparison);
     } elseif ($rol instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(EmpleadoPeer::IDROL, $rol->toKeyValue('PrimaryKey', 'Idrol'), $comparison);
     } else {
         throw new PropelException('filterByRol() only accepts arguments of type Rol or PropelCollection');
     }
 }
Example #4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param Rol $obj A Rol object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getIdrol();
         }
         // if key === null
         RolPeer::$instances[$key] = $obj;
     }
 }
Example #5
0
 /**
  * Declares an association between this object and a Rol object.
  *
  * @param                  Rol $v
  * @return Rolmodulo The current object (for fluent API support)
  * @throws PropelException
  */
 public function setRol(Rol $v = null)
 {
     if ($v === null) {
         $this->setIdrol(NULL);
     } else {
         $this->setIdrol($v->getIdrol());
     }
     $this->aRol = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Rol object, it will not be re-added.
     if ($v !== null) {
         $v->addRolmodulo($this);
     }
     return $this;
 }