2015-10-12 13:28:17 +02:00

140 lines
7.1 KiB
PHP

<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once(dirname(__FILE__) . '/classes/AdvMenuLink.php');
class AdvMenu extends Module
{
public function __construct()
{
$this->name = 'advmenu';
$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('Menu avancée');
$this->description = $this->l('Gestion des blocs de liens du menu du site');
}
public function install()
{
$sql = array();
$sql[] =
'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(11) UNSIGNED NOT NULL default 0,
PRIMARY KEY (`id_link`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'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';
$sql[] =
'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),
`text` text,
PRIMARY KEY (`id_link`,`id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] = "
INSERT INTO `ps_advmenu` (`id_link`, `id_parent`, `classbloc`, `position`) VALUES (1, '0', '', 0), (2, '0', '', 0), (3, '0', '', 0), (4, '0', '', 0), (5, '0', '', 0), (6, '0', '', 0), (7, '0', '', 0), (8, '0', '', 0), (9, '0', '', 0), (10, '1', 'menu-subtitle', 0), (11, '1', 'menu-subtitle', 0), (12, '1', 'menu-subtitle', 0), (13, '10', '', 0), (14, '0', NULL, 0), (15, '10', NULL, 0), (16, '10', NULL, 0), (17, '10', NULL, 0), (18, '10', NULL, 0), (19, '10', NULL, 0), (20, '10', NULL, 0), (21, '10', NULL, 0), (22, '10', NULL, 0), (23, '10', NULL, 0), (24, '11', NULL, 0), (25, '11', NULL, 0), (26, '11', NULL, 0), (27, '11', NULL, 0), (28, '11', NULL, 0), (29, '11', NULL, 0), (30, '11', NULL, 0), (31, '11', NULL, 0), (32, '11', NULL, 0), (33, '11', NULL, 0), (34, '12', NULL, 0), (35, '12', NULL, 0), (36, '12', NULL, 0), (37, '12', NULL, 0), (38, '12', NULL, 0), (39, '12', NULL, 0), (40, '12', NULL, 0), (41, '12', NULL, 0), (42, '12', NULL, 0), (43, '12', NULL, 0), (44, '1', 'menu-subtitle', 0), (45, '44', NULL, 0), (46, '44', NULL, 0), (47, '44', NULL, 0), (48, '44', NULL, 0), (49, '44', NULL, 0), (50, '44', NULL, 0), (51, '44', NULL, 0), (52, '44', NULL, 0), (53, '44', NULL, 0), (54, '44', NULL, 0);
";
$sql[] = "
INSERT INTO `ps_advmenu_lang` (`id_link`, `id_lang`, `title`, `url`, `text`) VALUES (1, 1, 'Lien 1', '#', ''), (2, 1, 'Lien 2', '#', ''), (3, 1, 'Lien 3', '#', ''), (4, 1, 'Lien 4', '#', ''), (5, 1, 'Lien 5', '#', ''), (6, 1, 'Lien 6', '#', ''), (7, 1, 'Lien 7', '#', ''), (8, 1, 'Lien 8', '#', ''), (9, 1, 'Lien 9', '#', ''), (10, 1, 'Sous categorie 1', '#', ''), (11, 1, 'Sous categorie 2', '#', ''), (12, 1, 'Sous categorie 3', '#', ''), (13, 1, 'Sous lien 1', '#', ''), (14, 1, 'Lien 10', '#', ''), (15, 1, 'Sous lien 2', '#', ''), (16, 1, 'Sous lien 3', '#', ''), (17, 1, 'Sous lien 4', '#', ''), (18, 1, 'Sous lien 5', '#', ''), (19, 1, 'Sous lien 6', '#', ''), (20, 1, 'Sous lien 7', '#', ''), (21, 1, 'Sous lien 8', '#', ''), (22, 1, 'Sous lien 9', '#', ''), (23, 1, 'Sous lien 10', '#', ''), (24, 1, 'Sous lien 1', '#', ''), (25, 1, 'Sous lien 2', '#', ''), (26, 1, 'Sous lien 3', '#', ''), (27, 1, 'Sous lien 4', '#', ''), (28, 1, 'Sous lien 5', '#', ''), (29, 1, 'Sous lien 6', '#', ''), (30, 1, 'Sous lien 7', '#', ''), (31, 1, 'Sous lien 8', '#', ''), (32, 1, 'Sous lien 9', '#', ''), (33, 1, 'Sous lien 10', '#', ''), (34, 1, 'Sous lien 1', '#', ''), (35, 1, 'Sous lien 2', '#', ''), (36, 1, 'Sous lien 3', '#', ''), (37, 1, 'Sous lien 4', '#', ''), (38, 1, 'Sous lien 5', '#', ''), (39, 1, 'Sous lien 6', '#', ''), (40, 1, 'Sous lien 7', '#', ''), (41, 1, 'Sous lien 8', '#', ''), (42, 1, 'Sous lien 9', '#', ''), (43, 1, 'Sous lien 10', '#', ''), (44, 1, 'Sous categorie 4', '#', ''), (45, 1, 'Sous lien 1', '#', ''), (46, 1, 'Sous lien 2', '#', ''), (47, 1, 'Sous lien 3', '#', ''), (48, 1, 'Sous lien 4', '#', ''), (49, 1, 'Sous lien 5', '#', ''), (50, 1, 'Sous lien 6', '#', ''), (51, 1, 'Sous lien 7', '#', ''), (52, 1, 'Sous lien 8', '#', ''), (53, 1, 'Sous lien 9', '#', ''), (54, 1, 'Sous lien 10', '#', '');
";
foreach ($sql as $_sql) {
Db::getInstance()->Execute($_sql);
}
$new_tab = new Tab();
$new_tab->class_name = 'AdminAdvMenu';
$new_tab->id_parent = Tab::getCurrentParentId();
$new_tab->module = $this->name;
$languages = Language::getLanguages();
foreach ($languages as $language) {
$new_tab->name[$language['id_lang']] = 'Menu du site';
}
$new_tab->add();
return parent::install();
}
public function uninstall()
{
$sql = 'DROP TABLE IF EXISTS
`' . _DB_PREFIX_ . 'advmenu_lang`,
`' . _DB_PREFIX_ . 'advmenu_shop`,
`' . _DB_PREFIX_ . 'advmenu`
';
Db::getInstance()->Execute($sql);
$idTab = Tab::getIdFromClassName('AdminAdvMenu');
if ($idTab) {
$tab = new Tab($idTab);
$tab->delete();
}
return parent::uninstall();
}
public function hookDisplayMenu($params)
{
if(Context::getContext()->controller instanceOf IndexController) {
if (!$this->isCached('advmenu.tpl', $this->getCacheId())) {
$menuLinks = AdvMenuLink::getMenu();
if (!$menuLinks) {
return false;
}
$this->smarty->assign('menuLinks', $menuLinks);
}
return $this->display(__FILE__, 'advmenu.tpl', $this->getCacheId());
} else {
// page interne
$this->smarty->assign('url_ajax', _MODULE_DIR_.'advmenu/ajax.php');
return $this->display(__FILE__, 'advmenu_ajax.tpl');
}
}
public function loadMenu()
{
if (!$this->isCached('advmenu.tpl', $this->getCacheId())) {
$menuLinks = AdvMenuLink::getMenu();
if (!$menuLinks) {
return false;
}
$this->smarty->assign('menuLinks', $menuLinks);
}
return $this->display(__FILE__, 'advmenu.tpl', $this->getCacheId());
}
public function hookHeader($params)
{
$this->context->controller->addJS($this->_path.'js/advmenu.js');
}
public function hookActionSaveMenu()
{
$this->_clearCache('advmenu.tpl');
}
}