'ads_publication', 'primary' => 'id_publication', 'multilang' => true, 'fields' => array( 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'content' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isAnything'), 'date_from' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), 'date_to' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); public function getInfos($page_name = null) { if(!Validate::isLoadedObject($this)) $this->pages_infos = array(); if($this->pages_infos === null) { $array_tmp = array(); $sql = 'SELECT * FROM '._DB_PREFIX_.'ads_publication_other WHERE id_publication = '.(int)$this->id.''; $infos = Db::getInstance()->executeS($sql); foreach($infos as $info) { $array_tmp[$info['page_name']][] = $info['id_free']; } $this->pages_infos = $array_tmp; } if(empty($page_name)) return $this->pages_infos; if(isset($this->pages_infos[$page_name])) return $this->pages_infos[$page_name]; return array(); } public function getInfosWithValues($page_name) { $infos = $this->getInfos($page_name); if(count($infos) == 0) return array(); $id_lang = Context::getContext()->language->id; if($page_name == 'postcms') { $sql = ' SELECT c.id_post as id, lc.title as content FROM `'._DB_PREFIX_.'cmsps_posts` c LEFT JOIN `'._DB_PREFIX_.'cmsps_posts_lang` lc ON c.`id_post` = lc.`id_post` AND lc.id_lang = '.$id_lang.' WHERE c.id_post IN ('.implode(',', $infos).')'; } elseif($page_name == 'postedito') { $sql = ' SELECT c.id_edito as id, lc.title as content FROM `'._DB_PREFIX_.'cmsps_editos` c LEFT JOIN `'._DB_PREFIX_.'cmsps_editos_lang` lc ON c.`id_edito` = lc.`id_edito` AND lc.id_lang = '.$id_lang.' WHERE c.id_edito IN ('.implode(',', $infos).') GROUP BY c.id_edito'; } elseif($page_name == 'categorycms') { $sql = ' SELECT c.id_category as id, lc.title as content FROM `'._DB_PREFIX_.'cmsps_categories` c LEFT JOIN `'._DB_PREFIX_.'cmsps_categories_lang` lc ON c.`id_category` = lc.`id_category` AND lc.id_lang = '.$id_lang.' LEFT JOIN `'._DB_PREFIX_.'cmsps_categories_shop` ls ON c.`id_category` = ls.`id_category` WHERE c.`id_category IN ('.implode(',', $infos).') GROUP BY c.id_category'; } $res = Db::getInstance()->executeS($sql); return $res; } public function getSelectedPages() { if(!Validate::isLoadedObject($this)) $this->pages = array(); if($this->pages === null) { $sql = 'SELECT page_name FROM '._DB_PREFIX_.'ads_publication_page WHERE id_publication = '.(int)$this->id; $pages = Db::getInstance()->executeS($sql); $pages = array_map(function($line){ return $line['page_name']; }, $pages); $this->pages = $pages; } return $this->pages; } public function setPages($pages = array()) { $this->pages = $pages; if(Validate::isLoadedObject($this)) { Db::getInstance()->execute(' DELETE FROM '._DB_PREFIX_.'ads_publication_page WHERE id_publication = '.$this->id); $req = array(); foreach($pages as $page_name) $req[] = array( 'id_publication' => $this->id, 'page_name' => $page_name ); Db::getInstance()->insert('ads_publication_page', $req); } } public function setPageInfo($page_name, $infos) { $this->pages_infos[$page_name] = $infos; if(Validate::isLoadedObject($this)) { Db::getInstance()->execute(' DELETE FROM '._DB_PREFIX_.'ads_publication_other WHERE id_publication = '.$this->id.' AND page_name = "'.pSQL($page_name).'"'); $req = array(); foreach($infos as $info) $req[] = array( 'id_publication' => $this->id, 'page_name' => $page_name, 'id_free' => $info ); Db::getInstance()->insert('ads_publication_other', $req); } } public static function getAllPages() { return array( 'index', 'postcms', //Article 'categorycms', //Category d'article 'postedito', //Article mise en forme différent ); } public static function getPageNameTranslated($page_name) { $array = array( 'index' => 'Page d\'accueil', 'postcms' => 'Article', //Article 'categorycms' => 'Catégorie d\'article', //Category d'article 'postedito' => 'Edito', //Article mise en forme différent ); return isset($array[$page_name]) ? $array[$page_name] : $page_name; } public static function getPageNeedInfos() { return array( 'postcms', 'categorycms', 'postedito' ); } }