Exemplo n.º 1
0
 /**
  * Asigno permiso al usuario-proyecto-app
  * 
  * Y además creo el usuario en el cpanel del proyecto.
  * 
  * @return boolean
  */
 public function create()
 {
     $id = parent::create();
     if ($id) {
         // Para saber el perfil que tiene el usuario con la empresa.
         $usuario = new PcaeUsuarios($this->IdUsuario);
         $perfil = $usuario->getPerfilEmpresa($this->IdEmpresa);
         $idPerfil = $perfil->getId();
         unset($usuario);
         unset($perfil);
         $proyectoApp = new PcaeProyectosApps();
         $filtro = "IdProyecto='{$this->IdProyecto}' AND IdApp='{$this->IdApp}'";
         $rows = $proyectoApp->cargaCondicion("*", $filtro);
         unset($proyectoApp);
         $row = $rows[0];
         if ($row['Id']) {
             $connection = array('dbEngine' => $row['DbEngine'], 'host' => $row['Host'], 'user' => $row['User'], 'password' => $row['Password'], 'dataBase' => $row['Database']);
             $em = new EntityManager($connection);
             if ($em->getDbLink()) {
                 $query = "select Id from {$connection['dataBase']}.CpanUsuarios where IdUsuario='{$this->IdUsuario}'";
                 $em->query($query);
                 $rows = $em->fetchResult();
                 $id = $rows[0]['Id'];
                 if ($id) {
                     $query = "update {$connection['dataBase']}.CpanUsuarios set IdPerfil='{$idPerfil}' where Id='{$id}'";
                     $em->query($query);
                 } else {
                     $query = "insert into {$connection['dataBase']}.CpanUsuarios (IdUsuario,IdPerfil,IdRol,IdTipoUsuario) values ('{$this->IdUsuario}','{$idPerfil}','1','1');";
                     $em->query($query);
                     $lastId = $em->getInsertId();
                     $query = "update {$connection['dataBase']}.CpanUsuarios set SortOrder='{$lastId}', PrimaryKeyMD5='" . md5($lastId) . "' WHERE Id='{$lastId}'";
                     $em->query($query);
                 }
                 $em->desConecta();
             }
             unset($em);
         }
     }
     return $id;
 }
Exemplo n.º 2
0
 /**
  * Crea un registro nuevo
  *
  * Si viene por GET muestra un template vacio
  * Si viene por POST crea un registro
  *
  * @return array con el template y valores a renderizar
  */
 public function newAction()
 {
     if ($this->values['permisos']['permisosModulo']['IN']) {
         switch ($this->request["METHOD"]) {
             case 'GET':
                 //MOSTRAR FORMULARIO VACIO
                 //SI EN LA POSICION 2 DEL REQUEST VIENE ALGO,
                 //SE ENTIENDE QUE ES EL VALOR DE LA CLAVE PARA LINKAR CON LA ENTIDAD PADRE
                 //ESTO SE UTILIZA PARA LOS FORMULARIOS PADRE->HIJO
                 if ($this->request['2'] != '') {
                     $this->values['linkBy']['value'] = $this->request['2'];
                 }
                 $datos = new $this->entity();
                 $datos->setDefaultValues((array) $this->varEnvMod['columns']);
                 $this->values['datos'] = $datos;
                 $this->values['errores'] = array();
                 $template = $this->entity . '/new.html.twig';
                 break;
             case 'POST':
                 //CREAR NUEVO REGISTRO
                 //COGER EL LINK A LA ENTIDAD PADRE
                 if ($this->values['linkBy']['id'] != '') {
                     $this->values['linkBy']['value'] = $this->request[$this->entity][$this->values['linkBy']['id']];
                 }
                 $datos = new $this->entity();
                 $datos->bind($this->request[$this->entity]);
                 $rules = $this->form->getRules();
                 $rules['GLOBALES']['numMaxPages'] = $this->varEnvPro['numMaxPages'];
                 $rules['GLOBALES']['numMaxRecords'] = $this->varEnvMod['numMaxRecords'];
                 if ($datos->valida($rules)) {
                     $em = new EntityManager($datos->getConectionName());
                     if ($em->getDbLink()) {
                         $v = $this->request[$this->entity];
                         $columnas = "`IDAgente`,`IDRol`,`IDPerfil`,`IDSucursal`,`IDAlmacen`,`Activo`,`PrimaryKeyMD5`";
                         $valores = "'{$v['IDAgente']}','{$v['IDRol']}','{$v['IDPerfil']}','{$v['IDSucursal']}','{$v['IDAlmacen']}','{$v['Activo']}','" . md5($v['IDAgente']) . "'";
                         $query = "insert into {$datos->getDataBaseName()}.{$datos->getTableName()} ({$columnas}) VALUES ({$valores})";
                         $em->query($query);
                         $lastId = $em->getInsertId();
                         $em->desConecta();
                     }
                     $lastId = $this->request[$this->entity]['IDAgente'];
                     $this->values['errores'] = $datos->getErrores();
                     $this->values['alertas'] = $datos->getAlertas();
                     //Recargo el objeto para refrescar las propiedades que
                     //hayan podido ser objeto de algun calculo durante el proceso
                     //de guardado y pongo valores por defecto (urlamigable, etc)
                     if ($lastId and $datos->getUrlTarget() == '') {
                         $datos = new $this->entity($lastId);
                         $this->gestionUrlMeta($datos);
                         $this->values['errores'] = $datos->getErrores();
                         $this->values['alertas'] = $datos->getAlertas();
                     }
                     // Si ex buscable, actualizar la tabla de búsquedas
                     if ($lastId and $this->varEnvMod['searchable'] == '1') {
                         $this->ActualizaBusquedas($datos);
                     }
                     $this->values['datos'] = $datos;
                     $template = $this->values['errores'] ? $this->entity . '/edit.html.twig' : $this->entity . '/edit.html.twig';
                 } else {
                     $this->values['datos'] = $datos;
                     $this->values['errores'] = $datos->getErrores();
                     $this->values['alertas'] = $datos->getAlertas();
                     $template = $this->entity . '/new.html.twig';
                 }
                 break;
         }
     } else {
         $template = '_global/forbiden.html.twig';
     }
     return array('template' => $template, 'values' => $this->values);
 }