name = 'advslider2'; $this->tab = 'front_office_features'; $this->version = '1.0'; $this->author = 'Antadis'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Slider avancé home 2'); $this->description = $this->l('Gestion du slider'); } public function install() { $sql = array(); $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advslider2` ( `id_slide` int(10) unsigned NOT NULL auto_increment, `position` INT(11) UNSIGNED NOT NULL default 0, `active` INT(11) UNSIGNED NOT NULL default 1, PRIMARY KEY (`id_slide`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8'; $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advslider2_lang` ( `id_slide` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `title` varchar(255) NOT NULL, `subtitle` varchar(255) NOT NULL, `label` varchar(255) NOT NULL, `url` varchar(255), `description` TEXT, PRIMARY KEY (`id_slide`,`id_lang`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8'; $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advslider2_shop` ( `id_slide` int(10) unsigned NOT NULL auto_increment, `id_shop` int(10) unsigned NOT NULL, PRIMARY KEY (`id_slide`, `id_shop`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8'; foreach ($sql as $_sql) { Db::getInstance()->Execute($_sql); } $tab = new Tab(); $tab->class_name = 'AdminAdvSlider2'; $tab->id_parent = Tab::getCurrentParentId(); $tab->module = $this->name; $languages = Language::getLanguages(); foreach ($languages as $language) { $tab->name[$language['id_lang']] = 'Slider2'; } $img_dir = _PS_IMG_DIR_ . 'slider2'; $folder = is_dir($img_dir); if (!$folder) { $folder = mkdir($img_dir, 0755, true); } return parent::install() && $tab->add() && $this->registerHook('displaySlider2') && $this->registerHook('displayHeader') && $this->registerHook('actionRefreshSlider') && $folder; } public function uninstall() { $sql = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'advslider2_lang`, `' . _DB_PREFIX_ . 'advslider2_shop`, `' . _DB_PREFIX_ . 'advslider2` '; Db::getInstance()->Execute($sql); $idTab = Tab::getIdFromClassName('AdminAdvSlider2'); if ($idTab) { $tab = new Tab($idTab); $tab->delete(); } return parent::uninstall(); } public function hookDisplaySlider2($params) { if (!$this->isCached('advslider2.tpl', $this->getCacheId())) { $slides = AdvSlide2::getSlides(); if (!$slides) { return false; } $this->smarty->assign('slides2', $slides); } return $this->display(__FILE__, 'advslider2.tpl', $this->getCacheId()); } public function hookHeader($params) { $jsFiles = $this->context->controller->js_files; foreach($jsFiles as $jsFile) { if(strpos($jsFile, 'flexslider') !== false) { return false; } } $this->context->controller->addJS($this->_path.'js/flexslider.js'); } public function hookActionRefreshSlider() { $this->_clearCache('advslider2'); } }