/**
  * Edita, actualiza o borrar un registro
  *
  * Viene siempre por POST
  * Actualiza o Borrar según el valor de $this->request['accion']
  *
  * @return array con el template y valores a renderizar
  */
 public function editAction()
 {
     switch ($this->request['accion']) {
         case 'G':
             //GUARDAR DATOS
             if ($this->values['permisos']['permisosModulo']['UP']) {
                 $variables = new CpanVariables('Mod', 'Env', $this->request[$this->entity]['Entity']);
                 $this->varEnvMod = $variables->getValores();
                 unset($variables);
                 $this->values['varEnvMod'] = $this->varEnvMod;
                 $id = $this->request[$this->entity]['Id'];
                 $entidad = $this->request[$this->entity]['Entity'];
                 $idEntidad = $this->request[$this->entity]['IdEntity'];
                 $tipo = $this->request[$this->entity]['Type'];
                 $title = $this->request[$this->entity]['Title'];
                 $slug = $this->request[$this->entity]['Name'];
                 $showCaption = $this->request[$this->entity]['ShowCaption'];
                 $publicar = $this->request[$this->entity]['Publish'];
                 $documento = $this->request['FILES']['documento'];
                 $documento['maxWidth'] = $this->varEnvMod['galery']['maxWidthImage'];
                 $documento['maxHeight'] = $this->varEnvMod['galery']['maxHeightImage'];
                 $documento['modoRecortar'] = $this->request['modoRecortar'];
                 $rules = $this->getRules($this->request[$this->entity]['Type']);
                 // Para que deje actualizar aunque estemos en el límite del
                 // número máximo de documentos
                 if ($rules['numMaxDocs'] > 0) {
                     $rules['numMaxDocs']++;
                 }
                 $doc = new CpanDocs($id);
                 $doc->setTitle($title);
                 $doc->setName($slug);
                 $doc->setShowCaption($showCaption);
                 $doc->setPublish($publicar);
                 if ($documento['name'] != '') {
                     $doc->setArrayDoc($documento);
                 }
                 $doc->setIsThumbnail(0);
                 if ($doc->valida($rules)) {
                     $ok = $doc->actualiza();
                     // Subir Miniatura
                     if ($ok and $this->varEnvMod['galery']['generateThumbnail'] == '1') {
                         $thumbNail = $doc->getThumbNail();
                         $thumbNail->setTitle($title);
                         $thumbNail->setName($slug);
                         $thumbNail->setShowCaption($showCaption);
                         $thumbNail->setPublish($publicar);
                         $thumbNail->setIsThumbnail(1);
                         if ($documento['name'] != '') {
                             $documento['maxWidth'] = $this->varEnvMod['galery']['widthThumbnail'];
                             $documento['maxHeight'] = $this->varEnvMod['galery']['heightThumbnail'];
                             $thumbNail->setArrayDoc($documento);
                         }
                         if ($thumbNail->valida($rules)) {
                             $ok = $thumbNail->actualiza();
                         }
                         unset($thumbNail);
                     }
                 }
                 $this->values['errores'] = $doc->getErrores();
                 $this->values['alertas'] = $doc->getAlertas();
                 unset($doc);
                 return $this->listPopupAction($entidad, $idEntidad, $tipo, $this->request['formato']);
             } else {
                 return array('template' => '_global/forbiden.html.twig');
             }
             break;
         case 'B':
             //BORRAR DATOS
             if ($this->values['permisos']['permisosModulo']['DE']) {
                 $id = $this->request[$this->entity]['Id'];
                 $entidad = $this->request[$this->entity]['Entity'];
                 $idEntidad = $this->request[$this->entity]['IdEntity'];
                 $tipo = $this->request[$this->entity]['Type'];
                 $datos = new CpanDocs($id);
                 if ($datos->erase()) {
                     // Borro los eventuales hijos del documento ( los thumbnails)
                     $thumbNail = new CpanDocs();
                     $rows = $thumbNail->cargaCondicion('Id', "BelongsTo='{$id}'");
                     foreach ($rows as $row) {
                         $thumbNail = new CpanDocs($row['Id']);
                         $thumbNail->erase();
                     }
                     unset($thumbNail);
                     //$this->values['datos'] = $datos;
                     $this->values['errores'] = $datos->getErrores();
                 }
                 unset($datos);
                 return $this->listPopupAction($entidad, $idEntidad, $tipo, $this->request['formato']);
             } else {
                 return array('template' => '_global/forbiden.html.twig');
             }
             break;
     }
 }
示例#2
0
 /**
  * Sube o quita del servidor los documentos (imagenes, etc) asociados
  * a la entidad.
  *
  * @return array
  */
 public function ImagenAction()
 {
     $rules = array('allowTypes' => explode(",", $this->varEnvPro['allowTypes']), 'maxFileSize' => $this->varEnvMod['maxSizes']['image']);
     $idEntidad = $this->request[$this->entity][$this->form->getPrimaryKey()];
     switch ($this->request['accion']) {
         case 'EnviarMaster':
             if ($this->values['permisos']['permisosModulo']['UP']) {
                 $variables = new CpanVariables('Mod', 'Env', $this->entity);
                 $varEnv = $variables->getValores();
                 unset($variables);
                 $datos = new $this->entity($idEntidad);
                 $columnaSlug = $varEnv['fieldGeneratorUrlFriendly'];
                 $slug = $datos->{"get{$columnaSlug}"}();
                 unset($datos);
                 $doc = new CpanDocs();
                 $doc->setArrayDoc($_FILES['imagenMaster']);
                 if ($doc->validaArchivo($rules)) {
                     // Borrar las eventuales imagenes que existieran
                     $img = new CpanDocs();
                     $img->borraDocs($this->entity, $idEntidad, 'image%');
                     unset($img);
                     foreach ($this->varEnvMod['images'] as $key => $value) {
                         if ($value['visible'] == '1') {
                             $_FILES['imagenMaster']['maxWidth'] = $value['width'];
                             $_FILES['imagenMaster']['maxHeight'] = $value['height'];
                             $_FILES['imagenMaster']['modoRecortar'] = $this->request['modoRecortar'];
                             $doc = new CpanDocs();
                             $doc->setEntity($this->entity);
                             $doc->setIdEntity($idEntidad);
                             $doc->setPathName($this->entity . $idEntidad);
                             $doc->setName($slug);
                             $doc->setTitle($slug);
                             $doc->setType('image' . $key);
                             $doc->setArrayDoc($_FILES['imagenMaster']);
                             $doc->setIsThumbnail(0);
                             $doc->setPublish($value['valorDefectoPublicar']);
                             if ($doc->valida($rules)) {
                                 $lastId = $doc->create();
                             }
                             $this->values['errores'] = $doc->getErrores();
                             if (count($doc->getErrores())) {
                                 $doc->borraDocs($this->entity, $idEntidad, 'image%');
                                 $lastId = 0;
                             }
                             // Subir Miniatura
                             if ($lastId and $value['generateThumbnail'] == '1') {
                                 $_FILES['imagenMaster']['maxWidth'] = $value['widthThumbnail'];
                                 $_FILES['imagenMaster']['maxHeight'] = $value['heightThumbnail'];
                                 $doc = new CpanDocs();
                                 $doc->setEntity($this->entity);
                                 $doc->setIdEntity($idEntidad);
                                 $doc->setPathName($this->entity . $idEntidad);
                                 $doc->setName($slug);
                                 $doc->setTitle($slug);
                                 $doc->setType('image' . $key);
                                 $doc->setArrayDoc($_FILES['imagenMaster']);
                                 $doc->setIsThumbnail(1);
                                 $doc->setPublish($value['valorDefectoPublicar']);
                                 $doc->setBelongsTo($lastId);
                                 if ($doc->valida($rules)) {
                                     $ok = $doc->create();
                                 }
                                 if (!$ok) {
                                     $this->values['errores'] = $doc->getErrores();
                                 }
                             }
                         }
                     }
                 } else {
                     $this->values['errores'] = $doc->getErrores();
                 }
                 $template = $this->entity . '/edit.html.twig';
             } else {
                 $template = "_global/forbiden.html.twig";
             }
             break;
         case 'GuardarCambios':
             if ($this->values['permisos']['permisosModulo']['UP']) {
                 $idImagen = $this->request['idImagenEnviar'];
                 $id = $this->request['image'][$idImagen]['Id'];
                 $tipo = $this->request['image'][$idImagen]['Tipo'];
                 $title = trim($this->request['image'][$idImagen]['Title']);
                 $slug = trim($this->request['image'][$idImagen]['Name']);
                 $showCaption = $this->request['image'][$idImagen]['ShowCaption'];
                 $orden = $this->request['image'][$idImagen]['SortOrder'];
                 $publicar = $this->request['image'][$idImagen]['Publish'];
                 $documento = $this->request['FILES'][$tipo];
                 $documento['maxWidth'] = $this->varEnvMod['images'][$idImagen]['width'];
                 $documento['maxHeight'] = $this->varEnvMod['images'][$idImagen]['height'];
                 $documento['modoRecortar'] = $this->request['image'][$idImagen]['modoRecortar'];
                 $doc = new CpanDocs($id);
                 $doc->setTitle($title);
                 $doc->setName($slug);
                 $doc->setShowCaption($showCaption);
                 $doc->setSortOrder($orden);
                 $doc->setPublish($publicar);
                 if ($documento['name'] != '') {
                     $doc->setArrayDoc($documento);
                 }
                 $doc->setIsThumbnail(0);
                 if ($doc->valida($rules)) {
                     $ok = $doc->actualiza();
                     // Subir Miniatura
                     if ($ok and $this->varEnvMod['images'][$idImagen]['generateThumbnail'] == '1') {
                         $thumbNail = $doc->getThumbNail();
                         $thumbNail->setTitle($title);
                         $thumbNail->setName($slug);
                         $thumbNail->setShowCaption($showCaption);
                         $thumbNail->setSortOrder($orden);
                         $thumbNail->setIsThumbnail(1);
                         if ($documento['name'] != '') {
                             $documento['maxWidth'] = $this->varEnvMod['images'][$idImagen]['widthThumbnail'];
                             $documento['maxHeight'] = $this->varEnvMod['images'][$idImagen]['heightThumbnail'];
                             $thumbNail->setArrayDoc($documento);
                         }
                         if ($thumbNail->valida($rules)) {
                             $ok = $thumbNail->actualiza();
                         }
                         unset($thumbNail);
                     }
                 }
                 $template = $this->entity . '/edit.html.twig';
             } else {
                 $template = "_global/forbiden.html.twig";
             }
             break;
         case 'Quitar':
             if ($this->values['permisos']['permisosModulo']['DE']) {
                 $idImagen = $this->request['idImagenEnviar'];
                 $tipo = $this->request['image'][$idImagen]['Tipo'];
                 $img = new CpanDocs();
                 if (!$img->borraDocs($this->entity, $idEntidad, $tipo)) {
                     $this->values['errores'] = $img->getErrores();
                 }
                 unset($img);
                 $template = $this->entity . '/edit.html.twig';
             } else {
                 $template = "_global/forbiden.html.twig";
             }
             break;
     }
     $this->values['datos'] = new $this->entity($idEntidad);
     return array('template' => $template, 'values' => $this->values);
 }