17
17
18
18
namespace OnePlace \Project \Controller ;
19
19
20
- use Application \Controller \CoreController ;
20
+ use Application \Controller \CoreEntityController ;
21
21
use Application \Model \CoreEntityModel ;
22
22
use OnePlace \Project \Model \Project ;
23
23
use OnePlace \Project \Model \ProjectTable ;
24
24
use Laminas \View \Model \ViewModel ;
25
25
use Laminas \Db \Adapter \AdapterInterface ;
26
26
27
- class ProjectController extends CoreController {
27
+ class ProjectController extends CoreEntityController {
28
28
/**
29
29
* Project Table Object
30
30
*
31
31
* @since 1.0.0
32
32
*/
33
- private $ oTableGateway ;
33
+ protected $ oTableGateway ;
34
34
35
35
/**
36
36
* ProjectController constructor.
@@ -59,36 +59,10 @@ public function __construct(AdapterInterface $oDbAdapter,ProjectTable $oTableGat
59
59
* @return ViewModel - View Object with Data from Controller
60
60
*/
61
61
public function indexAction () {
62
- # Set Layout based on users theme
63
- $ this ->setThemeBasedLayout ('project ' );
64
62
65
- # Check license
66
- if (!$ this ->checkLicense ('project ' )) {
67
- $ this ->flashMessenger ()->addErrorMessage ('You have no active license for project ' );
68
- $ this ->redirect ()->toRoute ('home ' );
69
- }
70
-
71
- # Add Buttons for breadcrumb
72
- $ this ->setViewButtons ('project-index ' );
73
-
74
- # Set Table Rows for Index
75
- $ this ->setIndexColumns ('project-index ' );
76
-
77
- # Get Paginator
78
- $ oPaginator = $ this ->oTableGateway ->fetchAll (true );
79
- $ iPage = (int ) $ this ->params ()->fromQuery ('page ' , 1 );
80
- $ iPage = ($ iPage < 1 ) ? 1 : $ iPage ;
81
- $ oPaginator ->setCurrentPageNumber ($ iPage );
82
- $ oPaginator ->setItemCountPerPage (3 );
83
-
84
- # Log Performance in DB
85
- $ aMeasureEnd = getrusage ();
86
- $ this ->logPerfomance ('project-index ' ,$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"utime " ),$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"stime " ));
87
-
88
- return new ViewModel ([
89
- 'sTableName ' =>'project-index ' ,
90
- 'aItems ' =>$ oPaginator ,
91
- ]);
63
+ # You can just use the default function and customize it via hooks
64
+ # or replace the entire function if you need more customization
65
+ return $ this ->generateIndexView ('project ' );
92
66
}
93
67
94
68
/**
@@ -98,57 +72,17 @@ public function indexAction() {
98
72
* @return ViewModel - View Object with Data from Controller
99
73
*/
100
74
public function addAction () {
101
- # Set Layout based on users theme
102
- $ this ->setThemeBasedLayout ('project ' );
103
-
104
- # Check license
105
- if (!$ this ->checkLicense ('project ' )) {
106
- $ this ->flashMessenger ()->addErrorMessage ('You have no active license for project ' );
107
- $ this ->redirect ()->toRoute ('home ' );
108
- }
109
-
110
- # Get Request to decide wether to save or display form
111
- $ oRequest = $ this ->getRequest ();
112
-
113
- # Display Add Form
114
- if (!$ oRequest ->isPost ()) {
115
- # Add Buttons for breadcrumb
116
- $ this ->setViewButtons ('project-single ' );
117
-
118
- # Load Tabs for View Form
119
- $ this ->setViewTabs ($ this ->sSingleForm );
120
-
121
- # Load Fields for View Form
122
- $ this ->setFormFields ($ this ->sSingleForm );
123
-
124
- # Log Performance in DB
125
- $ aMeasureEnd = getrusage ();
126
- $ this ->logPerfomance ('project-add ' ,$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"utime " ),$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"stime " ));
127
-
128
- return new ViewModel ([
129
- 'sFormName ' => $ this ->sSingleForm ,
130
- ]);
131
- }
132
-
133
- # Get and validate Form Data
134
- $ aFormData = $ this ->parseFormData ($ _REQUEST );
135
-
136
- # Save Add Form
137
- $ oProject = new Project ($ this ->oDbAdapter );
138
- $ oProject ->exchangeArray ($ aFormData );
139
- $ iProjectID = $ this ->oTableGateway ->saveSingle ($ oProject );
140
- $ oProject = $ this ->oTableGateway ->getSingle ($ iProjectID );
141
-
142
- # Save Multiselect
143
- $ this ->updateMultiSelectFields ($ _REQUEST ,$ oProject ,'project-single ' );
144
-
145
- # Log Performance in DB
146
- $ aMeasureEnd = getrusage ();
147
- $ this ->logPerfomance ('project-save ' ,$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"utime " ),$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"stime " ));
148
-
149
- # Display Success Message and View New Project
150
- $ this ->flashMessenger ()->addSuccessMessage ('Project successfully created ' );
151
- return $ this ->redirect ()->toRoute ('project ' ,['action ' =>'view ' ,'id ' =>$ iProjectID ]);
75
+ /**
76
+ * You can just use the default function and customize it via hooks
77
+ * or replace the entire function if you need more customization
78
+ *
79
+ * Hooks available:
80
+ *
81
+ * project-add-before (before show add form)
82
+ * project-add-before-save (before save)
83
+ * project-add-after-save (after save)
84
+ */
85
+ return $ this ->generateAddView ('project ' );
152
86
}
153
87
154
88
/**
@@ -158,78 +92,17 @@ public function addAction() {
158
92
* @return ViewModel - View Object with Data from Controller
159
93
*/
160
94
public function editAction () {
161
- # Set Layout based on users theme
162
- $ this ->setThemeBasedLayout ('project ' );
163
-
164
- # Check license
165
- if (!$ this ->checkLicense ('project ' )) {
166
- $ this ->flashMessenger ()->addErrorMessage ('You have no active license for project ' );
167
- $ this ->redirect ()->toRoute ('home ' );
168
- }
169
-
170
- # Get Request to decide wether to save or display form
171
- $ oRequest = $ this ->getRequest ();
172
-
173
- # Display Edit Form
174
- if (!$ oRequest ->isPost ()) {
175
-
176
- # Get Project ID from URL
177
- $ iProjectID = $ this ->params ()->fromRoute ('id ' , 0 );
178
-
179
- # Try to get Project
180
- try {
181
- $ oProject = $ this ->oTableGateway ->getSingle ($ iProjectID );
182
- } catch (\RuntimeException $ e ) {
183
- echo 'Project Not found ' ;
184
- return false ;
185
- }
186
-
187
- # Attach Project Entity to Layout
188
- $ this ->setViewEntity ($ oProject );
189
-
190
- # Add Buttons for breadcrumb
191
- $ this ->setViewButtons ('project-single ' );
192
-
193
- # Load Tabs for View Form
194
- $ this ->setViewTabs ($ this ->sSingleForm );
195
-
196
- # Load Fields for View Form
197
- $ this ->setFormFields ($ this ->sSingleForm );
198
-
199
- # Log Performance in DB
200
- $ aMeasureEnd = getrusage ();
201
- $ this ->logPerfomance ('project-edit ' ,$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"utime " ),$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"stime " ));
202
-
203
- return new ViewModel ([
204
- 'sFormName ' => $ this ->sSingleForm ,
205
- 'oProject ' => $ oProject ,
206
- ]);
207
- }
208
-
209
- $ iProjectID = $ oRequest ->getPost ('Item_ID ' );
210
- $ oProject = $ this ->oTableGateway ->getSingle ($ iProjectID );
211
-
212
- # Update Project with Form Data
213
- $ oProject = $ this ->attachFormData ($ _REQUEST ,$ oProject );
214
-
215
- # Save Project
216
- $ iProjectID = $ this ->oTableGateway ->saveSingle ($ oProject );
217
-
218
- $ this ->layout ('layout/json ' );
219
-
220
- # Parse Form Data
221
- $ aFormData = $ this ->parseFormData ($ _REQUEST );
222
-
223
- # Save Multiselect
224
- $ this ->updateMultiSelectFields ($ aFormData ,$ oProject ,'project-single ' );
225
-
226
- # Log Performance in DB
227
- $ aMeasureEnd = getrusage ();
228
- $ this ->logPerfomance ('project-save ' ,$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"utime " ),$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"stime " ));
229
-
230
- # Display Success Message and View New User
231
- $ this ->flashMessenger ()->addSuccessMessage ('Project successfully saved ' );
232
- return $ this ->redirect ()->toRoute ('project ' ,['action ' =>'view ' ,'id ' =>$ iProjectID ]);
95
+ /**
96
+ * You can just use the default function and customize it via hooks
97
+ * or replace the entire function if you need more customization
98
+ *
99
+ * Hooks available:
100
+ *
101
+ * project-edit-before (before show edit form)
102
+ * project-edit-before-save (before save)
103
+ * project-edit-after-save (after save)
104
+ */
105
+ return $ this ->generateEditView ('project ' );
233
106
}
234
107
235
108
/**
@@ -239,45 +112,14 @@ public function editAction() {
239
112
* @return ViewModel - View Object with Data from Controller
240
113
*/
241
114
public function viewAction () {
242
- # Set Layout based on users theme
243
- $ this ->setThemeBasedLayout ('project ' );
244
-
245
- # Check license
246
- if (!$ this ->checkLicense ('project ' )) {
247
- $ this ->flashMessenger ()->addErrorMessage ('You have no active license for project ' );
248
- $ this ->redirect ()->toRoute ('home ' );
249
- }
250
-
251
- # Get Project ID from URL
252
- $ iProjectID = $ this ->params ()->fromRoute ('id ' , 0 );
253
-
254
- # Try to get Project
255
- try {
256
- $ oProject = $ this ->oTableGateway ->getSingle ($ iProjectID );
257
- } catch (\RuntimeException $ e ) {
258
- echo 'Project Not found ' ;
259
- return false ;
260
- }
261
-
262
- # Attach Project Entity to Layout
263
- $ this ->setViewEntity ($ oProject );
264
-
265
- # Add Buttons for breadcrumb
266
- $ this ->setViewButtons ('project-view ' );
267
-
268
- # Load Tabs for View Form
269
- $ this ->setViewTabs ($ this ->sSingleForm );
270
-
271
- # Load Fields for View Form
272
- $ this ->setFormFields ($ this ->sSingleForm );
273
-
274
- # Log Performance in DB
275
- $ aMeasureEnd = getrusage ();
276
- $ this ->logPerfomance ('project-view ' ,$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"utime " ),$ this ->rutime ($ aMeasureEnd ,CoreController::$ aPerfomanceLogStart ,"stime " ));
277
-
278
- return new ViewModel ([
279
- 'sFormName ' =>$ this ->sSingleForm ,
280
- 'oProject ' =>$ oProject ,
281
- ]);
115
+ /**
116
+ * You can just use the default function and customize it via hooks
117
+ * or replace the entire function if you need more customization
118
+ *
119
+ * Hooks available:
120
+ *
121
+ * project-view-before
122
+ */
123
+ return $ this ->generateViewView ('project ' );
282
124
}
283
125
}
0 commit comments