137 lines
4.1 KiB
PHP
Raw Normal View History

2017-07-06 17:41:10 +02:00
<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once(dirname(__FILE__) . '/classes/AdvRea3.php');
class AdvReassurance3 extends Module
{
public function __construct()
{
$this->name = 'advreassurance3';
$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('Reassurance avancé 3');
$this->description = $this->l('Gestion des blocks reassurance3');
}
public function install()
{
$sql = array();
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance3` (
`id_reassurance` 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_reassurance`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance3_lang` (
`id_reassurance` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`subtitle` TEXT NOT NULL,
`url` varchar(255),
PRIMARY KEY (`id_reassurance`,`id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance3_shop` (
`id_reassurance` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_reassurance`, `id_shop`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
foreach ($sql as $_sql) {
Db::getInstance()->Execute($_sql);
}
$tab = new Tab();
$tab->class_name = 'AdminAdvReassurance3';
$tab->id_parent = Tab::getCurrentParentId();
$tab->module = $this->name;
$languages = Language::getLanguages();
foreach ($languages as $language) {
$tab->name[$language['id_lang']] = 'Reassurance3';
}
$img_dir = _PS_IMG_DIR_ . 'reassurance3';
$folder = is_dir($img_dir);
if (!$folder)
{
$folder = mkdir($img_dir, 0755, true);
}
return parent::install() && $tab->add() && $this->registerHook('displayReassurance3') && $this->registerHook('actionRefreshReassurance3') && $folder;
}
public function uninstall()
{
$sql = 'DROP TABLE IF EXISTS
`' . _DB_PREFIX_ . 'advreassurance3_lang`,
`' . _DB_PREFIX_ . 'advreassurance3_shop`,
`' . _DB_PREFIX_ . 'advreassurance3`
';
Db::getInstance()->Execute($sql);
$idTab = Tab::getIdFromClassName('AdminAdvReassurance3');
if ($idTab) {
$tab = new Tab($idTab);
$tab->delete();
}
return parent::uninstall();
}
public function assignBlocks()
{
$blocks = AdvRea3::getBlocks();
if (!$blocks) {
return false;
}
$this->smarty->assign('blocks', $blocks);
}
public function hookDisplayReassurance3($params)
{
if (!$this->isCached('advreassurance3.tpl', $this->getCacheId()))
{
$this->assignBlocks();
}
return $this->display(__FILE__, 'advreassurance3.tpl', $this->getCacheId());
}
public function hookHome($params)
{
return $this->hookDisplayReassurance3($params);
}
public function hookDisplayReassurance3Bottom($params)
{
if (!$this->isCached('advreassurance3-bottom.tpl', $this->getCacheId()))
{
$this->assignBlocks();
}
return $this->display(__FILE__, 'advreassurance3-bottom.tpl', $this->getCacheId());
}
public function hookActionRefreshReassurance3()
{
$this->_clearCache('advreassurance3');
}
}