'seourl', 'primary' => 'id_seourl', 'multilang' => true, 'multilang_shop' => true, 'fields' => array( 'link_rewrite' => array('lang' => true, 'type' => self::TYPE_STRING, 'validate' => 'isString'), 'type' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'id_element' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'redirect' => array('lang' => true, 'type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString'), 'canonical' => array('lang' => true, 'type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isString'), ) ); public function __construct($id = null, $id_lang = null, $id_shop = null) { parent::__construct($id, $id_lang, $id_shop); } /** * Get Url info * * @param striung $url request uri * @param int $id_lang * @param int $id_shop * * @return array */ public static function getUrl($url, $id_lang = 1, $id_shop = 1) { if (!$id_lang) $id_lang = Context::getContext()->language->id; $sql = 'SELECT s.`id_seourl`, s.`type`, s.`id_element`, sl.`redirect`, sl.`canonical` FROM `'._DB_PREFIX_.'seourl` s LEFT JOIN `'._DB_PREFIX_.'seourl_lang` sl ON (s.`id_seourl` = sl.`id_seourl`) LEFT JOIN `'._DB_PREFIX_.'seourl_shop` shop ON (shop.`id_seourl` = s.`id_seourl`) WHERE sl.`link_rewrite` = "' . pSQL($url) .'" AND sl.`id_lang`='.(int)$id_lang .' AND shop.`id_shop`='.(int)$id_shop; if ($results = Db::getInstance()->getRow($sql)){ return $results; }else{ return "notfound"; } } /** * Créer un lien * @param int $id_type Type d'url * @param int $id_element id de l'element * @param array $slugs Tableau des liens par langue */ public static function createUrl($id_type, $id_element, $slugs, $canonical = null) { $url_rewrite = new ManageSeoUrl(); $url_rewrite->type = (int)$id_type; $url_rewrite->id_element = $id_element; $link_rewrite = array(); $canonical_array = array(); foreach (Language::getLanguages() as $language) { $id_lang = (int)$language['id_lang']; $link_rewrite[$id_lang] = $slugs[$id_lang]; $canonical_array[$id_lang] = $canonical; } $url_rewrite->canonical = $canonical_array; $url_rewrite->link_rewrite = $link_rewrite; return $url_rewrite->save(); } /** * Retourne une ManageSeoUrl en fonction de son type et son id_element * * @param int $id_element Id de l'element de retour * @param int $type Constante de la classe pour le type d'url * @param int $id_only Si true, ne retourne que l'id de l'url * @param int $id_lang Id_lang * @param int $id_shop Id shop */ public static function getByType($id_element, $type = self::TYPE_PRODUCT, $id_only = FALSE, $id_lang = NULL, $id_shop = NULL) { if ($id_shop == null) { $id_shop = Context::getContext()->shop->id; } $sql = ' SELECT s.`id_seourl` FROM `'._DB_PREFIX_.'seourl` s LEFT JOIN `'._DB_PREFIX_.'seourl_shop` shop ON(shop.`id_seourl` = s.`id_seourl`) WHERE s.`type` = "'.$type.'" AND s.`id_element` = '.(int)$id_element .' AND shop.`id_shop` = '.(int)$id_shop; if (!$id = Db::getInstance()->getValue($sql)) return false; if ($id_only) return $id; return new ManageSeoUrl((int)$id, $id_lang, $id_shop); } }