1
+ <?php
2
+ namespace Eike \Couch \Controller ;
3
+
4
+ use TYPO3 \CMS \Extbase \Utility \DebuggerUtility ;
5
+ /***************************************************************
6
+ *
7
+ * Copyright notice
8
+ *
9
+ * (c) 2016 Eike Starkmann <[email protected] >
10
+ *
11
+ * All rights reserved
12
+ *
13
+ * This script is part of the TYPO3 project. The TYPO3 project is
14
+ * free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation; either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * The GNU General Public License can be found at
20
+ * http://www.gnu.org/copyleft/gpl.html.
21
+ *
22
+ * This script is distributed in the hope that it will be useful,
23
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ * GNU General Public License for more details.
26
+ *
27
+ * This copyright notice MUST APPEAR in all copies of the script!
28
+ ***************************************************************/
29
+
30
+ /**
31
+ * CouchController
32
+ */
33
+ class CouchController extends \TYPO3 \CMS \Extbase \Mvc \Controller \ActionController
34
+ {
35
+
36
+ /**
37
+ * couchRepository
38
+ *
39
+ * @var \Eike\Couch\Domain\Repository\CouchRepository
40
+ * @inject
41
+ */
42
+ protected $ couchRepository = NULL ;
43
+ /**
44
+ * addressRepository
45
+ *
46
+ * @var \Undkonsorten\Addressmgmt\Domain\Repository\AddressRepository
47
+ * @inject
48
+ */
49
+ protected $ addressRepository = NULL ;
50
+
51
+ /**
52
+ * access
53
+ *
54
+ * @var \Eike\Couch\Service\Access
55
+ * @inject
56
+ */
57
+ protected $ access = NULL ;
58
+
59
+ /**
60
+ *
61
+ * @var \Undkonsorten\Addressmgmt\Service\Address
62
+ * @inject
63
+ */
64
+ protected $ addressService = NULL ;
65
+
66
+ public function initializeCreateAction () {
67
+ if (isset ($ this ->arguments ['newCouch ' ])) {
68
+ $ this ->arguments ['newCouch ' ]
69
+ ->getPropertyMappingConfiguration ()
70
+ ->forProperty ('begin ' )
71
+ ->setTypeConverterOption ('TYPO3 \\CMS \\Extbase \\Property \\TypeConverter \\DateTimeConverter ' , \TYPO3 \CMS \Extbase \Property \TypeConverter \DateTimeConverter::CONFIGURATION_DATE_FORMAT , 'Y/m/d H:i ' );
72
+ $ this ->arguments ['newCouch ' ]
73
+ ->getPropertyMappingConfiguration ()
74
+ ->forProperty ('end ' )
75
+ ->setTypeConverterOption ('TYPO3 \\CMS \\Extbase \\Property \\TypeConverter \\DateTimeConverter ' , \TYPO3 \CMS \Extbase \Property \TypeConverter \DateTimeConverter::CONFIGURATION_DATE_FORMAT , 'Y/m/d H:i ' );
76
+ }
77
+ }
78
+
79
+ public function initializeUpdateAction () {
80
+ if (isset ($ this ->arguments ['couch ' ])) {
81
+ $ this ->arguments ['couch ' ]
82
+ ->getPropertyMappingConfiguration ()
83
+ ->forProperty ('begin ' )
84
+ ->setTypeConverterOption ('TYPO3 \\CMS \\Extbase \\Property \\TypeConverter \\DateTimeConverter ' , \TYPO3 \CMS \Extbase \Property \TypeConverter \DateTimeConverter::CONFIGURATION_DATE_FORMAT , 'Y/m/d H:i ' );
85
+ $ this ->arguments ['couch ' ]
86
+ ->getPropertyMappingConfiguration ()
87
+ ->forProperty ('end ' )
88
+ ->setTypeConverterOption ('TYPO3 \\CMS \\Extbase \\Property \\TypeConverter \\DateTimeConverter ' , \TYPO3 \CMS \Extbase \Property \TypeConverter \DateTimeConverter::CONFIGURATION_DATE_FORMAT , 'Y/m/d H:i ' );
89
+ }
90
+ }
91
+
92
+ /**
93
+ * action list
94
+ *
95
+ * @return void
96
+ */
97
+ public function listAction ()
98
+ {
99
+ $ couchs = $ this ->couchRepository ->findAll ();
100
+
101
+ $ this ->view ->assign ('feUser ' , $ this ->access ->getLoggedInFrontendUser ());
102
+ $ this ->view ->assign ('couchs ' , $ couchs );
103
+ $ this ->view ->assign ('destination ' , $ this ->addressRepository ->findByUid ($ this ->settings ['destination ' ]));
104
+ }
105
+
106
+ /**
107
+ * action show
108
+ *
109
+ * @param \Eike\Couch\Domain\Model\Couch $couch
110
+ * @return void
111
+ */
112
+ public function showAction (\Eike \Couch \Domain \Model \Couch $ couch )
113
+ {
114
+ $ this ->view ->assign ('couch ' , $ couch );
115
+ }
116
+
117
+ /**
118
+ * action new
119
+ *
120
+ * @return void
121
+ */
122
+ public function newAction ()
123
+ {
124
+ if (!$ this ->access ->getLoggedInFrontendUser ()){
125
+ throw new InsufficientUserPermissionsException ('You are not logged in so you cannot create something here ' ,1466258305 );
126
+ }
127
+ $ this ->view ->assign ('now ' , new \DateTime ());
128
+ $ this ->view ->assign ('provider ' , $ this ->access ->getLoggedInFrontendUser ());
129
+ }
130
+
131
+ /**
132
+ * action create
133
+ *
134
+ * @param \Eike\Couch\Domain\Model\Couch $newCouch
135
+ * @return void
136
+ */
137
+ public function createAction (\Eike \Couch \Domain \Model \Couch $ newCouch )
138
+ {
139
+ $ this ->addFlashMessage ('The object was created. ' , '' , \TYPO3 \CMS \Core \Messaging \AbstractMessage::OK );
140
+ $ this ->addressService ->updateCoordinates ($ newCouch ->getAddress ());
141
+ $ this ->couchRepository ->add ($ newCouch );
142
+ $ this ->redirect ('list ' );
143
+ }
144
+
145
+ /**
146
+ * action edit
147
+ *
148
+ * @param \Eike\Couch\Domain\Model\Couch $couch
149
+ * @ignorevalidation $couch
150
+ * @return void
151
+ */
152
+ public function editAction (\Eike \Couch \Domain \Model \Couch $ couch )
153
+ {
154
+ if (!$ this ->access ->mayEditOrDelete ($ couch , $ this ->access ->getLoggedInFrontendUser ())){
155
+ throw new InsufficientUserPermissionsException ('You are not allowed to edit this couch ' ,1466260533 );
156
+ }
157
+ $ this ->view ->assign ('couch ' , $ couch );
158
+ $ this ->view ->assign ('provider ' , $ this ->access ->getLoggedInFrontendUser ());
159
+ }
160
+
161
+ /**
162
+ * action update
163
+ *
164
+ * @param \Eike\Couch\Domain\Model\Couch $couch
165
+ * @return void
166
+ */
167
+ public function updateAction (\Eike \Couch \Domain \Model \Couch $ couch )
168
+ {
169
+ $ this ->addFlashMessage ('The object was updated. ' , '' , \TYPO3 \CMS \Core \Messaging \AbstractMessage::OK );
170
+ $ this ->addressService ->updateCoordinates ($ couch ->getAddress ());
171
+ $ this ->couchRepository ->update ($ couch );
172
+ $ this ->redirect ('list ' );
173
+ }
174
+
175
+ /**
176
+ * action delete
177
+ *
178
+ * @param \Eike\Couch\Domain\Model\Couch $couch
179
+ * @return void
180
+ */
181
+ public function deleteAction (\Eike \Couch \Domain \Model \Couch $ couch )
182
+ {
183
+ if (!$ this ->access ->mayEditOrDelete ($ couch , $ this ->access ->getLoggedInFrontendUser ())){
184
+ throw new InsufficientUserPermissionsException ('You are not allowed to delete this couch ' ,1466260675 );
185
+ }
186
+ $ this ->addFlashMessage ('The object was deleted. ' , '' , \TYPO3 \CMS \Core \Messaging \AbstractMessage::OK );
187
+ $ this ->couchRepository ->remove ($ couch );
188
+ $ this ->redirect ('list ' );
189
+ }
190
+
191
+ }
0 commit comments