194 lines
6.4 KiB
PHP
194 lines
6.4 KiB
PHP
<?php
|
|
|
|
if (!defined('_CAN_LOAD_FILES_'))
|
|
exit;
|
|
|
|
include_once dirname(__FILE__).'/classes/AdvPictoClass.php';
|
|
|
|
class AdvPicto extends Module
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->name = 'advpicto';
|
|
$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('Gestionnaire de pictos');
|
|
$this->description = $this->l('Gérez vos pictos');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
return parent::install() && $this->registerHook('displayPictogrammesCategory') && $this->registerHook('displayPictogrammesProduct') && $this->createFolder() && $this->installDb() && $this->createTab();
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
|
|
if ( !parent::uninstall() ) {
|
|
return false;
|
|
}
|
|
|
|
$this->uninstallDb();
|
|
$this->deleteTab();
|
|
|
|
return true;
|
|
}
|
|
|
|
public function installDb()
|
|
{
|
|
$sql = [];
|
|
$sql[] =
|
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advpicto` (
|
|
`id_advpicto` int(10) unsigned NOT NULL auto_increment,
|
|
`active` int(11),
|
|
`position` int(11),
|
|
`external` int(10) unsigned NOT NULL,
|
|
`selfcategory_display` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`id_advpicto`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
$sql[] =
|
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advpicto_lang` (
|
|
`id_advpicto` int(10) unsigned NOT NULL,
|
|
`id_lang` int(10) unsigned NOT NULL,
|
|
`title` varchar(255) NOT NULL,
|
|
`alt` varchar(255) NOT NULL,
|
|
`link` varchar(255),
|
|
`content` text,
|
|
PRIMARY KEY (`id_advpicto`,`id_lang`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
$sql[] =
|
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advpicto_shop` (
|
|
`id_advpicto` int(10) unsigned NOT NULL,
|
|
`id_shop` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`id_advpicto`,`id_shop`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
$sql[] =
|
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advpicto_category` (
|
|
`id_advpicto` int(10) unsigned NOT NULL,
|
|
`id_category` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`id_advpicto`,`id_category`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
$sql[] =
|
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advpicto_product` (
|
|
`id_advpicto_product` int(11) NOT NULL AUTO_INCREMENT,
|
|
`id_advpicto` int(10) unsigned NOT NULL,
|
|
`id_product` int(10) unsigned NOT NULL,
|
|
`highlight` int(10) unsigned NOT NULL,
|
|
PRIMARY KEY (`id_advpicto`,`id_product`),
|
|
UNIQUE KEY `id_advpicto_product` (`id_advpicto_product`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
$sql[] =
|
|
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'advpicto_product_shop` (
|
|
`id_advpicto_product` int(11) NOT NULL,
|
|
`id_shop` int(11) NOT NULL,
|
|
PRIMARY KEY (`id_advpicto_product`,`id_shop`)
|
|
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
|
|
|
|
return $this->uninstallDb() && $this->updateDb($sql);
|
|
}
|
|
|
|
public function uninstallDb()
|
|
{
|
|
$sql = array();
|
|
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'advpicto` ;';
|
|
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'advpicto_lang` ;';
|
|
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'advpicto_shop` ;';
|
|
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'advpicto_category` ;';
|
|
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'advpicto_product` ;';
|
|
$sql[] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'advpicto_product_shop` ;';
|
|
|
|
return $this->updateDb($sql);
|
|
}
|
|
|
|
public function updateDb( $sqls )
|
|
{
|
|
foreach ( $sqls as $sql ) {
|
|
if ( !Db::getInstance()->execute($sql) ) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function createFolder()
|
|
{
|
|
$img_dir = _PS_IMG_DIR_ . 'picto';
|
|
$folder = is_dir($img_dir);
|
|
if (!$folder)
|
|
{
|
|
$folder = mkdir($img_dir, 0755, true);
|
|
}
|
|
|
|
return $folder;
|
|
}
|
|
|
|
public function createTab()
|
|
{
|
|
$languages = Language::getLanguages();
|
|
|
|
$new_tab = new Tab();
|
|
$new_tab->class_name = 'AdminAdvPicto';
|
|
$new_tab->id_parent = Tab::getCurrentParentId();
|
|
$new_tab->module = $this->name;
|
|
foreach ( $languages as $language ) {
|
|
$new_tab->name[$language['id_lang']] = 'Pictos';
|
|
}
|
|
$new_tab->add();
|
|
|
|
$under_tab = new Tab();
|
|
$under_tab->class_name = 'AdminAdvPictoProduct';
|
|
$under_tab->id_parent = $new_tab->id;
|
|
$under_tab->module = $this->name;
|
|
foreach ( $languages as $language ) {
|
|
$under_tab->name[$language['id_lang']] = 'Pictos';
|
|
}
|
|
$under_tab->add();
|
|
|
|
return true;
|
|
}
|
|
|
|
public function deleteTab()
|
|
{
|
|
$idTab = Tab::getIdFromClassName('AdminAdvPicto');
|
|
if ( $idTab ) {
|
|
$tab = new Tab($idTab);
|
|
$tab->delete();
|
|
}
|
|
}
|
|
|
|
public function hookDisplayPictogrammesCategory($params)
|
|
{
|
|
$id_product = $params['id_product'];
|
|
$id_category = Tools::getValue('id_category');
|
|
|
|
$tpl = isset($params['special']) ? 'product-list-highlight.tpl' : 'product-list.tpl';
|
|
|
|
$pictos = AdvPictoClass::getPictosForProductList($id_product, $id_category);
|
|
|
|
$this->smarty->assign('pictos', $pictos);
|
|
|
|
return $this->display(__FILE__, $tpl);
|
|
}
|
|
|
|
public function hookDisplayPictogrammesProduct($params)
|
|
{
|
|
$id_product = (int)$params['id_product'];
|
|
$is_listing = isset($params['is_listing'])?$params['is_listing']:'';
|
|
|
|
if($is_listing) {
|
|
$tpl = 'product-list.tpl';
|
|
} else {
|
|
$tpl = 'product.tpl';
|
|
}
|
|
|
|
$pictos = AdvPictoClass::getPictosForProductDetails($id_product);
|
|
$this->smarty->assign('pictos', $pictos);
|
|
return $this->display(__FILE__, $tpl);
|
|
}
|
|
} |