first commit
This commit is contained in:
68
class/smarty_plugins/function.insert_slider.php
Normal file
68
class/smarty_plugins/function.insert_slider.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* Type: function
|
||||
* Name: eval
|
||||
* Purpose: evaluate a template variable as a template
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
use KupShop\ContentBundle\Util\SliderUtil;
|
||||
use KupShop\KupShopBundle\Context\CacheContext;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
use KupShop\KupShopBundle\Util\Contexts;
|
||||
|
||||
function smarty_function_insert_slider($params, &$smarty)
|
||||
{
|
||||
if (!findModule('sliders')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$default = [
|
||||
'template' => 'block.slider.tpl',
|
||||
'id' => null,
|
||||
'cache' => null,
|
||||
'cache_key' => function ($params) {
|
||||
$cacheContext = Contexts::get(CacheContext::class);
|
||||
|
||||
return ['sliders', $params['id'], $cacheContext->getKey([CacheContext::TYPE_FULL_PAGE])];
|
||||
},
|
||||
];
|
||||
|
||||
if (empty($params['id']) && empty($params['label']) && empty($params['slider'])) {
|
||||
trigger_error("insert_slider: missing 'id', 'label' or 'slider'");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$smarty->loadPlugin('Smarty_function_include_cached');
|
||||
|
||||
if (!empty($params['slider'])) {
|
||||
$params = array_merge($default, $params);
|
||||
|
||||
smarty_function_include_cached_optional($params, $smarty);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($params['id']) && !empty($params['label'])) {
|
||||
$params['id'] = sqlQueryBuilder()->select('id')->from('sliders')
|
||||
->where(\Query\Operator::equals(['label' => $params['label']]))
|
||||
->execute()->fetchColumn();
|
||||
}
|
||||
|
||||
$params = array_merge($default, $params);
|
||||
|
||||
$params['get_data_function'] = function (&$params) {
|
||||
if (empty($params['id'])) {
|
||||
$params['slider'] = false;
|
||||
} else {
|
||||
$sliderUtil = ServiceContainer::getService(SliderUtil::class);
|
||||
$params['slider'] = $sliderUtil->get((int) $params['id']);
|
||||
}
|
||||
};
|
||||
|
||||
smarty_function_include_cached_optional($params, $smarty);
|
||||
}
|
||||
Reference in New Issue
Block a user