Exemplo n.º 1
0
 public function ClientesGrupos()
 {
     $nItems = 0;
     $nErrores = 0;
     $dbLink = mysql_connect("localhost", "root", "albatronic");
     $query = "TRUNCATE {$this->dbDestino}.ErpClientesGrupos";
     mysql_query($query);
     $query = "select * from {$this->dbOrigen}.clientes_grupos";
     $result = mysql_query($query, $dbLink);
     while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
         $row = $this->utf($row);
         $c = new ClientesGrupos();
         $c->setIDGrupo($row['IDGrupo']);
         $c->setGrupo($row['Grupo']);
         $c->setPrimaryKeyMD5(md5($row['IDGrupo']));
         if (!$c->create()) {
             $errores[] = $c->getErrores();
             $nErrores++;
         } else {
             $nItems++;
         }
     }
     //mysql_close($dbLink);
     echo "Clientes Grupos  {$nItems}<br/>";
     if (count($errores)) {
         echo "<pre>";
         print_r($errores);
         echo "</pre>";
     }
 }
 /**
  * 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();
                 $this->values['datos'] = $datos;
                 $this->values['errores'] = array();
                 return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values);
                 break;
             case 'POST':
                 //CREAR NUEVO REGISTRO
                 $idPromocion = $this->request[$this->entity][$this->values['linkBy']['id']];
                 //COGER EL LINK A LA ENTIDAD PADRE
                 if ($this->values['linkBy']['id'] != '') {
                     $this->values['linkBy']['value'] = $this->request[$this->entity][$this->values['linkBy']['id']];
                 }
                 $idGrupo = $this->request['PromocionesClientes']['IDGrupo'];
                 if ($idGrupo == -1) {
                     // Todos los grupos. Hay que crear la promocion para todos los grupos
                     $grupo = new ClientesGrupos();
                     $grupos = $grupo->cargaCondicion("IDGrupo", "1", "Grupo ASC");
                     foreach ($grupos as $value) {
                         $promo = new PromocionesClientes();
                         $promo->setIDPromocion($idPromocion);
                         $promo->setIDGrupo($value['IDGrupo']);
                         if ($promo->valida($this->form->getRules())) {
                             $promo->create();
                         }
                     }
                     unset($promo);
                     unset($grupo);
                     return $this->listAction($idPromocion);
                 } else {
                     $datos = new $this->entity();
                     $datos->bind($this->request[$this->entity]);
                     if ($datos->valida($this->form->getRules())) {
                         $datos->create();
                         $this->values['errores'] = $datos->getErrores();
                         $this->values['alertas'] = $datos->getAlertas();
                         //Recargo el objeto para refrescar las propiedas que
                         //hayan podido ser objeto de algun calculo durante el proceso
                         //de guardado.
                         $datos = new $this->entity($datos->getPrimaryKeyValue());
                         $this->values['datos'] = $datos;
                         if ($this->values['errores']) {
                             return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values);
                         } else {
                             return array('template' => $this->entity . '/edit.html.twig', 'values' => $this->values);
                         }
                     } else {
                         $this->values['datos'] = $datos;
                         $this->values['errores'] = $datos->getErrores();
                         $this->values['alertas'] = $datos->getAlertas();
                         return array('template' => $this->entity . '/new.html.twig', 'values' => $this->values);
                     }
                 }
                 break;
         }
     } else {
         return array('template' => '_global/forbiden.html.twig');
     }
 }