From 0c29c757447945a76ad418b06f5b180e35cf47ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Fri, 13 Mar 2020 12:57:54 +0100 Subject: [PATCH 1/2] Make non-bookable dates independent from typo3 uids --- .../Classes/Domain/Model/Product.php | 13 +++++ .../Domain/Repository/ProductRepository.php | 25 ---------- .../Classes/Service/DateService.php | 9 ++-- .../Classes/UserFunc/TcaProcFunc.php | 48 +++++++++++++++++++ .../tx_epproducts_domain_model_product.php | 6 +-- .../typo3conf/ext/ep_products/ext_tables.sql | 16 +------ 6 files changed, 69 insertions(+), 48 deletions(-) create mode 100644 public/typo3conf/ext/ep_products/Classes/UserFunc/TcaProcFunc.php diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php index 8dfc59ee..8a176bd3 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php @@ -260,6 +260,11 @@ class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements */ protected $badge; + /** + * @var string + */ + protected $nonBookableDateUids; + public function __construct() { $this->initStorageObjects(); @@ -1052,4 +1057,12 @@ class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements $this->badge = $badge; } + /** + * @return string + */ + public function getNonBookableDateUids() + { + return $this->nonBookableDateUids; + } + } diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php index 79ef964e..453a3876 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Repository/ProductRepository.php @@ -248,31 +248,6 @@ class ProductRepository extends AbstractRepository return $query->execute()->fetchAll(); } - /** - * Returns uids of date records that are selected to be non bookable - * via backend - * - * @param Product $product - * @return array - */ - public function getNonBookableDateUids(Product $product) - { - $qb = $this->getDbConnection()->createQueryBuilder(); - - $result = $qb - ->select('uid_foreign as uid') - ->from('tx_epproducts_product_date_mm') - ->where('uid_local = :product') - ->setParameter('product', $product->getUid()) - ->execute() - ->fetchAll() - ; - - return array_map(function ($row) { - return $row['uid']; - }, $result); - } - /** * @param Product $product * @param Hotel $hotel diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php index 5b7e45d0..9de74d32 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php @@ -35,6 +35,7 @@ use EP\EpProducts\Domain\Repository\ProductRepository; use EP\EpProducts\Utility\BookingUrlUtility; use Symfony\Component\OptionsResolver\OptionsResolver; use TYPO3\CMS\Core\SingletonInterface; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; class DateService implements SingletonInterface @@ -102,7 +103,7 @@ class DateService implements SingletonInterface $filterSettings = $this->filterService->getDefaultFilterSettings(); } - $nonBookableDateUids = $this->productRepository->getNonBookableDateUids($product); + $nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDateUids(), true); return $this->preprocessPriceTable([ 'priceTableData' => $this->productRepository->getPricetable($product, $hotel, $filterSettings, $date), @@ -148,7 +149,7 @@ class DateService implements SingletonInterface $filterSettings = $this->filterService->getDefaultFilterSettings(); } - $nonBookableDateUids = $this->productRepository->getNonBookableDateUids($product); + $nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDateUids(), true); $dateTableData = $this->productRepository->getAvailableDates( $product, @@ -289,7 +290,7 @@ class DateService implements SingletonInterface foreach ($priceTableData as $row) { - $isHideBookingButton = $resolvedOptions['isHideBookingButton'] || in_array($row['dateUid'], $nonBookableDateUids, false); + $isHideBookingButton = $resolvedOptions['isHideBookingButton'] || in_array($row['dateBusProId'], $nonBookableDateUids, false); $dateStart = new \DateTime($row['dateStart']); $dateEnd = new \DateTime($row['dateEnd']); @@ -349,7 +350,7 @@ class DateService implements SingletonInterface foreach ($dateTableData as $row) { - $isHideBookingButton = $resolvedOptions['isHideBookingButton'] || in_array($row['dateUid'], $nonBookableDateUids, false); + $isHideBookingButton = $resolvedOptions['isHideBookingButton'] || in_array($row['dateBusProId'], $nonBookableDateUids, false); $dateStart = new \DateTime($row['dateStart']); $dateEnd = new \DateTime($row['dateEnd']); diff --git a/public/typo3conf/ext/ep_products/Classes/UserFunc/TcaProcFunc.php b/public/typo3conf/ext/ep_products/Classes/UserFunc/TcaProcFunc.php new file mode 100644 index 00000000..2932e6f6 --- /dev/null +++ b/public/typo3conf/ext/ep_products/Classes/UserFunc/TcaProcFunc.php @@ -0,0 +1,48 @@ +getQueryBuilderForTable('tx_epproducts_domain_model_date'); + + $result = $qb + ->select('date_start', 'date_end', 'bus_pro_id') + ->from('tx_epproducts_domain_model_date') + ->where($qb->expr()->eq('product', $productUid)) + ->orderBy('date_start') + ->execute() + ->fetchAll() + ; + + foreach ($result as $row) { + $dateStart = new \DateTime($row['date_start']); + $dateEnd = new \DateTime($row['date_end']); + + $items[] = [ + sprintf('%s - %s', $dateStart->format('d.m.Y'), $dateEnd->format('d.m.Y')), + $row['bus_pro_id'], + ]; + } + + $config['items'] = $items; + + return $config; + } +} \ No newline at end of file diff --git a/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php b/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php index bfbed901..c5b062b4 100644 --- a/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php +++ b/public/typo3conf/ext/ep_products/Configuration/TCA/tx_epproducts_domain_model_product.php @@ -838,10 +838,8 @@ return [ 'config' => [ 'type' => 'select', 'renderType' => 'selectMultipleSideBySide', - 'foreign_table' => 'tx_epproducts_domain_model_date', - 'foreign_table_where' => 'AND tx_epproducts_domain_model_date.product=###THIS_UID### ORDER BY tx_epproducts_domain_model_date.date_start', - 'MM' => 'tx_epproducts_product_date_mm', + 'itemsProcFunc' => \EP\EpProducts\UserFunc\TcaProcFunc::class.'->getDateItemsForProduct', ] - ] + ], ], ]; diff --git a/public/typo3conf/ext/ep_products/ext_tables.sql b/public/typo3conf/ext/ep_products/ext_tables.sql index f806b43f..69bbfb0c 100644 --- a/public/typo3conf/ext/ep_products/ext_tables.sql +++ b/public/typo3conf/ext/ep_products/ext_tables.sql @@ -59,7 +59,7 @@ CREATE TABLE tx_epproducts_domain_model_product video varchar(255) DEFAULT '' NOT NULL, banner int(11) unsigned NOT NULL default '0', badge int(11) unsigned NOT NULL default '0', - non_bookable_dates int(11) unsigned NOT NULL default '0', + non_bookable_dates varchar(255) DEFAULT '' NOT NULL, tstamp int(11) unsigned DEFAULT '0' NOT NULL, crdate int(11) unsigned DEFAULT '0' NOT NULL, cruser_id int(11) unsigned DEFAULT '0' NOT NULL, @@ -1329,20 +1329,6 @@ CREATE TABLE tx_epproducts_product_region_mm KEY uid_foreign (uid_foreign) ); -# -# Table structure for table 'tx_epproducts_product_date_mm' -# -CREATE TABLE tx_epproducts_product_date_mm -( - uid_local int(11) unsigned DEFAULT '0' NOT NULL, - uid_foreign int(11) unsigned DEFAULT '0' NOT NULL, - sorting int(11) unsigned DEFAULT '0' NOT NULL, - sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL, - - KEY uid_local (uid_local), - KEY uid_foreign (uid_foreign) -); - # # Table structure for table 'tx_epproducts_hotel_teammember_mm' # From 2f70c458860f940d4dc571df7d8c47fbd10ec345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Fri, 13 Mar 2020 13:29:53 +0100 Subject: [PATCH 2/2] Fix incorrect property name --- .../ext/ep_products/Classes/Domain/Model/Product.php | 6 +++--- .../ext/ep_products/Classes/Service/DateService.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php index 8a176bd3..29a8e808 100644 --- a/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php +++ b/public/typo3conf/ext/ep_products/Classes/Domain/Model/Product.php @@ -263,7 +263,7 @@ class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements /** * @var string */ - protected $nonBookableDateUids; + protected $nonBookableDates; public function __construct() { @@ -1060,9 +1060,9 @@ class Product extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity implements /** * @return string */ - public function getNonBookableDateUids() + public function getNonBookableDates() { - return $this->nonBookableDateUids; + return $this->nonBookableDates; } } diff --git a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php index 9de74d32..dbf2628e 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/DateService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/DateService.php @@ -103,7 +103,7 @@ class DateService implements SingletonInterface $filterSettings = $this->filterService->getDefaultFilterSettings(); } - $nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDateUids(), true); + $nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDates(), true); return $this->preprocessPriceTable([ 'priceTableData' => $this->productRepository->getPricetable($product, $hotel, $filterSettings, $date), @@ -149,7 +149,7 @@ class DateService implements SingletonInterface $filterSettings = $this->filterService->getDefaultFilterSettings(); } - $nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDateUids(), true); + $nonBookableDateUids = GeneralUtility::trimExplode(',', $product->getNonBookableDates(), true); $dateTableData = $this->productRepository->getAvailableDates( $product,