[-] FO : added smarty cache to blockcms

This commit is contained in:
Damien Metzger
2013-06-28 16:20:04 +02:00
parent 8acf308639
commit a387ff5e2f
4 changed files with 74 additions and 50 deletions
+1
View File
@@ -38,6 +38,7 @@ class BlockCMSModel extends ObjectModel
const LEFT_COLUMN = 0;
const RIGHT_COLUMN = 1;
const FOOTER = 2;
/**
* @see ObjectModel::$definition
+63 -49
View File
@@ -39,7 +39,7 @@ class BlockCms extends Module
{
$this->name = 'blockcms';
$this->tab = 'front_office_features';
$this->version = '1.1.1';
$this->version = '1.2';
$this->author = 'PrestaShop';
$this->need_instance = 0;
@@ -52,14 +52,23 @@ class BlockCms extends Module
public function install()
{
if (!parent::install() ||
!$this->registerHooks() ||
!BlockCMSModel::createTables() ||
!Configuration::updateValue('FOOTER_CMS', '') ||
!Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) ||
!Configuration::updateValue('FOOTER_POWEREDBY', 1))
if (!parent::install()
|| !$this->registerHook('leftColumn')
|| !$this->registerHook('rightColumn')
|| !$this->registerHook('header')
|| !$this->registerHook('footer')
|| !$this->registerHook('actionObjectCmsUpdateAfter')
|| !$this->registerHook('actionObjectCmsDeleteAfter')
|| !$this->registerHook('actionShopDataDuplication')
|| !BlockCMSModel::createTables()
|| !Configuration::updateValue('FOOTER_CMS', '')
|| !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1)
|| !Configuration::updateValue('FOOTER_POWEREDBY', 1)
)
return false;
$this->_clearCache('blockcms.tpl');
// Install fixtures for blockcms
$default = Db::getInstance()->insert('cms_block', array(
'id_cms_category' => 1,
@@ -101,23 +110,16 @@ class BlockCms extends Module
public function uninstall()
{
$this->_clearCache('blockcms.tpl');
if (!parent::uninstall() ||
!BlockCMSModel::DropTables() ||
!Configuration::deleteByName('FOOTER_CMS') ||
!Configuration::deleteByName('FOOTER_BLOCK_ACTIVATION') ||
!Configuration::deleteByName('FOOTER_POWEREDBY'))
return false;
return true;
}
private function registerHooks()
{
return (
$this->registerHook('leftColumn') && $this->registerHook('rightColumn') &&
$this->registerHook('header') && $this->registerHook('footer') && $this->registerHook('actionShopDataDuplication'));
}
public function initToolbar()
{
$current_index = AdminController::$currentIndex;
@@ -541,6 +543,8 @@ class BlockCms extends Module
if ($this->_postValidation() == false)
return false;
$this->_clearCache('blockcms.tpl');
$this->_errors = array();
if (Tools::isSubmit('submitBlockCMS'))
{
@@ -661,42 +665,33 @@ class BlockCms extends Module
public function displayBlockCMS($column)
{
$cms_titles = BlockCMSModel::getCMSTitles($column);
if (!$this->isCached('blockcms.tpl', $this->getCacheId($column)))
{
$cms_titles = BlockCMSModel::getCMSTitles($column);
$this->smarty->assign(array(
'block' => 1,
'cms_titles' => $cms_titles,
'contact_url' => (_PS_VERSION_ >= 1.5) ? 'contact' : 'contact-form'
));
return $this->display(__FILE__, 'blockcms.tpl');
$this->smarty->assign(array(
'block' => 1,
'cms_titles' => $cms_titles,
'contact_url' => (_PS_VERSION_ >= 1.5) ? 'contact' : 'contact-form'
));
}
return $this->display(__FILE__, 'blockcms.tpl', $this->getCacheId($column));
}
private function _prepareHook()
protected function getCacheId($name = null)
{
$block_activation = Configuration::get('FOOTER_BLOCK_ACTIVATION');
if (!$block_activation)
return false;
$cms_titles = BlockCMSModel::getCMSTitlesFooter();
$display_footer = Configuration::get('PS_STORES_DISPLAY_FOOTER');
$display_poweredby = Configuration::get('FOOTER_POWEREDBY');
$footer_text = Configuration::get('FOOTER_CMS_TEXT_'.(int)$this->context->language->id);
$this->smarty->assign(
array(
'block' => 0,
'contact_url' => 'contact',
'cmslinks' => $cms_titles,
'display_stores_footer' => $display_footer,
'display_poweredby' => ((int)$display_poweredby === 1 || $display_poweredby === false),
'footer_text' => $footer_text
)
);
return true;
return parent::getCacheId('blockcms|'.$name);
}
public function hookActionObjectCmsUpdateAfter()
{
$this->_clearCache('blockcms.tpl');
}
public function hookActionObjectCmsDeleteAfter()
{
$this->_clearCache('blockcms.tpl');
}
public function hookHeader($params)
{
@@ -715,9 +710,28 @@ class BlockCms extends Module
public function hookFooter()
{
if (!$this->_prepareHook())
return ;
return $this->display(__FILE__, 'blockcms.tpl');
if (!($block_activation = Configuration::get('FOOTER_BLOCK_ACTIVATION')))
return;
if (!$this->isCached('blockcms.tpl', $this->getCacheId(BlockCMSModel::FOOTER)))
{
$cms_titles = BlockCMSModel::getCMSTitlesFooter();
$display_footer = Configuration::get('PS_STORES_DISPLAY_FOOTER');
$display_poweredby = Configuration::get('FOOTER_POWEREDBY');
$footer_text = Configuration::get('FOOTER_CMS_TEXT_'.(int)$this->context->language->id);
$this->smarty->assign(
array(
'block' => 0,
'contact_url' => 'contact',
'cmslinks' => $cms_titles,
'display_stores_footer' => $display_footer,
'display_poweredby' => ((int)$display_poweredby === 1 || $display_poweredby === false),
'footer_text' => $footer_text
)
);
}
return $this->display(__FILE__, 'blockcms.tpl', $this->getCacheId(BlockCMSModel::FOOTER));
}
protected function updatePositionsDnd()
+1 -1
View File
@@ -2,7 +2,7 @@
<module>
<name>blockcms</name>
<displayName><![CDATA[CMS Block]]></displayName>
<version><![CDATA[1.1.1]]></version>
<version><![CDATA[1.2]]></version>
<description><![CDATA[Adds a block with several CMS links.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
+9
View File
@@ -0,0 +1,9 @@
<?php
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_1_2($object)
{
return ($object->registerHook('actionObjectCmsUpdateAfter') && $object->registerHook('actionObjectCmsDeleteAfter'));
}