first commit
This commit is contained in:
45
bundles/KupShop/ComponentsBundle/Dto/SectionsMultiFetch.php
Normal file
45
bundles/KupShop/ComponentsBundle/Dto/SectionsMultiFetch.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace KupShop\ComponentsBundle\Dto;
|
||||
|
||||
use KupShop\ContentBundle\Util\SliderUtil;
|
||||
use Query\Operator;
|
||||
use Query\QueryBuilder;
|
||||
|
||||
class SectionsMultiFetch
|
||||
{
|
||||
private array $wasCalled = [];
|
||||
|
||||
public function __construct(protected array &$sections, private readonly SliderUtil $sliderUtil)
|
||||
{
|
||||
}
|
||||
|
||||
public function fetchSliders(): void
|
||||
{
|
||||
if (array_key_exists(__FUNCTION__, $this->wasCalled)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loadedSliders = $this->sliderUtil->fetchSliders(
|
||||
function (QueryBuilder $qb) {
|
||||
$sectionPositions = sqlQueryBuilder()
|
||||
->select('DISTINCT sis.id_slider', 'sis.position, sis.id_section')
|
||||
->from('sliders_in_sections', 'sis')
|
||||
->andWhere(Operator::inIntArray(array_keys($this->sections), 'sis.id_section'));
|
||||
|
||||
$qb->addSelect('sis.position AS section_position, sis.id_section')
|
||||
->joinSubQuery('sl', $sectionPositions, 'sis', 'sl.id = sis.id_slider');
|
||||
},
|
||||
indexBy: 'section_position',
|
||||
);
|
||||
|
||||
foreach ($loadedSliders as $key => $slider) {
|
||||
$object = $this->sections[$slider['id_section']]->getObject();
|
||||
$sliders = $object->getSliders();
|
||||
$sliders[$key] = $slider;
|
||||
$object->setSliders($sliders);
|
||||
}
|
||||
|
||||
$this->wasCalled[__FUNCTION__] = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user