public function __construct($request)
 {
     parent::__construct($request);
     $urls = new CpanUrlAmigables();
     $rows = $urls->cargaCondicion("distinct Controller", "1", "Controller ASC");
     $this->values['controllers'] = $rows;
     unset($urls);
 }
 public function __construct($request)
 {
     parent::__construct($request);
     $array = $this->getArrayIdiomas();
     foreach ($array as $idioma) {
         $idiomasDisponibles[$idioma['Id']] = $idioma['Value'];
     }
     $this->values['idiomas'] = $idiomasDisponibles;
     $urls = new CpanUrlAmigables();
     $rows = $urls->cargaCondicion("distinct Controller as Id,Controller as Value", "1", "Controller ASC");
     unset($urls);
     $rows[] = array("Id" => "", "Value" => "** Para todas **");
     $this->values['controllers'] = $rows;
 }
        $search->actualiza($objeto);
        unset($search);
    }
}
unset($objeto);
// Actualiza la columna en el resto de idiomas
if ($_SESSION['idiomas']['actual'] == 0) {
    // Recorro los idiomas adicionales
    foreach ($_SESSION['idiomas']['disponibles'] as $key => $value) {
        if ($key > 0) {
            $_SESSION['idiomas']['actual'] = $key;
            $objeto = new $entidad($idEntidad);
            $objeto->{"set{$columna}"}($v['valor']);
            if ($objeto->save() && ($columna == 'Publish' || $columna == 'Privacy')) {
                // Actualiza la url amigable
                $urlAmigable = CpanUrlAmigables::sincroniza($objeto);
                // Actualiza la tabla de búsquedas
                $variables = new CpanVariables("Mod", "Env", $entidad);
                if ($variables->getNode('searchable')) {
                    $search = new CpanSearch();
                    $search->actualiza($objeto);
                    unset($search);
                }
            }
            unset($objeto);
        }
    }
    $_SESSION['idiomas']['actual'] = 0;
}
$tag = "";
echo $tag;
 /**
  * Devuelve el objeto CpanUrlAmigables asociado
  */
 public function getObjetoUrlAmigable()
 {
     $url = new CpanUrlAmigables();
     $rows = $url->cargaCondicion("Id", "Idioma='{$_SESSION['idiomas']['actual']}' and Entity='{$this->getClassName()}' and IdEntity='{$this->getPrimaryKeyValue()}'");
     unset($url);
     return new CpanUrlAmigables($rows[0]['Id']);
 }
Exemple #5
0
 /**
  * Realiza validaciones lógicas
  *
  * Los errores los pone en $this->_errores[]
  * Las alertas las pone en $this->_alertas[]
  * Este método lo debe implementar la entidad que lo necesite
  */
 protected function validaLogico()
 {
     if ($this->BelongsTo == $this->getPrimaryKeyValue()) {
         $this->BelongsTo = 0;
         $this->_alertas[] = "El objeto no puede pertenecer a el mismo";
     }
     if ($this->getPrimaryKeyValue() != '') {
         // Estoy validando antes de actualizar
         if ($this->IsSuper and $_SESSION['usuarioPortal']['IdPerfil'] != '1') {
             $this->_errores[] = "No se puede modificar, es un valor reservado";
         }
     }
     if (trim($this->UrlTarget) != '') {
         // Desactivar la gestion de url amigable
         $this->LockUrlPrefix = 1;
         $this->UrlPrefix = '';
         $this->LockSlug = 1;
         $this->Slug = '';
         $this->UrlFriendly = '';
         $urlAmigable = new CpanUrlAmigables();
         $urlAmigable->borraUrl($_SESSION['idiomas']['actual'], $this->getClassName(), $this->getPrimaryKeyValue());
         unset($urlAmigable);
     }
     // Asignar el nivel Jerárquico
     $nivelPadre = 0;
     if ($this->BelongsTo != 0) {
         $objetoPadre = new $this($this->BelongsTo);
         $nivelPadre = $objetoPadre->getNivelJerarquico();
         unset($objetoPadre);
     }
     $this->setNivelJerarquico($nivelPadre + 1);
 }
 protected function calculaUrlAmigable($datos)
 {
     $urlPrefix = '';
     $urlAmigable = '';
     $slug = '';
     $columnaSlug = $this->varEnvMod['fieldGeneratorUrlFriendly'];
     // Si hay que generar la url amigable
     if ($columnaSlug) {
         $bloqueoUrlPrefix = $datos->getLockUrlPrefix()->getIDTipo() == '1';
         $datos->setLockUrlPrefix($bloqueoUrlPrefix);
         $bloqueoSlug = $datos->getLockSlug()->getIDTipo() == '1';
         $datos->setLockSlug($bloqueoSlug);
         $perteneceA = $datos->getBelongsTo()->getPrimaryKeyValue();
         // CALCULAR EL PREFIJO DE LA URL -----------------------------------
         //
         // Si está bloqueado el prefijo, se calcula
         if ($bloqueoUrlPrefix) {
             if ($this->varEnvMod['isModuleRoot']) {
                 // Es el módulo padre de la app
                 if ($perteneceA) {
                     $objetoPadre = new $this->entity($perteneceA);
                     if ($objetoPadre->getUrlHeritable()->getIDTipo() == '1') {
                         $urlPrefix = $objetoPadre->getUrlFriendly();
                     } else {
                         $urlPrefix = "/" . $this->varEnvApp['globales']['urlPrefix'];
                     }
                     unset($objetoPadre);
                 } else {
                     $urlPrefix = "/" . $this->varEnvApp['globales']['urlPrefix'];
                 }
             } else {
                 // No es el módulo padre de la app. Miro a ver si
                 // está linkado con otro módulo
                 $linkModule = $this->varWebMod['globales'];
                 if ($linkModule['linkFromColumn'] != '' and $linkModule['linkToEntity'] != '' and $linkModule['linkToColumn'] != '') {
                     // Está linkado con otro módulo. El prefijo será la url amigable
                     // del padre si es heredable
                     $idToLink = $datos->getColumnValue($linkModule['linkFromColumn']);
                     if (is_object($idToLink)) {
                         $idToLink = $idToLink->getPrimaryKeyValue();
                     }
                     $moduloPadre = new $linkModule['linkToEntity']($idToLink);
                     if ($moduloPadre->getUrlHeritable()->getIDTipo() == '1') {
                         $urlPrefix = $moduloPadre->getUrlFriendly();
                     } else {
                         $urlPrefix = "/" . $this->varEnvApp['globales']['urlPrefix'];
                     }
                     unset($moduloPadre);
                 }
             }
         } else {
             // Si no está bloqueado, se toma el indicado por el usuario y se limpia
             $urlPrefix = Textos::limpia($datos->getUrlPrefix());
             if ($urlPrefix) {
                 $urlPrefix = "/" . $urlPrefix;
             }
         }
         // -----------------------------------------------------------------
         // CALCULAR EL SLUG ------------------------------------------------
         //
         // Si está bloquedo el slug, se calcula
         if ($bloqueoSlug) {
             $slug = $datos->{"get{$columnaSlug}"}();
         } else {
             // Si no está bloqueado, se toma el indicado por el usuario
             $slug = $datos->getSlug();
         }
         $slug = Textos::limpia($slug);
         // -----------------------------------------------------------------
         // Construir la url amigable, límito su longitud al valor indicado
         // en la variable de entorno del proyecto
         if ($urlPrefix != '') {
             $urlAmigable = $urlPrefix;
         }
         $urlAmigable .= "/{$slug}";
         $urlAmigable = str_replace("//", "/", $urlAmigable);
         if ($this->varEnvPro['maxLengthUrlsFriendly']) {
             $urlAmigable = substr($urlAmigable, 0, $this->varEnvPro['maxLengthUrlsFriendly']);
         }
         if ($this->varEnvMod['parametros'] != '') {
             $urlAmigable .= "/" . $this->varEnvMod['parametros'];
         }
         $urls = new CpanUrlAmigables();
         $filtro = "Idioma='{$_SESSION['idiomas']['actual']}' and Entity='{$this->entity}' and IdEntity='{$datos->getPrimaryKeyValue()}'";
         $rows = $urls->cargaCondicion("Id", $filtro);
         $idUrl = $rows[0]['Id'];
         if (!$idUrl) {
             if ($_SESSION['idiomas']['actual'] == 0) {
                 // Pongo el controlador, action, template y parametros con las variables de entorno, pero...
                 $urls->setController($this->varEnvMod['controller']);
                 $urls->setAction($this->varEnvMod['action']);
                 $urls->setTemplate($this->varEnvMod['template']);
                 $urls->setParameters($this->varEnvMod['parametros']);
             } else {
                 $filtro = "Idioma='0' and Entity='{$this->entity}' and IdEntity='{$datos->getPrimaryKeyValue()}'";
                 $rows = $urls->cargaCondicion("Controller,Action,Template,Parameters", $filtro);
                 $row = $rows[0];
                 if ($row) {
                     // Si la entidad tiene padre (belongsto), pongo el controller del padre
                     $urls->setController($row['Controller']);
                     $urls->setAction($row['Action']);
                     $urls->setTemplate($row['Template']);
                     $urls->setParameters($row['Parameters']);
                 }
             }
             // Si el objeto es hijo (belongsTo), pongo el del objeto padre
             if ($datos->getBelongsTo()->getPrimaryKeyValue() > 0) {
                 $clasePadre = $datos->getClassName();
                 $urlPadre = new CpanUrlAmigables();
                 $filtro = "Idioma='{$_SESSION['idiomas']['actual']}' and Entity='{$clasePadre}' and IdEntity='{$datos->getBelongsTo()->getPrimaryKeyValue()}'";
                 $rows = $urlPadre->cargaCondicion("Controller,Action,Template,Parameters", $filtro);
                 $row = $rows[0];
                 if ($row) {
                     // Si la entidad tiene padre (belongsto), pongo el controller del padre
                     $urls->setController($row['Controller']);
                     $urls->setAction($row['Action']);
                     $urls->setTemplate($row['Template']);
                     $urls->setParameters($row['Parameters']);
                 }
             }
             $urls->setIdioma($_SESSION['idiomas']['actual']);
             $urls->setUrlFriendly($this->entity . $datos->getPrimaryKeyValue());
             $urls->setEntity($this->entity);
             $urls->setIdEntity($datos->getPrimaryKeyValue());
             $idUrl = $urls->create();
         }
         $rows = $urls->cargaCondicion("Id, Entity, IdEntity", "Idioma='{$_SESSION['idiomas']['actual']}' and UrlFriendly='{$urlAmigable}'");
         $row = $rows[0];
         if ($row['Id'] and ($row['Entity'] != "{$this->entity}" or $row['IdEntity'] != "{$datos->getPrimaryKeyValue()}")) {
             // Ya existe esa url amigable, le pongo al final el id
             $urlAmigable .= "-" . $idUrl;
             $slug .= "-" . $idUrl;
         }
         $urls = new CpanUrlAmigables($idUrl);
         $urls->setUrlFriendly($urlAmigable);
         $urls->setEntity($this->entity);
         $urls->setIdEntity($datos->getPrimaryKeyValue());
         $urls->setPrivacy($datos->getPrivacy()->getIDTipo());
         $urls->setAccessProfileList($datos->getAccessProfileList());
         $urls->setAccessProfileListWeb($datos->getAccessProfileListWeb());
         $urls->save();
     }
     $array = array();
     if ($urlPrefix . $urlAmigable . $slug) {
         $array = array('prefix' => $urlPrefix, 'url' => $urlAmigable, 'slug' => $slug);
     }
     return $array;
 }
 /**
  * Vacia las tablas de familias,fabricantes y articulos
  */
 static function VaciarTablas()
 {
     $tabla = new CpanUrlAmigables();
     $tabla->queryDelete("Controller='Familias' or Controller='Articulos' or Controller='Producto' or Controller='Fabricantes'");
     $tabla = new Familias();
     $tabla->queryDelete("1");
     $tabla = new Fabricantes();
     $tabla->queryDelete("1");
     $tabla = new Articulos();
     $tabla->queryDelete("1");
     $tabla = new CpanRelaciones();
     $tabla->queryDelete("EntidadOrigen='Familias' or EntidadOrigen='Fabricantes' or EntidadOrigen='Articulos'");
     $tabla->queryDelete("EntidadDestino='Familias' or EntidadDestino='Fabricantes' or EntidadDestino='Articulos'");
     unset($tabla);
 }
 /**
  * Borrar el registro de urlamigables correspondiente al $idioma, $entidad y $idEntidad
  *
  * @param int $idioma
  * @param string $entidad
  * @param integer $idEntidad
  * @return boolean TRUE si el borrado se hizo con éxito
  */
 public function borraUrl($idioma, $entidad, $idEntidad)
 {
     $row = $this->cargaCondicion("Id", "Idioma='{$idioma}' and Entity='{$entidad}' and IdEntity='{$idEntidad}'");
     $url = new CpanUrlAmigables($row[0]['Id']);
     $ok = $url->erase();
     unset($url);
     return $ok;
 }