Last active
December 16, 2018 10:46
-
-
Save benjaminkott/3677333e84353f8da03f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('TYPO3_MODE')) { | |
die('Access denied.'); | |
} | |
/*************** | |
* Register Slots to News Extension | |
*/ | |
/** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */ | |
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher'); | |
$signalSlotDispatcher->connect( | |
'GeorgRinger\\News\\Controller\\NewsController', | |
'listAction', | |
'Bk2k\\Client\\Slots\\NewsControllerSlot', | |
'listActionSlot', | |
TRUE | |
); | |
$signalSlotDispatcher->connect( | |
'GeorgRinger\\News\\Controller\\NewsController', | |
'detailAction', | |
'Bk2k\\Client\\Slots\\NewsControllerSlot', | |
'detailActionSlot', | |
TRUE | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Bk2k\Client\Slots; | |
/** | |
* This file is part of the TYPO3 CMS project. | |
* | |
* It is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU General Public License, either version 2 | |
* of the License, or any later version. | |
* | |
* For the full copyright and license information, please read the | |
* LICENSE.txt file that was distributed with this source code. | |
* | |
* The TYPO3 project - inspiring people to share! | |
*/ | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
use TYPO3\CMS\Extbase\Object\ObjectManager; | |
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult; | |
use GeorgRinger\News\Domain\Model\News; | |
use GeorgRinger\News\Domain\Model\Dto\NewsDemand; | |
use GeorgRinger\News\Domain\Repository\NewsRepository; | |
use Bk2k\Client\Domain\Repository\OfficeRepository; | |
/** | |
* News Controller Slot | |
*/ | |
class NewsControllerSlot | |
{ | |
/** | |
* @var \TYPO3\CMS\Extbase\Object\ObjectManager | |
*/ | |
protected $objectManager; | |
/** | |
* @var \Bk2k\Client\Domain\Repository\OfficeRepository | |
*/ | |
protected $officeRepository; | |
/** | |
* @var \GeorgRinger\News\Domain\Repository\NewsRepository | |
*/ | |
protected $newsRepository; | |
/** | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class); | |
$this->officeRepository = $this->objectManager->get(OfficeRepository::class); | |
$this->newsRepository = $this->objectManager->get(NewsRepository::class); | |
} | |
/** | |
* @param QueryResult $news | |
* @param array $overrideDemand | |
* @param array $demand | |
* @return array | |
*/ | |
public function listActionSlot(QueryResult $news = null, $overrideDemand, NewsDemand $demand) | |
{ | |
// Get tags from resultset | |
$currentTags = $demand->getTags(); | |
$demand->setTags(''); | |
$filteredNewsRecords = $this->newsRepository->findDemanded($demand); | |
$demand->setTags($currentTags); | |
$tags = array(); | |
foreach ($filteredNewsRecords as $record) { | |
foreach ($record->getTags() as $tag) { | |
$tags[] = $tag; | |
} | |
} | |
$uniqueTags = array_unique($tags); | |
// Get headquarter | |
$headquarter = $this->officeRepository->findByType(0)->getFirst(); | |
// Assign values | |
$assignedValues = [ | |
'news' => $news, | |
'overwriteDemand' => $overwriteDemand, | |
'demand' => $demand, | |
'extendedVariables' => [ | |
'tags' => $uniqueTags, | |
'headquarter' => $headquarter | |
] | |
]; | |
return $assignedValues; | |
} | |
/** | |
* @param News $newsItem | |
* @param int $currentPage | |
* @param array $demand | |
* @return array | |
*/ | |
public function detailActionSlot(News $newsItem = null, $currentPage, NewsDemand $demand) | |
{ | |
// Get headquarter | |
$headquarter = $this->officeRepository->findByType(0)->getFirst(); | |
// Assign values | |
$assignedValues = [ | |
'newsItem' => $newsItem, | |
'currentPage' => $currentPage, | |
'demand' => $demand, | |
'extendedVariables' => [ | |
'headquarter' => $headquarter | |
] | |
]; | |
return $assignedValues; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment