toutpratique/modules/advmanufacturer/advmanufacturer.php
2016-06-08 17:36:29 +02:00

136 lines
4.1 KiB
PHP

<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once(dirname(__FILE__) . '/classes/AdvManu.php');
class AdvManufacturer extends Module
{
public function __construct()
{
$this->name = 'advmanufacturer';
$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 des marques avancé');
$this->description = $this->l('Gestion du slider des marques');
}
public function install()
{
$sql = array();
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advmanufacturer` (
`id_advmanu` int(10) unsigned NOT NULL auto_increment,
`position` INT(11) unsigned NOT NULL default 0,
`active` INT(11) unsigned NOT NULL default 1,
`id_brand` INT(11) unsigned,
`link` INT(11) unsigned,
PRIMARY KEY (`id_advmanu`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advmanufacturer_lang` (
`id_advmanu` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`subtitle` varchar(255) NOT NULL,
`url` varchar(255),
PRIMARY KEY (`id_advmanu`,`id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advmanufacturer_shop` (
`id_advmanu` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_advmanu`, `id_shop`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
foreach ($sql as $_sql) {
Db::getInstance()->Execute($_sql);
}
$tab = new Tab();
$tab->class_name = 'AdminAdvManufacturer';
$tab->id_parent = Tab::getCurrentParentId();
$tab->module = $this->name;
$languages = Language::getLanguages();
foreach ($languages as $language) {
$tab->name[$language['id_lang']] = 'Slider de marques';
}
$img_dir = _PS_IMG_DIR_ . 'manufacturer';
$folder = is_dir($img_dir);
if (!$folder)
{
$folder = mkdir($img_dir, 0755, true);
}
return parent::install() && $tab->add() && $this->registerHook('displayManufacturers') && $this->registerHook('displayHeader') && $this->registerHook('actionRefreshManufacturer') && $folder;
}
public function uninstall()
{
$sql = 'DROP TABLE IF EXISTS
`' . _DB_PREFIX_ . 'advmanufacturer_lang`,
`' . _DB_PREFIX_ . 'advmanufacturer_shop`,
`' . _DB_PREFIX_ . 'advmanufacturer`
';
Db::getInstance()->Execute($sql);
$idTab = Tab::getIdFromClassName('AdminAdvManufacturer');
if ($idTab) {
$tab = new Tab($idTab);
$tab->delete();
}
return parent::uninstall();
}
public function hookDisplayManufacturers($params)
{
if (!$this->isCached('advmanufacturer.tpl', $this->getCacheId()))
{
$brands = AdvManu::getSlides();
if (!$brands)
{
return false;
}
$this->smarty->assign('brands', $brands);
}
return $this->display(__FILE__, 'advmanufacturer.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('advmanufacturer');
}
}