diff --git a/Classes/Controller/EventController.php b/Classes/Controller/EventController.php
index 9c2e591..fae6ed2 100644
--- a/Classes/Controller/EventController.php
+++ b/Classes/Controller/EventController.php
@@ -3,6 +3,7 @@
namespace Wrm\Events\Controller;
use TYPO3\CMS\Core\Database\QueryGenerator;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
@@ -122,6 +123,7 @@ class EventController extends ActionController
protected function createDemandFromSettings(): EventDemand
{
+ /** @var EventDemand $demand */
$demand = $this->objectManager->get(EventDemand::class);
$demand->setRegion((string)$this->settings['region']);
@@ -138,6 +140,8 @@ class EventController extends ActionController
$demand->setHighlight((bool)$this->settings['highlight']);
+ $demand->setRecordUids(GeneralUtility::intExplode(',', $this->settings['selectedRecords'], true));
+
if (!empty($this->settings['limit'])) {
$demand->setLimit($this->settings['limit']);
}
diff --git a/Classes/Domain/Model/Dto/EventDemand.php b/Classes/Domain/Model/Dto/EventDemand.php
index eb74e00..f07f843 100644
--- a/Classes/Domain/Model/Dto/EventDemand.php
+++ b/Classes/Domain/Model/Dto/EventDemand.php
@@ -45,6 +45,11 @@ class EventDemand
*/
protected $limit = '';
+ /**
+ * @var array
+ */
+ protected $recordUids = [];
+
/**
* @return string
*/
@@ -172,4 +177,20 @@ class EventDemand
{
$this->limit = $limit;
}
+
+ /**
+ * @return array
+ */
+ public function getRecordUids(): array
+ {
+ return $this->recordUids;
+ }
+
+ /**
+ * @param array $recordUids
+ */
+ public function setRecordUids(array $recordUids): void
+ {
+ $this->recordUids = $recordUids;
+ }
}
diff --git a/Classes/Domain/Repository/EventRepository.php b/Classes/Domain/Repository/EventRepository.php
index ebcfcc2..4b12613 100644
--- a/Classes/Domain/Repository/EventRepository.php
+++ b/Classes/Domain/Repository/EventRepository.php
@@ -20,6 +20,7 @@ use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
use Wrm\Events\Domain\Model\Dto\EventDemand;
+use Wrm\Events\Domain\Model\Event;
use Wrm\Events\Service\CategoryService;
class EventRepository extends Repository
@@ -56,6 +57,11 @@ class EventRepository extends Repository
public function findByDemand(EventDemand $demand)
{
$query = $this->createDemandQuery($demand);
+
+ if ($demand->getRecordUids() !== [] && $demand->getSortBy() === 'default') {
+ return $this->sortByDemand($query, $demand);
+ }
+
return $query->execute();
}
@@ -70,7 +76,8 @@ class EventRepository extends Repository
// sorting
$sortBy = $demand->getSortBy();
- if ($sortBy && $sortBy !== 'singleSelection' && $sortBy !== 'default') {
+ $sortingsToIgnore = ['singleSelection', 'default'];
+ if ($sortBy && in_array($sortBy, $sortingsToIgnore) === false) {
$order = strtolower($demand->getSortOrder()) === 'desc' ? QueryInterface::ORDER_DESCENDING : QueryInterface::ORDER_ASCENDING;
$query->setOrderings([$sortBy => $order]);
}
@@ -88,6 +95,10 @@ class EventRepository extends Repository
}
}
+ if ($demand->getRecordUids() !== []) {
+ $constraints['recordUids'] = $query->in('uid', $demand->getRecordUids());
+ }
+
if ($demand->getRegion() !== '') {
$constraints['region'] = $query->equals('region', $demand->getRegion());
}
@@ -133,6 +144,20 @@ class EventRepository extends Repository
return $constraints;
}
+ private function sortByDemand(QueryInterface $query, EventDemand $demand): array
+ {
+ $result = $query->execute()->toArray();
+ $expectedSorting = $demand->getRecordUids();
+
+ usort($result, function (Event $eventA, Event $eventB) use ($expectedSorting) {
+ $positionOfA = array_search($eventA->getUid(), $expectedSorting);
+ $positionOfB = array_search($eventB->getUid(), $expectedSorting);
+
+ return $positionOfA <=> $positionOfB;
+ });
+
+ return $result;
+ }
public function findSearchWord($search)
{
diff --git a/Configuration/FlexForms/Selected.xml b/Configuration/FlexForms/Selected.xml
new file mode 100644
index 0000000..d4a590e
--- /dev/null
+++ b/Configuration/FlexForms/Selected.xml
@@ -0,0 +1,24 @@
+
+
+
+
+ array
+
+
+
+ 1
+
+
+ group
+ db
+ tx_events_domain_model_event
+ 1
+ 1
+
+
+
+
+
+
+
+
diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php
index eda0c55..b0fb92b 100644
--- a/Configuration/TCA/Overrides/tt_content.php
+++ b/Configuration/TCA/Overrides/tt_content.php
@@ -69,4 +69,20 @@ call_user_func(function () {
);
+ /* Event Selected Plugin */
+
+ \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
+ 'Events',
+ 'Selected',
+ 'Events: Show selected',
+ 'EXT:events/Resources/Public/Icons/user_plugin_events.svg'
+ );
+
+ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['events_selected'] = 'pi_flexform';
+
+ \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
+ 'events_selected',
+ 'FILE:EXT:events/Configuration/FlexForms/Selected.xml'
+ );
+
});
diff --git a/Resources/Private/Language/de.locallang_db.xlf b/Resources/Private/Language/de.locallang_db.xlf
index 468831a..53d8dbd 100644
--- a/Resources/Private/Language/de.locallang_db.xlf
+++ b/Resources/Private/Language/de.locallang_db.xlf
@@ -1,16 +1,20 @@
-
-
-
-
-
- Veranstaltungen
-
-
-
- Veranstaltungs Modul
-
-
-
+
+
+
+
+
+ Veranstaltungen
+
+
+
+ Veranstaltungs Modul
+
+
+
+ Anzuzeigende Veranstaltungen
+
+
+
diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf
index 9462876..03080c4 100644
--- a/Resources/Private/Language/locallang_db.xlf
+++ b/Resources/Private/Language/locallang_db.xlf
@@ -1,14 +1,17 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ext_localconf.php b/ext_localconf.php
index d1ad0d8..caa33be 100644
--- a/ext_localconf.php
+++ b/ext_localconf.php
@@ -26,6 +26,12 @@ call_user_func(
[\Wrm\Events\Controller\DateController::class => 'show']
);
+ \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
+ 'Events',
+ 'Selected',
+ [\Wrm\Events\Controller\EventController::class => 'list']
+ );
+
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
$iconRegistry->registerIcon(
'events-plugin',