/** * Crea un registro nuevo * * Siempre viene por POST * 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 'POST': //CREAR NUEVO REGISTRO $entidad = $this->request[$this->entity]['Entity']; $idEntidad = $this->request[$this->entity]['IdEntity']; $tipo = $this->request[$this->entity]['Type']; $variables = new CpanVariables('Mod', 'Env', $entidad); $this->varEnvMod = $variables->getValores(); unset($variables); $this->values['varEnvMod'] = $this->varEnvMod; $datos = new CpanDocs(); $datos->bind($this->request['CpanDocs']); $datos->setArrayDoc($this->request['FILES']['documento']); $rules = $this->getRules($this->request[$this->entity]['Type']); switch ($this->request[$this->entity]['Type']) { case 'galery': if ($datos->valida($rules)) { $documento = $datos->getArrayDoc(); $documento['maxWidth'] = $this->varEnvMod['galery']['maxWidthImage']; $documento['maxHeight'] = $this->varEnvMod['galery']['maxHeightImage']; $documento['modoRecortar'] = $this->request['modoRecortar']; $datos->setArrayDoc($documento); $lastId = $datos->create(); if (!$lastId) { $this->values['errores'] = $datos->getErrores(); } // Subir Miniatura if ($lastId and $this->varEnvMod['galery']['generateThumbnail'] == '1') { $thumb = new CpanDocs(); $thumb->bind($this->request['CpanDocs']); $thumb->setBelongsTo($lastId); $documento = $this->request['FILES']['documento']; $documento['maxWidth'] = $this->varEnvMod['galery']['widthThumbnail']; $documento['maxHeight'] = $this->varEnvMod['galery']['heightThumbnail']; $thumb->setArrayDoc($documento); $thumb->setIsThumbnail(1); if ($thumb->valida($rules)) { $lastId = $thumb->create(); } $this->values['errores'] = $thumb->getErrores(); } } else { $this->values['errores'] = $datos->getErrores(); } break; case 'tiny': if ($datos->valida($rules)) { $documento = $datos->getArrayDoc(); $documento['maxWidth'] = $this->varEnvMod['galery']['maxWidthImage']; $documento['maxHeight'] = $this->varEnvMod['galery']['maxHeightImage']; $documento['modoRecortar'] = $this->request['modoRecortar']; $datos->setArrayDoc($documento); $lastId = $datos->create(); if (!$lastId) { $this->values['errores'] = $datos->getErrores(); } } else { $this->values['errores'] = $datos->getErrores(); } break; case 'document': case 'video': case 'audio': if ($datos->valida($rules)) { $lastId = $datos->create(); if (!$lastId) { $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 CpanDocs($lastId); $this->values['datos'] = $datos; } else { $this->values['datos'] = $datos; $this->values['errores'] = $datos->getErrores(); } break; } return $this->listPopupAction($entidad, $idEntidad, $tipo, $this->request['formato']); break; } } 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); }