2015-10-28 17:48:50 +01:00

117 lines
4.0 KiB
PHP

<?php
if (!defined('_CAN_LOAD_FILES_'))
exit;
include_once dirname(__FILE__).'/classes/CmsPsPost.php';
include_once dirname(__FILE__).'/classes/CmsPsEdito.php';
include_once dirname(__FILE__).'/classes/CmsPsCategory.php';
include_once dirname(__FILE__).'/../cms_extrafields/classes/CmsPsExtraFieldsValue.php';
class CmsPS extends Module
{
public function __construct()
{
$this->name = 'cmsps';
$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('CMS component by Antadis');
$this->description = $this->l('Manage CMS data in Prestashop');
$this->secure_key = Tools::encrypt($this->name);
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
if (!parent::install()
|| !$this->registerHook('displayRelatedProduct')
|| !$this->registerHook('displayProductCategory')
|| !$this->registerHook('footer')
|| !$this->createTables()
)
return false;
}
public function createTables (){
return true;
}
public function hookdisplayFooter() {
$this->context->controller->addJS(($this->_path).'voting.js', 'all');
if($this->context->controller->php_self == 'categorycms' && $this->context->controller->categorycms->id_category == 1){
$this->context->controller->addJqueryUI('ui.autocomplete', $theme = 'toutpratique', $check_dependencies = true);
$allTags = CmsPsExtraFieldsValue::getAll(false,true,false,Context::getContext()->language->id);
$tags = array();
foreach ($allTags as $key => $value) {
$tags[] = array(
'value' => $value->value,
'id' => $value->id_cmsps_extrafields_value,
);
}
$allSupports = CmsPsExtraFieldsValue::getAll(false,false,true,Context::getContext()->language->id);
$supports = array();
foreach ($allSupports as $key => $value) {
$supports[] = array(
'value' => $value->value,
'id' => $value->id_cmsps_extrafields_value,
);
}
global $smarty;
$smarty->assign(array(
'tags' => $tags,
'supports' => $supports
));
}
}
public function hookdisplayRelatedProduct($params) {
$id_product = $params['product']->id;
$relations = CmsPsPost::getPostRelationWithProduct($id_product, 3, Context::getContext()->language->id);
if ($relations) {
$this->smarty->assign(array(
'relations' => $relations,
));
return $this->display(__FILE__, 'product_relationscms.tpl');
}
}
public function hookdisplayProductCategory($params)
{
if (isset(Context::getContext()->controller->categorycms)) {
$categorycms = Context::getContext()->controller->categorycms;
$products = $categorycms->loadProductForCategoryDisplay();
if (!empty($products)) {
$this->smarty->assign(array(
'products' => $products,
));
return $this->display(__FILE__, 'category_products.tpl');
}
}
}
public function hookdisplayHomeVideo($params) {
$context = Context::getContext();
$video_article = CmsPsPost::getVideoPost($context->language->id, 1);
if ($video_article) {
$this->smarty->assign(array(
'video_article' => $video_article,
));
return $this->display(__FILE__, 'video_article.tpl');
}
}
}