159 lines
4.9 KiB
PHP
159 lines
4.9 KiB
PHP
<?php
|
|
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
exit;
|
|
|
|
require_once dirname(__FILE__).'/classes/AdvMenuLink.php';
|
|
|
|
class AdvMenu extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'advmenu';
|
|
$this->tab = 'front_office_features';
|
|
$this->version = '2.0';
|
|
$this->author = 'Antadis';
|
|
$this->need_instance = 0;
|
|
|
|
$this->bootstrap = true;
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Menu avancé');
|
|
$this->description = $this->l('Gestion des blocs de liens du menu du site');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
if (!parent::install()
|
|
|| !$this->installDb()
|
|
|| !$this->installTab()
|
|
|| !$this->registerHook('displayMenu')
|
|
|| !$this->registerHook('actionSaveMenu')
|
|
) {
|
|
$this->uninstall();
|
|
return false;
|
|
}
|
|
|
|
AdvMenuLink::refreshPositionsAll();
|
|
return true;
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
if (!parent::uninstall()
|
|
|| !$this->uninstallTab()
|
|
|| !$this->uninstallDb()
|
|
|| !$this->unregisterHook('displayMenu')
|
|
|| !$this->unregisterHook('actionSaveMenu')
|
|
) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function installDb()
|
|
{
|
|
$return = true;
|
|
$sqlQueries = array();
|
|
$sqlQueries[] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'advmenu` (
|
|
`id_link` INT(10) UNSIGNED NOT NULL auto_increment,
|
|
`id_parent` VARCHAR(255) NOT NULL,
|
|
`classbloc` VARCHAR(255),
|
|
`position` INT(10) UNSIGNED NOT NULL DEFAULT 0,
|
|
`external` TINYINT(1) NOT NULL DEFAULT 0,
|
|
`tree_categories` TINYINT(1) NOT NULL DEFAULT 0,
|
|
PRIMARY KEY (`id_link`)
|
|
) ENGINE='._MYSQL_ENGINE_.'DEFAULT CHARSET=utf8';
|
|
$sqlQueries[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advmenu_shop` (
|
|
`id_link` INT(10) UNSIGNED NOT NULL auto_increment,
|
|
`id_shop` INT(10) UNSIGNED NOT NULL,
|
|
PRIMARY KEY (`id_link`, `id_shop`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
$sqlQueries[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advmenu_lang` (
|
|
`id_link` INT(10) UNSIGNED NOT NULL,
|
|
`id_lang` INT(10) UNSIGNED NOT NULL,
|
|
`title` VARCHAR(255) NOT NULL,
|
|
`url` VARCHAR(255),
|
|
`cta` text,
|
|
PRIMARY KEY (`id_link`,`id_lang`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
|
|
|
|
foreach ($sqlQueries as $sql) {
|
|
$return = Db::getInstance()->Execute($sql);
|
|
}
|
|
|
|
return $return;
|
|
}
|
|
|
|
public function uninstallDb()
|
|
{
|
|
return Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'advmenu`, `'._DB_PREFIX_.'advmenu_lang`, `'._DB_PREFIX_.'advmenu_shop`');
|
|
}
|
|
|
|
public function installTab()
|
|
{
|
|
$langs = Language::getLanguages();
|
|
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
|
|
$tab_i18n = array(
|
|
'fr' => array('Menu du site'),
|
|
'en' => array('Website menu')
|
|
);
|
|
$tab = new Tab();
|
|
$tab->class_name = 'AdminAdvMenu';
|
|
$tab->module = $this->name;
|
|
$tab->id_parent = Tab::getCurrentParentId();
|
|
$tab->position = 10;
|
|
foreach($langs as $lang){
|
|
if(isset($tab_i18n[$lang['iso_code']])) {
|
|
$tab->name[$lang['id_lang']] = $tab_i18n[$lang['iso_code']][0];
|
|
} else {
|
|
$tab->name[$lang['id_lang']] = $tab_i18n['en'][0];
|
|
}
|
|
}
|
|
|
|
return $tab->save();
|
|
}
|
|
|
|
public function uninstallTab()
|
|
{
|
|
if ($id_tab = Tab::getIdFromClassName('AdminAdvMenu')) {
|
|
$tab = new Tab((int)$id_tab);
|
|
return $tab->delete();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/*
|
|
* Display top menu
|
|
*/
|
|
public function hookDisplayMenu($params)
|
|
{
|
|
if (!$this->isCached('advmenu.tpl', $this->getCacheId())) {
|
|
$menuLinks = AdvMenuLink::getMenu();
|
|
if (!$menuLinks) {
|
|
return false;
|
|
}
|
|
unset($menuLinks[0]);
|
|
$this->smarty->assign('menuLinks', $menuLinks);
|
|
}
|
|
return $this->display(__FILE__, 'advmenu.tpl', $this->getCacheId());
|
|
}
|
|
|
|
public function hookDisplayMenu2($params)
|
|
{
|
|
if (!$this->isCached('advmenu2.tpl', $this->getCacheId())) {
|
|
$menuLinks = AdvMenuLink::getMenu();
|
|
if (!$menuLinks) {
|
|
return false;
|
|
}
|
|
$this->smarty->assign('menuLinks', $menuLinks);
|
|
}
|
|
return $this->display(__FILE__, 'advmenu2.tpl', $this->getCacheId());
|
|
}
|
|
|
|
public function hookActionSaveMenu()
|
|
{
|
|
$this->_clearCache('advmenu.tpl');
|
|
}
|
|
} |