76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Smarty plugin
|
|
* -------------------------------------------------------------
|
|
* Type: function
|
|
* Name: get_html_page
|
|
* Purpose: get HTML page of given: name, id or label
|
|
* -------------------------------------------------------------
|
|
*/
|
|
|
|
use KupShop\ContentBundle\Entity\Wrapper\PageWrapper;
|
|
use KupShop\ContentBundle\Util\MenuLinksPage;
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
use Query\Operator;
|
|
|
|
/**
|
|
* @param $smarty \Smarty
|
|
*
|
|
* @return string
|
|
*/
|
|
function smarty_function_get_html_page($params, &$smarty)
|
|
{
|
|
if (empty($params['name']) && empty($params['id']) && empty($params['label'])) {
|
|
return 'get_html_page: Have to specify one of parameters: id, name or label';
|
|
}
|
|
|
|
$menuLinkId = null;
|
|
if (isset($params['name']) && !$menuLinkId) {
|
|
$menuLinkId = findMenuLinkBySpec(Operator::equals(['name' => $params['name']]));
|
|
}
|
|
|
|
if (isset($params['id']) && is_numeric($params['id']) && !$menuLinkId) {
|
|
$menuLinkId = findMenuLinkBySpec(Operator::equals(['old_id_page' => $params['id']]));
|
|
}
|
|
|
|
if (isset($params['label']) && !$menuLinkId) {
|
|
$menuLinkId = findMenuLinkBySpec(Operator::equals(['code' => $params['label']]));
|
|
}
|
|
|
|
/** @var MenuLinksPage $menuLinksPage */
|
|
$menuLinksPage = ServiceContainer::getService(MenuLinksPage::class);
|
|
$pageWrapper = ServiceContainer::getService(PageWrapper::class);
|
|
|
|
if ($menuLinkId) {
|
|
$page = [];
|
|
if ($pageEntity = $menuLinksPage->getPage((int) $menuLinkId)) {
|
|
$page = $pageWrapper->setObject($pageEntity);
|
|
}
|
|
} else {
|
|
return 'Neexistuje stránka: '.print_r($params, true);
|
|
}
|
|
|
|
if (empty($params['assign'])) {
|
|
foreach ($page['blocks'] as $block) {
|
|
$firstBlockContent = $block['content'];
|
|
break;
|
|
}
|
|
|
|
return isset($firstBlockContent) ? $firstBlockContent : '';
|
|
}
|
|
|
|
$smarty->assign($params['assign'], $page);
|
|
|
|
return '';
|
|
}
|
|
|
|
function findMenuLinkBySpec($spec)
|
|
{
|
|
return sqlQueryBuilder()->select('id')
|
|
->from('menu_links')
|
|
->where($spec)
|
|
->execute()
|
|
->fetchColumn();
|
|
}
|