Implement filterable offer list
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace EP\EpEvents\Domain\Dto;
|
||||
|
||||
class FilterSettings
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $travelType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $locationType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $locationDistance;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $hotelType;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $activityType;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTravelType()
|
||||
{
|
||||
return $this->travelType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $travelType
|
||||
*/
|
||||
public function setTravelType($travelType)
|
||||
{
|
||||
$this->travelType = $travelType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLocationType()
|
||||
{
|
||||
return $this->locationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $locationType
|
||||
*/
|
||||
public function setLocationType($locationType)
|
||||
{
|
||||
$this->locationType = $locationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLocationDistance()
|
||||
{
|
||||
return $this->locationDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $locationDistance
|
||||
*/
|
||||
public function setLocationDistance($locationDistance)
|
||||
{
|
||||
$this->locationDistance = $locationDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHotelType()
|
||||
{
|
||||
return $this->hotelType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $hotelType
|
||||
*/
|
||||
public function setHotelType($hotelType)
|
||||
{
|
||||
$this->hotelType = $hotelType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getActivityType()
|
||||
{
|
||||
return $this->activityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $activityType
|
||||
*/
|
||||
public function setActivityType($activityType)
|
||||
{
|
||||
$this->activityType = $activityType;
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,10 @@ namespace EP\EpEvents\Domain\Repository;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpEvents\Domain\Dto\FilterSettings;
|
||||
use EP\EpEvents\Domain\Model\Activity;
|
||||
use EP\EpEvents\Domain\Model\Offer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
|
||||
|
||||
class OfferRepository extends AbstractRepository
|
||||
@@ -74,6 +76,72 @@ class OfferRepository extends AbstractRepository
|
||||
return $query->matching($query->logicalAnd($constraints))->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FilterSettings $filterSettings
|
||||
* @return array
|
||||
*/
|
||||
public function findByFilterSettings(FilterSettings $filterSettings)
|
||||
{
|
||||
/** @var ConnectionPool $connectionPool */
|
||||
$connectionPool = $this->objectManager->get(ConnectionPool::class);
|
||||
$qb = $connectionPool->getQueryBuilderForTable('tx_epevents_domain_model_offer');
|
||||
|
||||
$qb->select(
|
||||
'o.uid AS uid', 'o.name AS name', 'o.configurator_type AS configuratorType',
|
||||
'o.detail_page AS detailPageUid',
|
||||
'l.name AS locationName', 'l.configurator_type AS locationType',
|
||||
'l.configurator_distance AS locationDistance', 'h.configurator_type AS hotelType',
|
||||
'a.configurator_type AS activityType'
|
||||
)
|
||||
->from('tx_epevents_domain_model_offer', 'o')
|
||||
->join('o', 'tx_epevents_domain_model_location', 'l', 'o.location = l.uid')
|
||||
->join('o', 'tx_epevents_domain_model_hotel', 'h', 'o.hotel = h.uid')
|
||||
->join('o', 'tx_epevents_offer_activity_mm', 'mm', 'mm.uid_local = o.uid')
|
||||
->join('mm', 'tx_epevents_domain_model_activity', 'a', 'mm.uid_foreign = a.uid')
|
||||
->where($qb->expr()->neq('o.type', Offer::TYPE_CLIENT))
|
||||
->orderBy('l.name', 'ASC')
|
||||
->addOrderBy('o.name', 'ASC');
|
||||
|
||||
if ($filterSettings->getTravelType() > 0) {
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'o.configurator_type', $qb->createNamedParameter($filterSettings->getTravelType())
|
||||
));
|
||||
}
|
||||
if ($filterSettings->getLocationDistance() > 0) {
|
||||
$qb->andWhere($qb->expr()->eq('l.configurator_distance', $filterSettings->getLocationDistance()));
|
||||
}
|
||||
if ($filterSettings->getLocationType() > 0) {
|
||||
$qb->andWhere($qb->expr()->eq('l.configurator_type', $filterSettings->getLocationType()));
|
||||
}
|
||||
if ($filterSettings->getHotelType() > 0) {
|
||||
$qb->andWhere($qb->expr()->eq('h.configurator_type', $filterSettings->getHotelType()));
|
||||
}
|
||||
if ($filterSettings->getActivityType() > 0) {
|
||||
$qb->andWhere($qb->expr()->eq('a.configurator_type', $filterSettings->getActivityType()));
|
||||
}
|
||||
|
||||
$result = $qb->execute()->fetchAll();
|
||||
$offers = [];
|
||||
|
||||
foreach ($result as $row) {
|
||||
if (!array_key_exists($row['uid'], $offers)) {
|
||||
$offers[$row['uid']] = [
|
||||
'name' => $row['name'],
|
||||
'configuratorType' => $row['configuratorType'],
|
||||
'detailPageUid' => $row['detailPageUid'],
|
||||
'locationType' => $row['locationType'],
|
||||
'locationName' => $row['locationName'],
|
||||
'locationDistance' => $row['locationDistance'],
|
||||
'hotelType' => $row['hotelType'],
|
||||
'activityTypes' => [],
|
||||
];
|
||||
}
|
||||
$offers[$row['uid']]['activityTypes'][] = $row['activityType'];
|
||||
}
|
||||
|
||||
return $offers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity $activity
|
||||
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
|
||||
|
||||
Reference in New Issue
Block a user