public function listPopupAction($entidad = '', $idEntidad = '', $tipo = '', $formato = '') { if ($this->values['permisos']['permisosModulo']['CO']) { if ($entidad == '') { $entidad = $this->request[2]; } if ($idEntidad == '') { $idEntidad = $this->request[3]; } if ($tipo == '') { $tipo = $this->request[4]; } if ($formato == '') { $formato = $this->request[5]; } // Leer las variables de entorno del módulo en curso $variables = new CpanVariables('Mod', 'Env', $entidad); $this->varEnvMod = $variables->getValores(); unset($variables); $this->values['varEnvMod'] = $this->varEnvMod; // Añadir un documento nuevo vacio $objetoNuevo = new CpanDocs(); $objetoNuevo->setEntity($entidad); $objetoNuevo->setIdEntity($idEntidad); $objetoNuevo->setType($tipo); $lineas[] = $objetoNuevo; unset($objetoNuevo); $lis = new CpanDocs(); foreach ($lis->getDocs($entidad, $idEntidad, $tipo, "IsThumbnail='0'") as $doc) { array_push($lineas, $doc); } unset($lis); // Tamaño máximo del archivo switch ($tipo) { case 'galery': case 'tiny': $maxFileSize = $this->varEnvMod['maxSizes']['image']; break; case 'document': case 'video': case 'audio': $maxFileSize = $this->varEnvMod['maxSizes'][$tipo]; break; } $this->values['maxFileSize'] = $maxFileSize; $this->values['listado']['data'] = $lineas; $this->values['formato'] = $formato; $template = "CpanDocs/form{$formato}.html.twig"; return array('template' => $template, 'values' => $this->values); } else { return array('template' => '_global/forbiden.html.twig'); } }
/** * 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); }