Cleanup code, add missing return types
This commit is contained in:
+128
-159
@@ -2,43 +2,19 @@
|
||||
|
||||
namespace EP\EpProducts\Domain\Repository;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2016 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpProducts\Domain\Model\Dto\FilterOptions;
|
||||
use EP\EpProducts\Service\FilterService;
|
||||
use EP\EpProducts\Traits\DbConnectionTrait;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
|
||||
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
|
||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||
|
||||
abstract class AbstractRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
|
||||
abstract class AbstractRepository extends Repository
|
||||
{
|
||||
use DbConnectionTrait;
|
||||
|
||||
public function initializeObject()
|
||||
public function initializeObject(): void
|
||||
{
|
||||
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
|
||||
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
|
||||
@@ -60,202 +36,195 @@ abstract class AbstractRepository extends \TYPO3\CMS\Extbase\Persistence\Reposit
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
protected function addDateFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addFiltersettingsConditions
|
||||
(
|
||||
QueryBuilder $qb,
|
||||
array $filterSettings,
|
||||
bool $constraintDates = true
|
||||
): void {
|
||||
if ($constraintDates) {
|
||||
$this->addDateFilterConditions($qb, $filterSettings);
|
||||
}
|
||||
$this->addPriceRangeFilterConditions($qb, $filterSettings);
|
||||
$this->addCountryRegionAndCityFilterConditions($qb, $filterSettings);
|
||||
$this->addConceptFilterConditions($qb, $filterSettings);
|
||||
$this->addPaxFilterConditions($qb, $filterSettings);
|
||||
$this->addDurationFilterConditions($qb, $filterSettings);
|
||||
$this->addHotelTypesFilterConditions($qb, $filterSettings);
|
||||
$this->addBoardTypesFilterConditions($qb, $filterSettings);
|
||||
$this->addRoomTypesFilterConditions($qb, $filterSettings);
|
||||
$this->addTransportationFilterConditions($qb, $filterSettings);
|
||||
|
||||
// Product
|
||||
if (!empty($filterSettings['productUid'])) {
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'date.product',
|
||||
$qb->createNamedParameter((int)$filterSettings['productUid'], Connection::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
// Hotel
|
||||
if (!empty($filterSettings['hotelUid'])) {
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'date.hotel',
|
||||
$qb->createNamedParameter((int)$filterSettings['hotelUid'], Connection::PARAM_INT)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addDateFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Date Start
|
||||
if (!empty($filterSettings['dateFrom'])) {
|
||||
$query
|
||||
->andWhere('date.date_start >= :dateStart')
|
||||
->setParameter('dateStart', $filterSettings['dateFrom'])
|
||||
;
|
||||
$qb->andWhere($qb->expr()->gte(
|
||||
'date.date_start',
|
||||
$qb->createNamedParameter($filterSettings['dateFrom'])
|
||||
));
|
||||
}
|
||||
|
||||
// Date End
|
||||
if (!empty($filterSettings['dateTo'])) {
|
||||
$query
|
||||
->andWhere('date.date_end <= :dateEnd')
|
||||
->setParameter('dateEnd', $filterSettings['dateTo'])
|
||||
;
|
||||
$qb->andWhere($qb->expr()->lte(
|
||||
'date.date_end',
|
||||
$qb->createNamedParameter($filterSettings['dateTo'])
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addHotelFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addHotelFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Hotel
|
||||
if (!empty($filterSettings['hotelUid'])) {
|
||||
$query
|
||||
->andWhere('date.hotel = :hotelUid')
|
||||
->setParameter('hotelUid', (int)$filterSettings['hotelUid'])
|
||||
;
|
||||
if ($filterSettings['hotelUid'] > 0) {
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'date.hotel',
|
||||
$qb->createNamedParameter((int)$filterSettings['hotelUid'], Connection::PARAM_INT)
|
||||
));
|
||||
}
|
||||
|
||||
// Hotel types
|
||||
if (!empty($filterSettings['hotelTypes'])) {
|
||||
$query
|
||||
->andWhere('date.hotel_type IN (:hotelTypes)')
|
||||
->setParameter('hotelTypes', (array)$filterSettings['hotelTypes'], Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
if (count($filterSettings['hotelTypes']) > 0) {
|
||||
$qb->andWhere($qb->expr()->in(
|
||||
'date.hotel_type',
|
||||
$qb->createNamedParameter($filterSettings['hotelTypes'], Connection::PARAM_INT_ARRAY)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addCountryRegionAndCityFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addCountryRegionAndCityFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
if (!empty($filterSettings['cityUids'])) {
|
||||
$query
|
||||
->andWhere('date.city IN (:cityUids)')
|
||||
->setParameter('cityUids', (array)$filterSettings['cityUids'], Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
} elseif (!empty($filterSettings['regionUids'])) {
|
||||
$query
|
||||
->andWhere('date.region IN (:regionUids)')
|
||||
->setParameter('regionUids', (array)$filterSettings['regionUids'], Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
} elseif (!empty($filterSettings['countryUids'])) {
|
||||
$query
|
||||
->andWhere('date.country IN (:countryUids)')
|
||||
->setParameter('countryUids', (array)$filterSettings['countryUids'], Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
foreach (['city', 'region', 'country'] as $column) {
|
||||
$key = $column . 'Uids';
|
||||
if (count($filterSettings[$key]) > 0) {
|
||||
$qb->andWhere($qb->expr()->in(
|
||||
'date.' . $column,
|
||||
$qb->createNamedParameter($filterSettings[$key], Connection::PARAM_INT_ARRAY)
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function addConceptFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addConceptFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
if (!empty($filterSettings['conceptUids'])) {
|
||||
$query
|
||||
->andWhere('date.concept IN (:conceptUids)')
|
||||
->setParameter('conceptUids', (array)$filterSettings['conceptUids'], Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
if (count($filterSettings['conceptUids']) > 0) {
|
||||
$qb->andWhere($qb->expr()->in(
|
||||
'date.concept',
|
||||
$qb->createNamedParameter($filterSettings['conceptUids'], Connection::PARAM_INT_ARRAY)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addPaxFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addPaxFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Pax
|
||||
if (!empty($filterSettings['pax'])) {
|
||||
$query
|
||||
->andWhere('date.available >= :pax')
|
||||
->setParameter('pax', (int)$filterSettings['pax'])
|
||||
;
|
||||
if ($filterSettings['pax'] > 0) {
|
||||
$qb->andWhere($qb->expr()->gte(
|
||||
'date.available',
|
||||
$qb->createNamedParameter($filterSettings['pax'], Connection::PARAM_INT)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addPriceRangeFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addPriceRangeFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Price ranges
|
||||
if (!empty($filterSettings['priceRanges'])) {
|
||||
$orX = $query->expr()->orX();
|
||||
foreach ((array)$filterSettings['priceRanges'] as $priceRange) {
|
||||
if (count($filterSettings['priceRanges']) > 0) {
|
||||
$orX = $qb->expr()->orX();
|
||||
foreach ($filterSettings['priceRanges'] as $priceRange) {
|
||||
[ $priceMin, $priceMax ] = FilterOptions::$priceRangeOptions[$priceRange];
|
||||
$orX->add($query->expr()->andX(
|
||||
$query->expr()->gte('date.min_price', ':priceMin'),
|
||||
$query->expr()->lt('date.min_price', ':priceMax')
|
||||
$orX->add($qb->expr()->andX(
|
||||
$qb->expr()->gte(
|
||||
'date.min_price',
|
||||
$qb->createNamedParameter($priceMin, Connection::PARAM_INT)
|
||||
),
|
||||
$qb->expr()->lt(
|
||||
'date.min_price',
|
||||
$qb->createNamedParameter($priceMax, Connection::PARAM_INT)
|
||||
)
|
||||
));
|
||||
$query
|
||||
->setParameter('priceMin', $priceMin)
|
||||
->setParameter('priceMax', $priceMax)
|
||||
;
|
||||
}
|
||||
$query->andWhere($orX);
|
||||
$qb->andWhere($orX);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addDurationFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addDurationFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Duration
|
||||
if (empty($filterSettings['nights'])) {
|
||||
if (0 === $filterSettings['nights']) {
|
||||
return;
|
||||
}
|
||||
$nights = (int)$filterSettings['nights'];
|
||||
$nights = $filterSettings['nights'];
|
||||
if ($nights === FilterService::DURATION_SHORT) {
|
||||
$query
|
||||
->andWhere('date.nights <= :nights')
|
||||
->setParameter('nights', $nights)
|
||||
;
|
||||
$qb->andWhere($qb->expr()->lte(
|
||||
'date.nights',
|
||||
$qb->createNamedParameter($nights, Connection::PARAM_INT))
|
||||
);
|
||||
} elseif ($nights === FilterService::DURATION_LONG) {
|
||||
$query
|
||||
->andWhere('date.nights >= :nights')
|
||||
->setParameter('nights', $nights)
|
||||
;
|
||||
$qb->andWhere($qb->expr()->gte(
|
||||
'date.nights',
|
||||
$qb->createNamedParameter($nights, Connection::PARAM_INT))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addHotelTypesFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addHotelTypesFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Hotel types
|
||||
if (!empty($filterSettings['hotelTypes'])) {
|
||||
$query
|
||||
->andWhere('date.hotel_type IN (:hotelTypes)')
|
||||
->setParameter('hotelTypes', (array)$filterSettings['hotelTypes'], Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
if (count($filterSettings['hotelTypes']) > 0) {
|
||||
$qb->andWhere($qb->expr()->in(
|
||||
'date.hotel_type',
|
||||
$qb->createNamedParameter($filterSettings['hotelTypes'], Connection::PARAM_INT_ARRAY)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addBoardTypesFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addBoardTypesFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Board types
|
||||
if (!empty($filterSettings['boardTypes'])) {
|
||||
$query
|
||||
->andWhere('date.board_bus_pro_id IN (:boardTypes)')
|
||||
->setParameter('boardTypes', (array)$filterSettings['boardTypes'], Connection::PARAM_STR_ARRAY)
|
||||
;
|
||||
if (count($filterSettings['boardTypes']) > 0) {
|
||||
$qb->andWhere($qb->expr()->in(
|
||||
'date.board_bus_pro_id',
|
||||
$qb->createNamedParameter($filterSettings['boardTypes'], Connection::PARAM_INT_ARRAY)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addRoomTypesFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addRoomTypesFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Room types
|
||||
if (!empty($filterSettings['roomTypes'])) {
|
||||
$query
|
||||
->andWhere('room.type IN (:roomTypes)')
|
||||
->setParameter('roomTypes', (array)$filterSettings['roomTypes'], Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
if (count($filterSettings['roomTypes']) > 0) {
|
||||
$qb->andWhere($qb->expr()->in(
|
||||
'room.type',
|
||||
$qb->createNamedParameter($filterSettings['roomTypes'], Connection::PARAM_INT_ARRAY)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addTransportationFilterConditions(QueryBuilder $query, array $filterSettings): void
|
||||
protected function addTransportationFilterConditions(QueryBuilder $qb, array $filterSettings): void
|
||||
{
|
||||
// Transportation
|
||||
if (!empty($filterSettings['bus'])) {
|
||||
$query->andWhere('date.bus_available = 1');
|
||||
if (null !== $filterSettings['bus']) {
|
||||
$qb->andWhere($qb->expr()->eq('date.bus_available', 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds general conditions for provided filtersettings
|
||||
*
|
||||
* @param QueryBuilder $query
|
||||
* @param array $filterSettings
|
||||
* @param bool $constraintDates
|
||||
*/
|
||||
protected function addFiltersettingsConditions(QueryBuilder $query, array $filterSettings, bool $constraintDates = true)
|
||||
{
|
||||
if ($constraintDates) {
|
||||
$this->addDateFilterConditions($query, $filterSettings);
|
||||
}
|
||||
$this->addPriceRangeFilterConditions($query, $filterSettings);
|
||||
$this->addCountryRegionAndCityFilterConditions($query, $filterSettings);
|
||||
$this->addConceptFilterConditions($query, $filterSettings);
|
||||
$this->addPaxFilterConditions($query, $filterSettings);
|
||||
$this->addDurationFilterConditions($query, $filterSettings);
|
||||
$this->addHotelTypesFilterConditions($query, $filterSettings);
|
||||
$this->addBoardTypesFilterConditions($query, $filterSettings);
|
||||
$this->addRoomTypesFilterConditions($query, $filterSettings);
|
||||
$this->addTransportationFilterConditions($query, $filterSettings);
|
||||
|
||||
// Product
|
||||
if (!empty($filterSettings['productUid'])) {
|
||||
$query
|
||||
->andWhere('date.product = :productUid')
|
||||
->setParameter('productUid', (int)$filterSettings['productUid'])
|
||||
;
|
||||
}
|
||||
|
||||
// Hotel
|
||||
if (!empty($filterSettings['hotelUid'])) {
|
||||
$query
|
||||
->andWhere('date.hotel = :hotel')
|
||||
->setParameter(':hotel', (int)$filterSettings['hotelUid'])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,175 +2,5 @@
|
||||
|
||||
namespace EP\EpProducts\Domain\Repository;
|
||||
|
||||
use EP\EpProducts\Domain\Model\Product;
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
|
||||
class DateRepository extends AbstractRepository
|
||||
{
|
||||
|
||||
public function getDateRange(Product $product = null): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
->addSelectLiteral('MIN(date_start) dateRangeFrom')
|
||||
->addSelectLiteral('MAX(date_end) dateRangeTo')
|
||||
->from('tx_epproducts_domain_model_date', 'date')
|
||||
->where('date_start >= NOW()')
|
||||
->andWhere('product_searchable = 1')
|
||||
;
|
||||
|
||||
if ($product !== null) {
|
||||
$query
|
||||
->andWhere('product = :productUid')
|
||||
->setParameter('productUid', $product->getUid())
|
||||
;
|
||||
}
|
||||
|
||||
$dates = $query->execute()->fetchAssociative();
|
||||
|
||||
if ($dates['dateRangeFrom'] !== null && $dates['dateRangeTo'] !== null) {
|
||||
$dateRangeFrom = \DateTime::createFromFormat('Y-m-d', $dates['dateRangeFrom']);
|
||||
$dateRangeTo = \DateTime::createFromFormat('Y-m-d', $dates['dateRangeTo']);
|
||||
} else {
|
||||
$dateRangeFrom = new \DateTime('now');
|
||||
$dateRangeTo = clone $dateRangeFrom;
|
||||
$dateRangeTo->add(new \DateInterval('P1Y'));
|
||||
}
|
||||
|
||||
return [$dateRangeFrom, $dateRangeTo];
|
||||
}
|
||||
|
||||
public function searchHotels(string $search, array $filterSettings): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
->select('hotel as uid')
|
||||
->addSelectLiteral('REPLACE(hotel_name, "\r\n", " ") name')
|
||||
->from('tx_epproducts_domain_model_date', 'date')
|
||||
->where('product_searchable = 1')
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->like('hotel_name',':searchName'),
|
||||
$qb->expr()->like('hotel_keywords', ':searchKeywords')
|
||||
))
|
||||
->orderBy('hotel_name')
|
||||
->groupBy('hotel_name')
|
||||
->setParameters([
|
||||
'searchName' => '%' . $search . '%',
|
||||
'searchKeywords' => '%' . $search . '%'
|
||||
])
|
||||
;
|
||||
|
||||
if (null !== $filterSettings['productsPid']) {
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'date.product_pid',
|
||||
$qb->createNamedParameter($filterSettings['productsPid'], Connection::PARAM_INT))
|
||||
);
|
||||
}
|
||||
|
||||
$this->addDateFilterConditions($query, $filterSettings);
|
||||
$this->addDurationFilterConditions($query, $filterSettings);
|
||||
$this->addPaxFilterConditions($query, $filterSettings);
|
||||
$this->addConceptFilterConditions($query, $filterSettings);
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
}
|
||||
|
||||
public function searchProducts(string $search, array $filterSettings, array $excludedConceptUids = []): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
->select('product as uid')
|
||||
->addSelectLiteral('CONCAT(REPLACE(product_name, "\r\n", " "), " (", concept_name, ")") as name')
|
||||
->from('tx_epproducts_domain_model_date', 'date')
|
||||
->where('product_searchable = 1')
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->like('product_name',':searchName'),
|
||||
$qb->expr()->like('product_keywords', ':searchKeywords'),
|
||||
$qb->expr()->like('country_name',':searchKeywords'),
|
||||
$qb->expr()->like('country_keywords', ':searchKeywords'),
|
||||
$qb->expr()->like('region_name', ':searchKeywords'),
|
||||
$qb->expr()->like('region_keywords', ':searchKeywords'),
|
||||
$qb->expr()->like('city_name', ':searchKeywords'),
|
||||
$qb->expr()->like('city_keywords', ':searchKeywords')
|
||||
))
|
||||
->orderBy('product_name')
|
||||
->groupBy('product_name')
|
||||
->setParameters([
|
||||
'searchName' => '%' . $search . '%',
|
||||
'searchKeywords' => '%' . $search . '%'
|
||||
])
|
||||
;
|
||||
|
||||
if (null !== $filterSettings['productsPid']) {
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'date.product_pid',
|
||||
$qb->createNamedParameter($filterSettings['productsPid'], Connection::PARAM_INT))
|
||||
);
|
||||
}
|
||||
|
||||
if (count($excludedConceptUids) > 0) {
|
||||
$qb->andWhere($qb->expr()->notIn(
|
||||
'concept',
|
||||
$qb->createNamedParameter($excludedConceptUids, Connection::PARAM_INT_ARRAY))
|
||||
);
|
||||
}
|
||||
|
||||
$this->addDateFilterConditions($query, $filterSettings);
|
||||
$this->addDurationFilterConditions($query, $filterSettings);
|
||||
$this->addPaxFilterConditions($query, $filterSettings);
|
||||
$this->addConceptFilterConditions($query, $filterSettings);
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
}
|
||||
|
||||
public function searchDestinations(
|
||||
string $type,
|
||||
string $search,
|
||||
array $filterSettings,
|
||||
array $excludedRegionUids = []
|
||||
): array {
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
->select($type . ' as uid')
|
||||
->addSelectLiteral('REPLACE(' . $type . '_name, "\r\n", " ") as name')
|
||||
->from('tx_epproducts_domain_model_date', 'date')
|
||||
->where('product_searchable = 1')
|
||||
->andWhere($qb->expr()->orX(
|
||||
$qb->expr()->like($type . '_name',':searchName'),
|
||||
$qb->expr()->like($type . '_keywords', ':searchKeywords')
|
||||
))
|
||||
->orderBy($type . '_name')
|
||||
->groupBy($type . '_name')
|
||||
->setParameters([
|
||||
'searchName' => '%' . $search . '%',
|
||||
'searchKeywords' => '%' . $search . '%'
|
||||
])
|
||||
;
|
||||
|
||||
if (null !== $filterSettings['productsPid']) {
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'date.product_pid',
|
||||
$qb->createNamedParameter($filterSettings['productsPid'], Connection::PARAM_INT))
|
||||
);
|
||||
}
|
||||
|
||||
$this->addDateFilterConditions($query, $filterSettings);
|
||||
$this->addDurationFilterConditions($query, $filterSettings);
|
||||
$this->addPaxFilterConditions($query, $filterSettings);
|
||||
$this->addConceptFilterConditions($query, $filterSettings);
|
||||
|
||||
if (count($excludedRegionUids) > 0) {
|
||||
$query
|
||||
->andWhere('date.region NOT IN (:excludedRegionUids)')
|
||||
->setParameter('excludedRegionUids', $excludedRegionUids, Connection::PARAM_INT_ARRAY)
|
||||
;
|
||||
}
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
}
|
||||
|
||||
}
|
||||
{}
|
||||
|
||||
@@ -13,7 +13,7 @@ class ProductRepository extends AbstractRepository
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
$qb
|
||||
->select(
|
||||
'date.concept as conceptUid', 'date.concept_name as conceptName',
|
||||
'date.concept_code as conceptCode', 'date.product as productUid', 'date.product_name as productName',
|
||||
@@ -45,14 +45,17 @@ class ProductRepository extends AbstractRepository
|
||||
->addOrderBy('date.hotel_name')
|
||||
;
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
return $qb
|
||||
->execute()
|
||||
->fetchAllAssociative()
|
||||
;
|
||||
}
|
||||
|
||||
public function getSearchResult(array $filterSettings, array $excludedConceptUids = []): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
$qb
|
||||
->select(
|
||||
'date.concept as conceptUid', 'date.concept_name as conceptName',
|
||||
'date.concept_code as conceptCode', 'date.concept_sorting as conceptSorting',
|
||||
@@ -95,16 +98,19 @@ class ProductRepository extends AbstractRepository
|
||||
);
|
||||
}
|
||||
|
||||
$this->addFiltersettingsConditions($query, $filterSettings);
|
||||
$this->addFiltersettingsConditions($qb, $filterSettings);
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
return $qb
|
||||
->execute()
|
||||
->fetchAllAssociative()
|
||||
;
|
||||
}
|
||||
|
||||
public function getTeasers(array $filterSettings, array $excludedConceptUids = [], int $limit = 0): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
$qb
|
||||
->select(
|
||||
'product as productUid', 'product_name as productName', 'product_detail_page as productDetailPage',
|
||||
'product_feature as productFeature', 'product_teaser as productTeaser', 'product_fact as productFact',
|
||||
@@ -140,23 +146,23 @@ class ProductRepository extends AbstractRepository
|
||||
}
|
||||
|
||||
if ($limit > 0) {
|
||||
$query->setMaxResults($limit);
|
||||
$qb->setMaxResults($limit);
|
||||
}
|
||||
|
||||
if (empty($filterSettings['productUid'])) {
|
||||
$query->andWhere('product_searchable = 1');
|
||||
$qb->andWhere($qb->expr()->eq('product_searchable', 1));
|
||||
} else {
|
||||
$query->andWhere($qb->expr()->eq(
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'product',
|
||||
$qb->createNamedParameter($filterSettings['productUid'], Connection::PARAM_INT))
|
||||
);
|
||||
}
|
||||
|
||||
$this->addDateFilterConditions($query, $filterSettings);
|
||||
$this->addHotelFilterConditions($query, $filterSettings);
|
||||
$this->addCountryRegionAndCityFilterConditions($query, $filterSettings);
|
||||
$this->addConceptFilterConditions($query, $filterSettings);
|
||||
$this->addTransportationFilterConditions($query, $filterSettings);
|
||||
$this->addDateFilterConditions($qb, $filterSettings);
|
||||
$this->addHotelFilterConditions($qb, $filterSettings);
|
||||
$this->addCountryRegionAndCityFilterConditions($qb, $filterSettings);
|
||||
$this->addConceptFilterConditions($qb, $filterSettings);
|
||||
$this->addTransportationFilterConditions($qb, $filterSettings);
|
||||
|
||||
if (count($excludedConceptUids) > 0) {
|
||||
$qb->andWhere($qb->expr()->notIn(
|
||||
@@ -165,18 +171,22 @@ class ProductRepository extends AbstractRepository
|
||||
);
|
||||
}
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
return $qb
|
||||
->execute()
|
||||
->fetchAllAssociative()
|
||||
;
|
||||
}
|
||||
|
||||
public function getPricetable(Product $product, Hotel $hotel, array $filterSettings, Date $date = null): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
$qb
|
||||
->select(
|
||||
'date.uid as dateUid', 'date.date_start as dateStart', 'date.date_end as dateEnd', 'date.bus_pro_id as dateBusProId',
|
||||
'date.hotel as hotelUid', 'date.hotel_bus_pro_id as hotelBusProId', 'date.bus_included as dateBusIncluded',
|
||||
'date.skipass_included as dateSkipassIncluded', 'date.season as season',
|
||||
'date.uid as dateUid', 'date.date_start as dateStart', 'date.date_end as dateEnd',
|
||||
'date.bus_pro_id as dateBusProId', 'date.hotel as hotelUid', 'date.hotel_bus_pro_id as hotelBusProId',
|
||||
'date.bus_included as dateBusIncluded', 'date.skipass_included as dateSkipassIncluded',
|
||||
'date.season as season',
|
||||
'room.uid as roomUid', 'room.bus_pro_id as roomBusProId', 'room.name as roomName',
|
||||
'room.price as roomPrice', 'date.discount as roomDiscount', 'date.bus_price as busPrice',
|
||||
'room.services as roomOptionalServices', 'room.nights as roomNights', 'room.available as roomAvailable'
|
||||
@@ -205,22 +215,25 @@ class ProductRepository extends AbstractRepository
|
||||
}
|
||||
|
||||
if ($date !== null) {
|
||||
$query->andWhere($qb->expr()->eq(
|
||||
$qb->andWhere($qb->expr()->eq(
|
||||
'date.uid',
|
||||
$qb->createNamedParameter($date->getUid(), Connection::PARAM_INT))
|
||||
);
|
||||
}
|
||||
|
||||
$this->addFiltersettingsConditions($query, $filterSettings);
|
||||
$this->addFiltersettingsConditions($qb, $filterSettings);
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
return $qb
|
||||
->execute()
|
||||
->fetchAllAssociative()
|
||||
;
|
||||
}
|
||||
|
||||
public function getAvailableDates(Product $product, Hotel $hotel, array $filterSettings): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
$qb
|
||||
->select(
|
||||
'date.uid as dateUid', 'date.date_start as dateStart', 'date.date_end as dateEnd',
|
||||
'date.season as season', 'date.min_price as dateMinPrice', 'date.pseudo_price as datePseudoPrice',
|
||||
@@ -253,9 +266,12 @@ class ProductRepository extends AbstractRepository
|
||||
);
|
||||
}
|
||||
|
||||
$this->addFiltersettingsConditions($query, $filterSettings, true);
|
||||
$this->addFiltersettingsConditions($qb, $filterSettings, true);
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
return $qb
|
||||
->execute()
|
||||
->fetchAllAssociative()
|
||||
;
|
||||
}
|
||||
|
||||
public function hasDates(Product $product): bool
|
||||
@@ -281,15 +297,16 @@ class ProductRepository extends AbstractRepository
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
$qb
|
||||
->select(
|
||||
'date.bus_pro_id as dateBusProId', 'date.date_start as dateStart', 'date.date_end as dateEnd',
|
||||
'date.min_price as dateMinPrice', 'date.discount as dateDiscount', 'date.bus_price as busPrice',
|
||||
'date.nights as dateNights', 'date.bus_included as dateBusIncluded', 'date.services_included as dateServicesIncluded',
|
||||
'date.services_general as dateServicesGeneral', 'date.skipass_included as dateSkipassIncluded',
|
||||
'date.bus_pro_id as dateBusProId', 'date.hotel_bus_pro_id as hotelBusProId', 'date.pickups as pickups',
|
||||
'room.uid as roomUid', 'room.bus_pro_id as roomBusProId', 'room.code as roomCode', 'room.name as roomName',
|
||||
'room.price as roomPrice', 'room.pax as roomPax', 'date.discount as roomDiscount', 'date.bus_price as busPrice',
|
||||
'date.nights as dateNights', 'date.bus_included as dateBusIncluded', 'date.bus_price as busPrice',
|
||||
'date.services_included as dateServicesIncluded', 'date.services_general as dateServicesGeneral',
|
||||
'date.skipass_included as dateSkipassIncluded', 'date.bus_pro_id as dateBusProId',
|
||||
'date.discount as roomDiscount', 'date.hotel_bus_pro_id as hotelBusProId', 'date.pickups as pickups',
|
||||
'room.uid as roomUid', 'room.bus_pro_id as roomBusProId', 'room.code as roomCode',
|
||||
'room.name as roomName', 'room.price as roomPrice', 'room.pax as roomPax',
|
||||
'room.services as roomOptionalServices', 'room.nights as roomNights', 'room.available as roomAvailable'
|
||||
)
|
||||
->from('tx_epproducts_domain_model_date', 'date')
|
||||
@@ -307,21 +324,25 @@ class ProductRepository extends AbstractRepository
|
||||
)
|
||||
;
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
return $qb
|
||||
->execute()
|
||||
->fetchAllAssociative()
|
||||
;
|
||||
}
|
||||
|
||||
public function getEventPriceTable(Product $product): array
|
||||
{
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$query = $qb
|
||||
$qb
|
||||
->select(
|
||||
'date.bus_pro_id as dateBusProId', 'date.hotel_bus_pro_id as hotelBusProId', 'date.date_end as dateEnd',
|
||||
'date.hotel as hotelUid', 'date.hotel_name as hotelName', 'date.hotel_header_title as hotelTitle',
|
||||
'date.hotel_category as hotelCategory',
|
||||
'date.bus_pro_id as dateBusProId', 'date.hotel_bus_pro_id as hotelBusProId',
|
||||
'date.date_end as dateEnd', 'date.hotel as hotelUid', 'date.hotel_name as hotelName',
|
||||
'date.hotel_header_title as hotelTitle', 'date.hotel_category as hotelCategory',
|
||||
'room.pax as roomPax', 'room.price as roomPrice', 'room.available as available',
|
||||
'room.pax as roomPax', 'room.price as roomPrice', 'room.available as available',
|
||||
'hotel.detail_page as hotelDetailPageUid', 'hotel.short_name as hotelShortName', 'hotel.show_as_teaser as hotelShowAsTeaser'
|
||||
'hotel.detail_page as hotelDetailPageUid', 'hotel.short_name as hotelShortName',
|
||||
'hotel.show_as_teaser as hotelShowAsTeaser'
|
||||
)
|
||||
->from('tx_epproducts_domain_model_date', 'date')
|
||||
->innerJoin('date', 'tx_epproducts_domain_model_room', 'room', 'room.date = date.uid')
|
||||
@@ -332,7 +353,10 @@ class ProductRepository extends AbstractRepository
|
||||
)
|
||||
;
|
||||
|
||||
return $query->execute()->fetchAllAssociative();
|
||||
return $qb
|
||||
->execute()
|
||||
->fetchAllAssociative()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-34
@@ -2,31 +2,6 @@
|
||||
|
||||
namespace EP\EpProducts\Traits;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2016 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpProducts\Service\FilterService;
|
||||
use EP\EpProducts\Service\SearchResultService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
@@ -35,10 +10,7 @@ use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
trait RequestArgumentTypeConversionTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* Converts array to searchparams object
|
||||
*/
|
||||
public function processSearchParamsArgument()
|
||||
public function processSearchParamsArgument(): void
|
||||
{
|
||||
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
|
||||
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
@@ -58,11 +30,7 @@ trait RequestArgumentTypeConversionTrait
|
||||
$this->request->setArgument('searchParams', $searchParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts urlencoded json or array to filtersettings object
|
||||
* @param array $forcedConceptUids
|
||||
*/
|
||||
public function processFilterSettingsArgument(array $forcedConceptUids = [])
|
||||
public function processFilterSettingsArgument(array $forcedConceptUids = []): void
|
||||
{
|
||||
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */
|
||||
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
|
||||
Reference in New Issue
Block a user