forked from visol-forks/ext-roq_newsevent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventController.php
233 lines (199 loc) · 9.11 KB
/
EventController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/**
* Copyright (c) 2012, ROQUIN B.V. (C), http://www.roquin.nl
*
* @author: J. de Groot
* @file: EventController.php
* @description: News event Controller, extending functionality from the News Controller
*/
/**
* @package TYPO3
* @subpackage roq_newsevent
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_RoqNewsevent_Controller_EventController extends \GeorgRinger\News\Controller\NewsController {
/**
* eventRepository
*
* @var Tx_RoqNewsevent_Domain_Repository_EventRepository
* @inject
*/
protected $eventRepository;
/**
* Initializes the settings
*
* @param array $settings
* @return array $settings
*/
protected function initializeSettings($settings) {
if (isset($settings['event']['dateField'])) {
$settings['dateField'] = $settings['event']['dateField'];
} else {
$settings['dateField'] = 'eventStartdate';
}
return $settings;
}
/**
* Overrides setViewConfiguration: Use event view configuration instead of news view configuration if an event
* controller action is used
*
* @param Tx_Extbase_MVC_View_ViewInterface $view
* @return void
*/
protected function setViewConfiguration(Tx_Extbase_MVC_View_ViewInterface $view) {
$extbaseFrameworkConfiguration =
$this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
// Fetch the current controller action which is set in the news plugin
$controllerConfigurationAction = implode(';', $extbaseFrameworkConfiguration['controllerConfiguration']['News']['actions']);
parent::setViewConfiguration($view);
// Check if the current controller configuration action matches with one of the event controller actions
foreach($GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['switchableControllerActions']['newItems'] as $switchableControllerActions => $value) {
$action = str_replace('News->', '', $switchableControllerActions);
if(strpos($action, $controllerConfigurationAction) !== FALSE) {
// the current controller configuration action matches with one of the event controller actions: set event view configuration
$this->setEventViewConfiguration($view);
}
}
}
/**
* Override templateRootPath, layoutRootPath and/or partialRootPath of the news view with event specific settings
*
* @param Tx_Extbase_MVC_View_ViewInterface $view
* @param array $extbaseFrameworkConfiguration
* @return void
*/
protected function setEventViewConfiguration(Tx_Extbase_MVC_View_ViewInterface $view) {
// Template Path Override
$extbaseFrameworkConfiguration =
$this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
if (isset($extbaseFrameworkConfiguration['view']['event']['templateRootPath'])
&& strlen($extbaseFrameworkConfiguration['view']['event']['templateRootPath']) > 0
&& method_exists($view, 'setTemplateRootPath')) {
$view->setTemplateRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['event']['templateRootPath']));
}
if (isset($extbaseFrameworkConfiguration['view']['event']['layoutRootPath'])
&& strlen($extbaseFrameworkConfiguration['view']['event']['layoutRootPath']) > 0
&& method_exists($view, 'setLayoutRootPath')) {
$view->setLayoutRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['event']['layoutRootPath']));
}
if (isset($extbaseFrameworkConfiguration['view']['event']['partialRootPath'])
&& strlen($extbaseFrameworkConfiguration['view']['event']['partialRootPath']) > 0
&& method_exists($view, 'setPartialRootPath')) {
$view->setPartialRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['event']['partialRootPath']));
}
}
/**
* Create the demand object which define which records will get shown
*
* @param array $settings
* @return Tx_News_Domain_Model_NewsDemand
*/
protected function eventCreateDemandObjectFromSettings($settings) {
$demand = parent::createDemandObjectFromSettings($settings);
$orderByAllowed = $demand->getOrderByAllowed();
if(sizeof($orderByAllowed) > 0) {
$orderByAllowed .= ',';
}
// set ordering
if($settings['event']['orderByAllowed']) {
$demand->setOrderByAllowed($orderByAllowed . str_replace(' ', '', $settings['event']['orderByAllowed']));
} else {
// default orderByAllowed list
$demand->setOrderByAllowed($orderByAllowed . 'tx_roqnewsevent_startdate,tx_roqnewsevent_starttime');
}
if($demand->getArchiveRestriction() == 'archived') {
if ($settings['event']['archived']['orderBy']) {
$demand->setOrder($settings['event']['archived']['orderBy']);
} else {
// default ordering for archived events
$demand->setOrder('tx_roqnewsevent_startdate DESC, tx_roqnewsevent_starttime DESC');
}
} else {
if ($settings['event']['orderBy']) {
$demand->setOrder($settings['event']['orderBy']);
} else {
// default ordering for active events
$demand->setOrder('tx_roqnewsevent_startdate ASC, tx_roqnewsevent_starttime ASC');
}
}
if($settings['event']['startingpoint']) {
$demand->setStoragePage(Tx_News_Utility_Page::extendPidListByChildren($settings['event']['startingpoint'], $settings['recursive']));
}
return $demand;
}
/**
* Render a menu by dates, e.g. years, months or dates
*
* @param array $overwriteDemand
* @return void
*/
public function eventDateMenuAction(array $overwriteDemand = NULL) {
$this->settings = $this->initializeSettings($this->settings);
$demand = $this->eventCreateDemandObjectFromSettings($this->settings);
$eventRecords = $this->eventRepository->findDemanded($demand);
if (!$dateField = $this->settings['dateField']) {
$dateField = 'eventStartdate';
}
$this->view->assignMultiple(array(
'listPid' => ($this->settings['listPid'] ? $this->settings['listPid'] : $GLOBALS['TSFE']->id),
'dateField' => $dateField,
'events' => $eventRecords,
'overwriteDemand' => $overwriteDemand,
));
}
/**
* Output a list view of news events
*
* @param array $overwriteDemand
* @return string the Rendered view
*/
public function eventListAction(array $overwriteDemand = NULL) {
$this->settings = $this->initializeSettings($this->settings);
$demand = $this->eventCreateDemandObjectFromSettings($this->settings);
if ($this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== NULL) {
$demand = $this->overwriteDemandObject($demand, $overwriteDemand);
}
$newsRecords = $this->eventRepository->findDemanded($demand);
$this->view->assignMultiple(array(
'news' => $newsRecords,
'overwriteDemand' => $overwriteDemand,
));
Tx_News_Utility_Cache::addPageCacheTagsByDemandObject($demand);
}
/**
* Single view of a news event record
*
* @param Tx_RoqNewsevent_Domain_Model_Event $event
* @param integer $currentPage current page for optional pagination
* @return void
*/
public function eventDetailAction(Tx_RoqNewsevent_Domain_Model_Event $event = NULL, $currentPage = 1) {
$this->settings = $this->initializeSettings($this->settings);
if (is_null($event)) {
if ((int)$this->settings['singleNews'] > 0) {
$previewNewsId = $this->settings['singleNews'];
} elseif ($this->request->hasArgument('news_preview')) {
$previewNewsId = $this->request->getArgument('news_preview');
} else {
$previewNewsId = $this->request->getArgument('news');
}
if ($this->settings['previewHiddenRecords']) {
$event = $this->eventRepository->findByUid($previewNewsId, FALSE);
} else {
$event = $this->eventRepository->findByUid($previewNewsId);
}
}
if (is_null($event) && isset($this->settings['detail']['errorHandling'])) {
$this->handleNoNewsFoundError($this->settings['detail']['errorHandling']);
}
$this->view->assignMultiple(array(
'newsItem' => $event,
'currentPage' => (int)$currentPage,
));
Tx_News_Utility_Page::setRegisterProperties($this->settings['detail']['registerProperties'], $event);
if ($event instanceof Tx_RoqNewsevent_Domain_Model_Event) {
Tx_News_Utility_Cache::addCacheTagsByNewsRecords(array($event));
}
}
}
?>