'ant_marketing_landingpage', 'multilang' => true, 'primary' => 'id_landingpage', 'fields' => array( 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isString'), 'meta_title' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'lang' => true), 'meta_description' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'lang' => true), 'url' => array('type' => self::TYPE_STRING, 'validate' => 'isLinkRewrite', 'lang' => true), 'content' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'lang' => true), 'content_type' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'content_return' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'lang' => true), 'cfg' => array('type' => self::TYPE_STRING, 'validate' => 'isString'), 'subscribe' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'active' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'id_sponsor_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate') ) ); public function __construct($id = null, $id_lang = null, $id_shop = null) { parent::__construct($id, $id_lang, $id_shop); $this->image_dir = _PS_IMG_DIR_.'landingpage/'; } public static function getPositionArray() { $array = array(); foreach(self::$content_types as $type) { $array[] = array('id' => $type, 'name' => self::getContentTypeName($type) ); } return $array; } public static function getContentTypeName($content_type) { switch($content_type) { case self::CONTENT_TYPE_TOP: return 'Haut'; break; case self::CONTENT_TYPE_BOTTOM: return 'Bas'; break; case self::CONTENT_TYPE_LEFT: return 'Gauche'; break; case self::CONTENT_TYPE_RIGHT: return 'Droite'; break; } } public static function getImgDir($root = true) { if($root === true) return _PS_IMG_DIR_.'landingpage/'; else return _PS_IMG_.'landingpage/'; } public static function getLogoLinkStatic($id, $type, $root = true) { return self::getImgDir($root).$id.'-'.$type.'.jpg'; } public function getImgLink($type, $root = true) { return self::getLogoLinkStatic($this->id, $type, $root); } public function haveImg($type) { return file_exists($this->getImgLink($type)); } public function haveLogo() { return file_exists($this->getImgLink('logo')); } public function deleteImage($force_delete = false, $type = null) { if (!$this->id) return false; if ($force_delete || !$this->hasMultishopEntries()) { /* Deleting object images and thumbnails (cache) */ if($this->haveImg($type) && !unlink($this->getImgLink($type))) return false; } return true; } public static function findByUrl($url) { $collection = new Collection('AntLandingPage', Context::getContext()->language->id); $collection->where(Collection::LANG_ALIAS.'.url', '=', $url); if(count($collection) > 0) return $collection->getFirst(); return false; } public function getLink($id_shop = null, $id_lang = null) { if($id_shop === null) $shop = Context::getContext()->shop; else $shop = new Shop($id_shop); if($id_lang === null) $id_lang = Context::getContext()->language->id; return $shop->getBaseUrl().$this->url[$id_lang]; } public function addSubscribe($nb = 1) { $this->subscribe = $this->subscribe + 1; $this->save(); } public static function getAllUrl($id_lang = null) { if($id_lang === null) $id_lang = Context::getContext()->language->id; return Db::getInstance()->executeS('SELECT url FROM '._DB_PREFIX_.self::$definition['table'].' a LEFT JOIN '._DB_PREFIX_.self::$definition['table'].'_lang b ON a.id_landingpage = b.id_landingpage AND b.id_lang = '.(int)$id_lang.''); } public function displayTag(){ $sql = 'SELECT `displaytag` FROM `'._DB_PREFIX_.'ant_marketing_landingpage_extra` WHERE `id_landingpage` = ' . (int)$this->id; return Db::getInstance()->getValue($sql); } public function setTag($tag){ return Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'ant_marketing_landingpage_extra` (id_landingpage, displaytag) VALUES(' . (int)$this->id . ', ' . ($tag ? 1 : 0) . ') ON DUPLICATE KEY UPDATE displaytag = ' . ($tag ? 1 : 0)); } }