mirror of
https://github.com/werkraum-media/events.git
synced 2024-11-24 18:56:11 +01:00
Provide new "Event selected" plugin
Allow editors to select specific events to display. Therefore add new necessary demand and setting for events and respect them within repository. Relates: #8092
This commit is contained in:
parent
8da7284e1f
commit
17bd83eedf
8 changed files with 128 additions and 25 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace Wrm\Events\Controller;
|
namespace Wrm\Events\Controller;
|
||||||
|
|
||||||
use TYPO3\CMS\Core\Database\QueryGenerator;
|
use TYPO3\CMS\Core\Database\QueryGenerator;
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
use TYPO3\CMS\Extbase\Annotation as Extbase;
|
||||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
|
@ -122,6 +123,7 @@ class EventController extends ActionController
|
||||||
|
|
||||||
protected function createDemandFromSettings(): EventDemand
|
protected function createDemandFromSettings(): EventDemand
|
||||||
{
|
{
|
||||||
|
/** @var EventDemand $demand */
|
||||||
$demand = $this->objectManager->get(EventDemand::class);
|
$demand = $this->objectManager->get(EventDemand::class);
|
||||||
|
|
||||||
$demand->setRegion((string)$this->settings['region']);
|
$demand->setRegion((string)$this->settings['region']);
|
||||||
|
@ -138,6 +140,8 @@ class EventController extends ActionController
|
||||||
|
|
||||||
$demand->setHighlight((bool)$this->settings['highlight']);
|
$demand->setHighlight((bool)$this->settings['highlight']);
|
||||||
|
|
||||||
|
$demand->setRecordUids(GeneralUtility::intExplode(',', $this->settings['selectedRecords'], true));
|
||||||
|
|
||||||
if (!empty($this->settings['limit'])) {
|
if (!empty($this->settings['limit'])) {
|
||||||
$demand->setLimit($this->settings['limit']);
|
$demand->setLimit($this->settings['limit']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,11 @@ class EventDemand
|
||||||
*/
|
*/
|
||||||
protected $limit = '';
|
protected $limit = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $recordUids = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -172,4 +177,20 @@ class EventDemand
|
||||||
{
|
{
|
||||||
$this->limit = $limit;
|
$this->limit = $limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getRecordUids(): array
|
||||||
|
{
|
||||||
|
return $this->recordUids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $recordUids
|
||||||
|
*/
|
||||||
|
public function setRecordUids(array $recordUids): void
|
||||||
|
{
|
||||||
|
$this->recordUids = $recordUids;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ use TYPO3\CMS\Extbase\Persistence\QueryInterface;
|
||||||
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
|
||||||
use TYPO3\CMS\Extbase\Persistence\Repository;
|
use TYPO3\CMS\Extbase\Persistence\Repository;
|
||||||
use Wrm\Events\Domain\Model\Dto\EventDemand;
|
use Wrm\Events\Domain\Model\Dto\EventDemand;
|
||||||
|
use Wrm\Events\Domain\Model\Event;
|
||||||
use Wrm\Events\Service\CategoryService;
|
use Wrm\Events\Service\CategoryService;
|
||||||
|
|
||||||
class EventRepository extends Repository
|
class EventRepository extends Repository
|
||||||
|
@ -56,6 +57,11 @@ class EventRepository extends Repository
|
||||||
public function findByDemand(EventDemand $demand)
|
public function findByDemand(EventDemand $demand)
|
||||||
{
|
{
|
||||||
$query = $this->createDemandQuery($demand);
|
$query = $this->createDemandQuery($demand);
|
||||||
|
|
||||||
|
if ($demand->getRecordUids() !== [] && $demand->getSortBy() === 'default') {
|
||||||
|
return $this->sortByDemand($query, $demand);
|
||||||
|
}
|
||||||
|
|
||||||
return $query->execute();
|
return $query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +76,8 @@ class EventRepository extends Repository
|
||||||
|
|
||||||
// sorting
|
// sorting
|
||||||
$sortBy = $demand->getSortBy();
|
$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;
|
$order = strtolower($demand->getSortOrder()) === 'desc' ? QueryInterface::ORDER_DESCENDING : QueryInterface::ORDER_ASCENDING;
|
||||||
$query->setOrderings([$sortBy => $order]);
|
$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() !== '') {
|
if ($demand->getRegion() !== '') {
|
||||||
$constraints['region'] = $query->equals('region', $demand->getRegion());
|
$constraints['region'] = $query->equals('region', $demand->getRegion());
|
||||||
}
|
}
|
||||||
|
@ -133,6 +144,20 @@ class EventRepository extends Repository
|
||||||
return $constraints;
|
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)
|
public function findSearchWord($search)
|
||||||
{
|
{
|
||||||
|
|
24
Configuration/FlexForms/Selected.xml
Normal file
24
Configuration/FlexForms/Selected.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<T3DataStructure>
|
||||||
|
<sheets>
|
||||||
|
<sDEF>
|
||||||
|
<ROOT>
|
||||||
|
<type>array</type>
|
||||||
|
<el>
|
||||||
|
<settings.selectedRecords>
|
||||||
|
<TCEforms>
|
||||||
|
<exclude>1</exclude>
|
||||||
|
<label>LLL:EXT:events/Resources/Private/Language/de.locallang_db.xlf:tx_events.flexform.selected.selectedRecords</label>
|
||||||
|
<config>
|
||||||
|
<type>group</type>
|
||||||
|
<internal_type>db</internal_type>
|
||||||
|
<allowed>tx_events_domain_model_event</allowed>
|
||||||
|
<minitems>1</minitems>
|
||||||
|
<show_thumbs>1</show_thumbs>
|
||||||
|
</config>
|
||||||
|
</TCEforms>
|
||||||
|
</settings.selectedRecords>
|
||||||
|
</el>
|
||||||
|
</ROOT>
|
||||||
|
</sDEF>
|
||||||
|
</sheets>
|
||||||
|
</T3DataStructure>
|
|
@ -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'
|
||||||
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,20 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||||
<xliff version="1.0">
|
<xliff version="1.0">
|
||||||
<file source-language="en" datatype="plaintext" original="messages" date="2019-04-03T12:11:11Z" product-name="tx_events">
|
<file source-language="en" datatype="plaintext" original="messages" date="2019-04-03T12:11:11Z" product-name="tx_events">
|
||||||
<header/>
|
<header/>
|
||||||
<body>
|
<body>
|
||||||
<trans-unit id="tx_events.name">
|
<trans-unit id="tx_events.name">
|
||||||
<source>Events</source>
|
<source>Events</source>
|
||||||
<target>Veranstaltungen</target>
|
<target>Veranstaltungen</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="tx_events.description">
|
<trans-unit id="tx_events.description">
|
||||||
<source>Event Modul</source>
|
<source>Event Modul</source>
|
||||||
<target>Veranstaltungs Modul</target>
|
<target>Veranstaltungs Modul</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
</body>
|
<trans-unit id="tx_events.flexform.selected.selectedRecords">
|
||||||
</file>
|
<source>Records to show</source>
|
||||||
|
<target>Anzuzeigende Veranstaltungen</target>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
|
||||||
<xliff version="1.0">
|
<xliff version="1.0">
|
||||||
<file source-language="en" datatype="plaintext" original="messages" date="2019-04-03T12:11:11Z" product-name="tx_events">
|
<file source-language="en" datatype="plaintext" original="messages" date="2019-04-03T12:11:11Z" product-name="tx_events">
|
||||||
<header/>
|
<header/>
|
||||||
<body>
|
<body>
|
||||||
<trans-unit id="tx_events.name">
|
<trans-unit id="tx_events.name">
|
||||||
<source>Events</source>
|
<source>Events</source>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="tx_events.description">
|
<trans-unit id="tx_events.description">
|
||||||
<source>Event Modul</source>
|
<source>Event Modul</source>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
</body>
|
<trans-unit id="tx_events.flexform.selected.selectedRecords">
|
||||||
</file>
|
<source>Records to show</source>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
|
@ -26,6 +26,12 @@ call_user_func(
|
||||||
[\Wrm\Events\Controller\DateController::class => 'show']
|
[\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 = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
|
||||||
$iconRegistry->registerIcon(
|
$iconRegistry->registerIcon(
|
||||||
'events-plugin',
|
'events-plugin',
|
||||||
|
|
Loading…
Reference in a new issue