94 lines
2.4 KiB
PHP
94 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Smarty plugin.
|
|
*/
|
|
use KupShop\I18nBundle\Translations\PhotosTranslation;
|
|
use Query\Translation;
|
|
|
|
/**
|
|
* Smarty {url} plugin.
|
|
*
|
|
* Type: function<br>
|
|
* Name: get_photos<br>
|
|
* Purpose: return array of photos for product/article/page
|
|
*
|
|
* @param array $params parameters
|
|
* @param Smarty_Internal_Template $smarty template object
|
|
*
|
|
* @return string
|
|
*/
|
|
function smarty_function_get_photos($params, &$smarty)
|
|
{
|
|
$type = 'null';
|
|
$id = null;
|
|
$image = null;
|
|
|
|
extract($params);
|
|
$photos = [];
|
|
switch ($type) {
|
|
case 'pages':
|
|
$field = 'id_menu';
|
|
if (!$image) {
|
|
$image = 1;
|
|
}
|
|
$menu_id = returnSQLResult('SELECT id FROM menu_links WHERE old_id_page=:id', ['id' => $id]);
|
|
// Pokud staré ID neexistuje, tváříme se, že jsme dostali nové ID stránky kvůli kompatibilitě.
|
|
if ($menu_id) {
|
|
$id = $menu_id;
|
|
}
|
|
$type = 'menu';
|
|
break;
|
|
case 'articles':
|
|
$field = 'id_art';
|
|
if (!$image) {
|
|
$image = 1;
|
|
}
|
|
break;
|
|
case 'products':
|
|
$image = 1;
|
|
break;
|
|
case 'sections':
|
|
if (!$image) {
|
|
$image = 1;
|
|
}
|
|
break;
|
|
case 'producers':
|
|
$field = 'id_producer';
|
|
if (!$image) {
|
|
$image = 1;
|
|
}
|
|
break;
|
|
default:
|
|
echo "Non-existing type: {$type}";
|
|
|
|
return;
|
|
}
|
|
|
|
if (empty($field)) {
|
|
$field = 'id_'.substr($type, 0, -1);
|
|
}
|
|
|
|
$SQL = sqlQueryBuilder()
|
|
->select('ph.*, pr.id_photo')
|
|
->from('photos_'.$type.'_relation', 'pr')
|
|
->leftJoin('pr', 'photos', 'ph', 'pr.id_photo = ph.id')
|
|
->where(Translation::coalesceTranslatedFields(PhotosTranslation::class))
|
|
->andWhere(\Query\Operator::equals(['pr.'.$field => $id]))
|
|
->orderBy('position', 'ASC')
|
|
->execute();
|
|
|
|
if (!empty($SQL)) {
|
|
foreach ($SQL as $photo) {
|
|
$photo['img'] = getImage($photo['id_photo'], $photo['image_2'], $photo['source'], $image, $photo['descr'], strtotime($photo['date_update']));
|
|
$photos[] = $photo;
|
|
}
|
|
}
|
|
|
|
if (!empty($assign)) {
|
|
$smarty->assign($assign, $photos);
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|