privilegedemarque/modules/belvg_blockconstructor/belvg_blockconstructor.php
Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

160 lines
5.2 KiB
PHP

<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER *
* *************************************** */
/* Do not edit or add to this file if you wish to upgrade Prestashop to newer
* versions in the future.
* ****************************************************
* @category Belvg
* @package belvg_blockconstructor
* @author Dzianis Yurevich (dzianis.yurevich@gmail.com)
* @copyright Copyright (c) 2010 - 2012 BelVG LLC. (http://www.belvg.com)
* @license http://store.belvg.com/BelVG-LICENSE-COMMUNITY.txt
*/
if (!defined('_PS_VERSION_')) {
exit;
}
include_once(_PS_MODULE_DIR_ . 'belvg_blockconstructor/classes/BelvgBlockConstructor.php');
class belvg_blockconstructor extends Module
{
public function __construct()
{
$this->name = 'belvg_blockconstructor';
$this->tab = 'front_office_features';
$this->version = '1.6.1';
$this->author = 'BelVG';
$this->need_instance = 0;
$this->module_key = 'ab9287f3944d7128cc80e8e194fef8dd';
parent::__construct();
$this->displayName = $this->l('Blocks Constructor (PS 1.6)');
$this->description = $this->l('Blocks Constructor (PS 1.6)');
}
public function install()
{
$sql = array();
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'belvg_blockconstructor` (
`id_belvg_blockconstructor` int(10) unsigned NOT NULL auto_increment,
`status` int(10) NOT NULL default "1",
`id_hook` int(10) NOT NULL,
`id_category` int(10) NOT NULL,
`nb_column` int(10) NOT NULL,
`position` int(10) NOT NULL,
`date_from` date NOT NULL,
`date_to` date NOT NULL,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_belvg_blockconstructor`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'belvg_blockconstructor_shop` (
`id_belvg_blockconstructor` int(10) unsigned NOT NULL auto_increment,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_belvg_blockconstructor`, `id_shop`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
$sql[] =
'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'belvg_blockconstructor_lang` (
`id_belvg_blockconstructor` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`subtitle` varchar(255),
`classbloc` varchar(255),
`link` varchar(255),
`content` text,
PRIMARY KEY (`id_belvg_blockconstructor`,`id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';
foreach ($sql as $_sql) {
Db::getInstance()->Execute($_sql);
}
$new_tab = new Tab();
$new_tab->class_name = 'AdminBlockConstructor';
$new_tab->id_parent = Tab::getCurrentParentId();
$new_tab->module = $this->name;
$languages = Language::getLanguages();
foreach ($languages as $language) {
$new_tab->name[$language['id_lang']] = 'Belvg Blocks Constructor';
}
$new_tab->add();
$install = parent::install();
$_hooks = Hook::getHooks(1);
$this->registerHook('displayHome');
$this->registerHook('displayProductAfter');
return $install;
}
public function uninstall()
{
$sql = array();
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'belvg_blockconstructor`';
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'belvg_blockconstructor_shop`';
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'belvg_blockconstructor_lang`';
foreach ($sql as $_sql) {
Db::getInstance()->Execute($_sql);
}
$idTab = Tab::getIdFromClassName('AdminBlockConstructor');
if ($idTab) {
$tab = new Tab($idTab);
$tab->delete();
}
$uninstall = parent::uninstall();
$_hooks = Hook::getHooks(1);
foreach ($_hooks as $hook) {
$this->unregisterHook($hook['name']);
}
return $uninstall;
}
public function __call($name, $args = array())
{
$hookName = str_replace('hook', '', $name);
$id_hook = (int)Hook::getIdByName($hookName);
if ($id_hook) {
$this->smarty->assign(
array(
'blocks' => BelvgBlockConstructor::getBlocksContent($id_hook),
'linkimg' =>'modules/belvg_blockconstructor/img/',
'position' => $args[0]['position'],
)
);
return $this->display(__FILE__, $hookName.'.tpl');
}
return NULL;
}
}