first commit
This commit is contained in:
63
bundles/KupShop/ContentBundle/Feed/PageConfigurableFeed.php
Normal file
63
bundles/KupShop/ContentBundle/Feed/PageConfigurableFeed.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace KupShop\ContentBundle\Feed;
|
||||
|
||||
use KupShop\ContentBundle\Feed\Wrapper\PageWrapper;
|
||||
use KupShop\ContentBundle\Util\MenuUtil;
|
||||
use KupShop\FeedGeneratorBundle\Feed\ConfigurableFeedTrait;
|
||||
use KupShop\FeedGeneratorBundle\Feed\IConfigurableFeed;
|
||||
use KupShop\FeedsBundle\Feed\IFeed;
|
||||
use KupShop\I18nBundle\Translations\MenuLinksTranslation;
|
||||
use Query\Operator;
|
||||
use Query\QueryBuilder;
|
||||
use Query\Translation;
|
||||
|
||||
class PageConfigurableFeed implements IFeed, IConfigurableFeed
|
||||
{
|
||||
use \DatabaseCommunication;
|
||||
use ConfigurableFeedTrait;
|
||||
|
||||
/** @var string */
|
||||
public static $type = 'pageConfigurable';
|
||||
|
||||
/** @var string */
|
||||
public static $alias = 'Stránky';
|
||||
|
||||
/** @var string */
|
||||
public static $objectType = 'page';
|
||||
|
||||
/** @var \Query\QueryBuilder */
|
||||
protected $query;
|
||||
|
||||
public function __construct(PageWrapper $pageWrapper)
|
||||
{
|
||||
$this->objectWrapper = $pageWrapper;
|
||||
}
|
||||
|
||||
public function getQuery(): QueryBuilder
|
||||
{
|
||||
$qb = sqlQueryBuilder()->select('ml.*')
|
||||
->from('menu_links', 'ml')
|
||||
->where(Operator::equals(['ml.type' => MenuUtil::TYPE_PAGE]))
|
||||
->andWhere(Translation::coalesceTranslatedFields(MenuLinksTranslation::class))
|
||||
->orderBy('ml.parent, ml.list_order');
|
||||
|
||||
foreach ($this->specs as $spec) {
|
||||
$qb->andWhere($spec);
|
||||
}
|
||||
|
||||
$this->query = $qb;
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function filterByObjectID($objectID): void
|
||||
{
|
||||
$this->specs[] = Operator::equals(['ml.id' => $objectID]);
|
||||
}
|
||||
|
||||
public static function isAllowed(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
135
bundles/KupShop/ContentBundle/Feed/Wrapper/PageWrapper.php
Normal file
135
bundles/KupShop/ContentBundle/Feed/Wrapper/PageWrapper.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace KupShop\ContentBundle\Feed\Wrapper;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use KupShop\FeedsBundle\Utils\FeedUtils;
|
||||
use KupShop\FeedsBundle\Wrapper\BaseWrapper;
|
||||
use KupShop\FeedsBundle\Wrapper\BlockWrapper;
|
||||
use KupShop\FeedsBundle\Wrapper\BlockWrapperFactory;
|
||||
use KupShop\FeedsBundle\Wrapper\MultiWrapper;
|
||||
use KupShop\FeedsBundle\Wrapper\PhotoWrapper;
|
||||
use KupShop\FeedsBundle\Wrapper\PhotoWrapperFactory;
|
||||
use Symfony\Component\Routing\Router;
|
||||
|
||||
class PageWrapper extends BaseWrapper
|
||||
{
|
||||
protected ArrayCollection $objects;
|
||||
|
||||
protected array $feedRow;
|
||||
|
||||
protected MultiWrapper $blocksWrapper;
|
||||
|
||||
protected PhotoWrapper $photoWrapper;
|
||||
protected MultiWrapper $photosWrapper;
|
||||
|
||||
public function __construct(
|
||||
PhotoWrapper $photoWrapper,
|
||||
PhotoWrapperFactory $photoWrapperFactory,
|
||||
BlockWrapper $blockWrapper,
|
||||
BlockWrapperFactory $blockWrapperFactory,
|
||||
protected FeedUtils $feedUtils,
|
||||
) {
|
||||
$this->photoWrapper = $photoWrapper;
|
||||
$this->photosWrapper = new MultiWrapper($photoWrapper, $photoWrapperFactory);
|
||||
$this->blocksWrapper = new MultiWrapper($blockWrapper, $blockWrapperFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $feedRow
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
public function setFeedRow($feedRow)
|
||||
{
|
||||
$this->feedRow = $feedRow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
public function setObjects(ArrayCollection $objects): void
|
||||
{
|
||||
$this->objects = $objects;
|
||||
}
|
||||
|
||||
/** ID stránky */
|
||||
public function field_id(): int
|
||||
{
|
||||
return (int) $this->object->id;
|
||||
}
|
||||
|
||||
/** Název stránky */
|
||||
public function field_title(): ?string
|
||||
{
|
||||
return $this->object->name ?? null;
|
||||
}
|
||||
|
||||
/** Krátký název stránky v menu */
|
||||
public function field_title_short(): ?string
|
||||
{
|
||||
return $this->object->name_short ?? null;
|
||||
}
|
||||
|
||||
/** Viditelnost stránky.
|
||||
*
|
||||
* Y - Viditelná
|
||||
* N - Skrytá
|
||||
*/
|
||||
public function field_visibility(): string
|
||||
{
|
||||
return $this->object->figure ?? 'Y';
|
||||
}
|
||||
|
||||
/** Hlavní obrázek */
|
||||
public function field_main_photo()
|
||||
{
|
||||
$this->fetchPhotos();
|
||||
|
||||
return ($this->object->_main_photo['src'] ?? false) ? $this->photoWrapper->setObject($this->object->_main_photo) : null;
|
||||
}
|
||||
|
||||
/** Ostatní obrázky */
|
||||
public function field_photos()
|
||||
{
|
||||
$this->fetchPhotos();
|
||||
|
||||
return $this->photosWrapper->setObject($this->object->_photos ?? []);
|
||||
}
|
||||
|
||||
/** URL adresa stránky */
|
||||
public function field_url(): string
|
||||
{
|
||||
return path(
|
||||
'page_not_found',
|
||||
['path' => $this->object->url],
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
}
|
||||
|
||||
/** Bloky (obsah) */
|
||||
public function field_blocks()
|
||||
{
|
||||
$this->feedUtils->fetchCollectionBlocks($this->objects);
|
||||
|
||||
return !empty($this->object->_raw_blocks) ? $this->blocksWrapper->setObject($this->object->_raw_blocks) : [];
|
||||
}
|
||||
|
||||
/** SEO název */
|
||||
public function field_meta_title()
|
||||
{
|
||||
return $this->object->meta_title;
|
||||
}
|
||||
|
||||
/** SEO popis */
|
||||
public function field_meta_description()
|
||||
{
|
||||
return $this->object->meta_description;
|
||||
}
|
||||
|
||||
/** @private */
|
||||
protected function fetchPhotos()
|
||||
{
|
||||
$this->feedUtils->fetchPhotos($this->objects, 'photos_menu_relation', 'id_menu', 'product_catalog');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user