From f1cbba74c1a6395312369899967fdf9e637040e3 Mon Sep 17 00:00:00 2001 From: Dirk Date: Wed, 14 Aug 2019 17:22:01 +0200 Subject: [PATCH] Implement date search --- Classes/Controller/DateController.php | 114 +++++++++++--- Classes/Controller/EventController.php | 15 ++ Classes/Domain/Model/Date.php | 14 +- Classes/Domain/Model/Dto/DateDemand.php | 73 ++++++++- Classes/Domain/Repository/DateRepository.php | 91 +++++------ Classes/Domain/Repository/EventRepository.php | 12 ++ Configuration/FlexForms/Pi1.xml | 37 +++-- .../Private/Partials/Date/ListTable.html | 2 + .../Private/Partials/Date/SearchForm.html | 55 +++++++ .../Private/Partials/Event/SearchForm.html | 14 ++ .../Private/Partials/Events/Properties.html | 148 ------------------ Resources/Private/Templates/Date/Search.html | 42 +++++ Resources/Private/Templates/Event/Search.html | 27 ++++ ext_localconf.php | 8 +- 14 files changed, 386 insertions(+), 266 deletions(-) create mode 100644 Resources/Private/Partials/Date/SearchForm.html create mode 100644 Resources/Private/Partials/Event/SearchForm.html delete mode 100644 Resources/Private/Partials/Events/Properties.html create mode 100644 Resources/Private/Templates/Date/Search.html create mode 100644 Resources/Private/Templates/Event/Search.html diff --git a/Classes/Controller/DateController.php b/Classes/Controller/DateController.php index 73a2f1a..f4d36f0 100644 --- a/Classes/Controller/DateController.php +++ b/Classes/Controller/DateController.php @@ -1,21 +1,9 @@ - * - ***/ - use Wrm\Events\Domain\Model\Dto\DateDemand; -use Wrm\Events\Domain\Model\Date; use Wrm\Events\Domain\Repository\DateRepository; +use Wrm\Events\Domain\Repository\RegionRepository; use TYPO3\CMS\Core\Database\QueryGenerator; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; @@ -29,7 +17,12 @@ class DateController extends ActionController /** * @var dateRepository */ - protected $dateRepository = null; + protected $dateRepository; + + /** + * @var regionRepository + */ + protected $regionRepository; /** * @var QueryGenerator @@ -41,11 +34,15 @@ class DateController extends ActionController */ protected $pluginSettings; - /** + /* + * @param RegionRepository $regionRepository * @param DateRepository $dateRepository */ - public function injectDateRepository(DateRepository $dateRepository) - { + public function __construct( + RegionRepository $regionRepository, + DateRepository $dateRepository + ) { + $this->regionRepository = $regionRepository; $this->dateRepository = $dateRepository; } @@ -71,6 +68,49 @@ class DateController extends ActionController $this->view->assign('dates', $dates); } + /** + * @return void + */ + public function searchAction() + { + + $searchword = null; + $regions = null; + $selRegion = null; + $dates = null; + $start = null; + $end = null; + + if ($this->request->hasArgument('searchword') && $this->request->getArgument('searchword') != '') { + $searchword = $this->request->getArgument('searchword'); + } + + if ($this->request->hasArgument('region') && $this->request->getArgument('region') != '') { + $selRegion = $this->request->getArgument('region'); + } + + if ($this->request->hasArgument('start') && $this->request->getArgument('start') != '') { + $start = date( "Y-m-d", strtotime( $this->request->getArgument('start'))); + } + + if ($this->request->hasArgument('end') && $this->request->getArgument('end') != '') { + $end = date( "Y-m-d", strtotime( $this->request->getArgument('end'))); + } + + $demand = $this->createDemandFromSearch(); + $dates = $this->dateRepository->findByDemand($demand); + + $regions = $this->regionRepository->findAll(); + + $this->view->assign('searchword', $searchword); + $this->view->assign('regions', $regions); + $this->view->assign('selRegion', $selRegion); + $this->view->assign('dates', $dates); + $this->view->assign('start', $start); + $this->view->assign('end', $end); + + } + /** * action teaser * @@ -96,25 +136,53 @@ class DateController extends ActionController /** * @return DateDemand */ - protected function createDemandFromSettings(): DateDemand { $demand = $this->objectManager->get(DateDemand::class); $demand->setRegion((string)$this->settings['region']); - $demand->setCategories((string)$this->settings['categories']); $categoryCombination = (int)$this->settings['categoryCombination'] === 1 ? 'or' : 'and'; - $demand->setCategoryCombination($categoryCombination); - $demand->setIncludeSubCategories((bool)$this->settings['includeSubcategories']); + $demand->setSortBy((string)$this->settings['sortByDate']); + $demand->setSortOrder((string)$this->settings['sortOrder']); + $demand->setHighlight((int)$this->settings['highlight']); + + if (!empty($this->settings['limit'])) { + $demand->setLimit($this->settings['limit']); + } + + return $demand; + } + + /** + * @return DateDemand + */ + protected function createDemandFromSearch(): DateDemand + { + $demand = $this->objectManager->get(DateDemand::class); + + if ($this->request->hasArgument('region') && $this->request->getArgument('region') != '') + $demand->setRegion((string)$this->request->getArgument('region')); + + if ($this->request->hasArgument('highlight') && $this->request->hasArgument('highlight') != '') + $demand->setHighlight((int)$this->settings['highlight']); + + if ($this->request->hasArgument('searchword') && $this->request->getArgument('searchword') != '') + $demand->setSearchword((string)$this->request->getArgument('searchword')); + + if ($this->request->hasArgument('start') && $this->request->getArgument('start') != '') { + $demand->setStart(date( "Y-m-d", strtotime( $this->request->getArgument('start')))); + } + + if ($this->request->hasArgument('end') && $this->request->getArgument('end') != '') { + $demand->setEnd(date( "Y-m-d", strtotime( $this->request->getArgument('end')))); + } $demand->setSortBy((string)$this->settings['sortByDate']); $demand->setSortOrder((string)$this->settings['sortOrder']); - $demand->setHighlight((string)$this->settings['highlight']); - if (!empty($this->settings['limit'])) { $demand->setLimit($this->settings['limit']); } diff --git a/Classes/Controller/EventController.php b/Classes/Controller/EventController.php index def1182..805b2a4 100644 --- a/Classes/Controller/EventController.php +++ b/Classes/Controller/EventController.php @@ -84,6 +84,21 @@ class EventController extends ActionController $this->view->assign('events', $events); } + /** + * @param string $search + */ + public function searchAction(): void + { + $search = ''; + if ($this->request->hasArgument('search')) { + $search = $this->request->getArgument('search'); + } + + $this->view->assign('search', $search); + $this->view->assign('events', $this->eventRepository->findSearchWord($search)); + + } + /** * @return EventDemand */ diff --git a/Classes/Domain/Model/Date.php b/Classes/Domain/Model/Date.php index cd059db..9203b96 100644 --- a/Classes/Domain/Model/Date.php +++ b/Classes/Domain/Model/Date.php @@ -2,18 +2,6 @@ namespace Wrm\Events\Domain\Model; -/*** - * - * This file is part of the "DD Events" Extension for TYPO3 CMS. - * - * For the full copyright and license information, please read the - * LICENSE.txt file that was distributed with this source code. - * - * (c) 2019 Dirk Koritnik - * - ***/ - - /** * Date */ @@ -28,7 +16,7 @@ class Date extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity /** * @var \DateTime */ - protected $end = ''; + protected $end = null; /** * @var \Wrm\Events\Domain\Model\Event diff --git a/Classes/Domain/Model/Dto/DateDemand.php b/Classes/Domain/Model/Dto/DateDemand.php index 4b4597f..0f0a538 100644 --- a/Classes/Domain/Model/Dto/DateDemand.php +++ b/Classes/Domain/Model/Dto/DateDemand.php @@ -32,18 +32,33 @@ class DateDemand { /** * @var string */ - protected $region = null; + protected $region = ''; /** - * @var string + * @var bool */ - protected $highlight = null; + protected $highlight = 0; /** * @var string */ protected $limit = ''; + /** + * @var string + */ + protected $start = ''; + + /** + * @var string + */ + protected $end = ''; + + /** + * @var string + */ + protected $searchword = ''; + /** * @return string */ @@ -141,15 +156,15 @@ class DateDemand { } /** - * @return string + * @return bool */ - public function getHighlight(): string + public function getHighlight(): bool { return $this->highlight; } /** - * @param string $hightlight + * @param bool $highlight */ public function setHighlight(string $highlight): void { @@ -172,6 +187,52 @@ class DateDemand { $this->limit = $limit; } + /** + * @return string + */ + public function getSearchword(): string + { + return $this->searchword; + } + /** + * @param string $searchword + */ + public function setSearchword(string $searchword): void + { + $this->searchword = $searchword; + } + + /** + * @return string + */ + public function getStart(): string + { + return $this->start; + } + + /** + * @param string $start + */ + public function setStart(string $start): void + { + $this->start = $start; + } + + /** + * @return string + */ + public function getEnd(): string + { + return $this->end; + } + + /** + * @param string $end + */ + public function setEnd(string $end): void + { + $this->end = $end; + } } \ No newline at end of file diff --git a/Classes/Domain/Repository/DateRepository.php b/Classes/Domain/Repository/DateRepository.php index 611bef5..78f080b 100644 --- a/Classes/Domain/Repository/DateRepository.php +++ b/Classes/Domain/Repository/DateRepository.php @@ -1,21 +1,7 @@ createQuery(); - //$query->getQuerySettings()->setRespectStoragePage(false); - $query->matching( $query->in('uid', $uids) ); - - //return $this->orderByField($query->execute(), $uids); - return $query->execute(); } @@ -56,11 +34,11 @@ class DateRepository extends \TYPO3\CMS\Extbase\Persistence\Repository public function findByDemand(DateDemand $demand) { $query = $this->createDemandQuery($demand); + return $query->execute(); // For testing purposes // $query = $this->createDemandQueryViaBuilder($demand); - - return $query->execute(); + //return $query->execute()->fetchAll(); } /** @@ -71,9 +49,7 @@ class DateRepository extends \TYPO3\CMS\Extbase\Persistence\Repository protected function createDemandQuery(DateDemand $demand): QueryInterface { $query = $this->createQuery(); - $constraints = []; - $categories = $demand->getCategories(); if ($categories) { @@ -89,25 +65,37 @@ class DateRepository extends \TYPO3\CMS\Extbase\Persistence\Repository $constraints['region'] = $query->equals('event.region', $demand->getRegion()); } - if ($demand->getRegion() !== null) { + if ($demand->getHighlight() !== FALSE) { $constraints['highlight'] = $query->equals('event.highlight', $demand->getHighlight()); } + if ($demand->getSearchword() !== '') { + $constraints['searchword'] = $query->logicalOr( + [ + $query->like('event.title', '%' . $demand->getSearchword() . '%'), + $query->like('event.teaser', '%' . $demand->getSearchword() . '%') + ] + ); + } + + if ($demand->getStart() !== '' && $demand->getEnd() != '') { + $constraints['daterange'] = $query->logicalAnd( + [ + $query->greaterThanOrEqual('start', $demand->getStart()), + $query->lessThanOrEqual('start', $demand->getEnd()) + ] + ); + } + if ($demand->getLimit() !== '') { $query->setLimit((int) $demand->getLimit()); } - if (!empty($constraints)) { $query->matching($query->logicalAnd($constraints)); } - - $sortBy = $demand->getSortBy(); - if ($sortBy && $sortBy !== 'singleSelection' && $sortBy !== 'default') { - $order = strtolower($demand->getSortOrder()) === 'desc' ? QueryInterface::ORDER_DESCENDING : QueryInterface::ORDER_ASCENDING; - $query->setOrderings([$sortBy => $order]); - } + $query->setOrderings([$demand->getSortBy() => $demand->getSortOrder()]); return $query; } @@ -140,37 +128,30 @@ class DateRepository extends \TYPO3\CMS\Extbase\Persistence\Repository } /** - * @param DateDemand - * @return $statement - * @throws InvalidQueryException + * findSearchWord with Query Builder + * @param $search */ - - protected function createDemandQueryViaBuilder(DateDemand $demand) { - - //$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_Events_domain_model_date'); + public function findSearchWord($search) + { $connection = GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable('tx_Events_domain_model_date'); + ->getConnectionForTable('tx_events_domain_model_date'); $queryBuilder = $connection->createQueryBuilder(); $statement = $queryBuilder - ->select('tx_Events_domain_model_date.start', 'tx_Events_domain_model_date.end', 'tx_Events_domain_model_date.event') - ->from('tx_Events_domain_model_date') + ->select('*') + ->from('tx_events_domain_model_date') ->join( - 'tx_Events_domain_model_date', - 'tx_Events_domain_model_event', + 'tx_events_domain_model_date', + 'tx_events_domain_model_event', 'event', - $queryBuilder->expr()->eq('tx_Events_domain_model_date.event', $queryBuilder->quoteIdentifier('event.uid')) + $queryBuilder->expr()->eq('tx_events_domain_model_date.event', $queryBuilder->quoteIdentifier('event.uid')) )->where( - $queryBuilder->expr()->eq('event.title', $queryBuilder->createNamedParameter('Bachführung')) - ); + $queryBuilder->expr()->like('event.title', $queryBuilder->createNamedParameter('%' . $search . '%')) + )->orderBy('tx_events_domain_model_date.start'); - if ($demand->getLimit() !== '') { - $statement->setMaxResults((int) $demand->getLimit()); - } - - return $statement; + return $statement->execute()->fetchAll(); } } \ No newline at end of file diff --git a/Classes/Domain/Repository/EventRepository.php b/Classes/Domain/Repository/EventRepository.php index 3f0c9f3..c20a99e 100644 --- a/Classes/Domain/Repository/EventRepository.php +++ b/Classes/Domain/Repository/EventRepository.php @@ -131,4 +131,16 @@ class EventRepository extends \TYPO3\CMS\Extbase\Persistence\Repository return $constraints; } + + public function findSearchWord($search) + { + $query = $this->createQuery(); + $query->matching( + $query->like('title', '%' . $search . '%') + ); + $query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]); + $query->setLimit(20); + return $query->execute(); + } + } \ No newline at end of file diff --git a/Configuration/FlexForms/Pi1.xml b/Configuration/FlexForms/Pi1.xml index fdfb0bd..bb4db2a 100644 --- a/Configuration/FlexForms/Pi1.xml +++ b/Configuration/FlexForms/Pi1.xml @@ -41,6 +41,16 @@ Date->show + + Event Search + Event->search + + + + Date Search + Date->search + + @@ -55,21 +65,14 @@ select - Default - default - - Title title - + Region region - @@ -78,26 +81,24 @@ 1 - FIELD:switchableControllerActions:=:Date->list + + + FIELD:switchableControllerActions:=:Date->list + FIELD:switchableControllerActions:=:Date->search + + select - Default - default - - Start start - + End end - @@ -110,6 +111,7 @@ FIELD:switchableControllerActions:=:Event->list FIELD:switchableControllerActions:=:Date->list + FIELD:switchableControllerActions:=:Date->search @@ -141,6 +143,7 @@ FIELD:switchableControllerActions:=:Event->list FIELD:switchableControllerActions:=:Date->list + FIELD:switchableControllerActions:=:Date->search diff --git a/Resources/Private/Partials/Date/ListTable.html b/Resources/Private/Partials/Date/ListTable.html index 5c1463b..2099e60 100644 --- a/Resources/Private/Partials/Date/ListTable.html +++ b/Resources/Private/Partials/Date/ListTable.html @@ -1,5 +1,6 @@ +
@@ -34,4 +35,5 @@
+ \ No newline at end of file diff --git a/Resources/Private/Partials/Date/SearchForm.html b/Resources/Private/Partials/Date/SearchForm.html new file mode 100644 index 0000000..2d8f8c5 --- /dev/null +++ b/Resources/Private/Partials/Date/SearchForm.html @@ -0,0 +1,55 @@ + +
+
+ + + + +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/Resources/Private/Partials/Event/SearchForm.html b/Resources/Private/Partials/Event/SearchForm.html new file mode 100644 index 0000000..8488d62 --- /dev/null +++ b/Resources/Private/Partials/Event/SearchForm.html @@ -0,0 +1,14 @@ + + +
+
+
+ +
+ + +
+
+
+
+
diff --git a/Resources/Private/Partials/Events/Properties.html b/Resources/Private/Partials/Events/Properties.html deleted file mode 100644 index f7bf0fd..0000000 --- a/Resources/Private/Partials/Events/Properties.html +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - {events.globalId} -
- - - {events.title} -
- - - {events.teaser} -
- - - {events.details} -
- - - {events.priceInfo} -
- - - {events.street} -
- - - {events.district} -
- - - {events.city} -
- - - {events.zip} -
- - - {events.web} -
- - - {events.booking} -
- - - {events.ticket} -
- - - {events.facebook} -
- - - {events.youtube} -
- - - {events.latitude} -
- - - {events.longitude} -
- - - -
- - - {events.slug} -
- \ No newline at end of file diff --git a/Resources/Private/Templates/Date/Search.html b/Resources/Private/Templates/Date/Search.html new file mode 100644 index 0000000..ad64c8c --- /dev/null +++ b/Resources/Private/Templates/Date/Search.html @@ -0,0 +1,42 @@ + + + + +
+ + + +
+
+ {date.start}
+ {date.start}
+ {date.start}
+ {date.event.region.title}
+
+
+ + + Hightlight + + +

{date.event.title}

+

{date.event.teaser}

+ {date.event.details} +
+
+ + + + + + + + Dummy + + +
+
+
+
+ + \ No newline at end of file diff --git a/Resources/Private/Templates/Event/Search.html b/Resources/Private/Templates/Event/Search.html new file mode 100644 index 0000000..73dd4af --- /dev/null +++ b/Resources/Private/Templates/Event/Search.html @@ -0,0 +1,27 @@ + + +
+ +
+ +
+
+ {event.region.title} +

{event.title}

+

{event.teaser}

+
+
+
+
+
\ No newline at end of file diff --git a/ext_localconf.php b/ext_localconf.php index 1960708..59912b5 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -9,12 +9,12 @@ call_user_func( 'Wrm.Events', 'Pi1', [ - 'Event' => 'teaser, list, show', - 'Date' => 'teaser, list, show' + 'Event' => 'teaser, list, show, search', + 'Date' => 'teaser, list, show, search' ], [ - 'Event' => 'teaser, list, show', - 'Date' => 'teaser, list, show' + 'Event' => 'teaser, list, show, search', + 'Date' => 'teaser, list, show, search' ] );