public function cambiarOrdenAction() { $nuevoOrden = explode(",", $this->request['nuevoOrden']); $objeto = $this->request['CpanDocs']; // Recorro los elementos que vienen en el acordeon, y los reordeno $orden = 0; $doc = new CpanDocs(); $em = new EntityManager($doc->getConectionName()); if ($em->getDbLink()) { foreach ($nuevoOrden as $idDoc) { $query = "update {$doc->getDataBaseName()}.{$doc->getTableName()} set SortOrder='{$orden}' where Id='{$idDoc}'"; $em->query($query); $orden += 1; } $em->desConecta(); } unset($em); unset($doc); return $this->listPopupAction($objeto['Entity'], $objeto['IdEntity'], $objeto['Type']); }
/** * Devuelve el objeto que es ThumbNail perteneciente * al objeto actual */ public function getThumbNail() { $obj = new CpanDocs(); $rows = $obj->cargaCondicion('Id', "BelongsTo='{$this->Id}'"); unset($obj); return new CpanDocs($rows[0]['Id']); }
/** * Devuelve el número de documentos asociados a la entidad * * @param string $tipo El tipo de documento, se admite '%' * @param string $criterio Expresión lógica a incluir en el criterio de filtro * @return integer El número de documentos */ public function getNumberOfDocuments($tipo = 'image%', $criterio = '1') { $docs = new CpanDocs(); $nDocs = $docs->getNumberOfDocs($this->getClassName(), $this->getPrimaryKeyValue(), $tipo, $criterio); unset($docs); return $nDocs; }
/** * 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); }