Make non-bookable dates independent from typo3 uids

This commit is contained in:
Björn Fromme
2020-03-13 12:57:54 +01:00
parent d8862feb7d
commit 0c29c75744
6 changed files with 69 additions and 48 deletions
@@ -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;
}
}
@@ -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
@@ -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']);
@@ -0,0 +1,48 @@
<?php
namespace EP\EpProducts\UserFunc;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class TcaProcFunc
{
public function getDateItemsForProduct($config)
{
$productUid = $config['row']['uid'];
if (!is_numeric($productUid)) {
return $config;
}
$items = [];
/** @var ConnectionPool $connectionPool */
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$qb = $connectionPool->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;
}
}
@@ -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',
]
]
],
],
];
@@ -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'
#