toutpratique/modules/advreassurance/advreassurance.php

134 lines
4.0 KiB
PHP
Raw Normal View History

2016-06-08 17:11:44 +02:00
<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once(dirname(__FILE__) . '/classes/AdvRea.php');
class AdvReassurance extends Module
{
public function __construct()
{
$this->name = 'advreassurance';
$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é');
$this->description = $this->l('Gestion des blocks reassurance');
}
public function install()
{
$sql = array();
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance` (
`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_ . 'advreassurance_lang` (
`id_reassurance` 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_reassurance`,`id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advreassurance_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 = 'AdminAdvReassurance';
$tab->id_parent = Tab::getCurrentParentId();
$tab->module = $this->name;
$languages = Language::getLanguages();
foreach ($languages as $language) {
$tab->name[$language['id_lang']] = 'Reassurance';
}
$img_dir = _PS_IMG_DIR_ . 'reassurance';
$folder = is_dir($img_dir);
if (!$folder)
{
$folder = mkdir($img_dir, 0755, true);
}
return parent::install() && $tab->add() && $this->registerHook('displayReassurance') && $this->registerHook('actionRefreshReassurance') && $folder;
}
public function uninstall()
{
$sql = 'DROP TABLE IF EXISTS
`' . _DB_PREFIX_ . 'advreassurance_lang`,
`' . _DB_PREFIX_ . 'advreassurance_shop`,
`' . _DB_PREFIX_ . 'advreassurance`
';
Db::getInstance()->Execute($sql);
$idTab = Tab::getIdFromClassName('AdminAdvReassurance');
if ($idTab) {
$tab = new Tab($idTab);
$tab->delete();
}
return parent::uninstall();
}
public function assignBlocks()
{
$blocks = AdvRea::getBlocks();
if (!$blocks)
{
return false;
}
$this->smarty->assign('blocks', $blocks);
}
public function hookDisplayReassurance($params)
{
if (!$this->isCached('advreassurance.tpl', $this->getCacheId()))
{
$this->assignBlocks();
}
return $this->display(__FILE__, 'advreassurance.tpl', $this->getCacheId());
}
public function hookDisplayReassuranceBottom($params)
{
if (!$this->isCached('advreassurance-bottom.tpl', $this->getCacheId()))
{
$this->assignBlocks();
}
return $this->display(__FILE__, 'advreassurance-bottom.tpl', $this->getCacheId());
}
public function hookActionRefreshReassurance()
{
$this->_clearCache('advreassurance');
}
}