3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Entitleds (contributions types and status) controller
10 * Copyright © 2020 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is 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.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
27 * @category Controllers
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2019-2020 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9.4dev - 2019-12-09
38 namespace Galette\Controllers\Crud
;
40 use Galette\Controllers\CrudController
;
42 use Slim\Http\Request
;
43 use Slim\Http\Response
;
45 use Galette\Entity\ContributionsTypes
;
46 use Galette\Entity\Status
;
47 use Galette\Repository\Members
;
52 * Galette Entitleds (contributions types and status) controller
54 * @category Controllers
55 * @name EntitledsController
57 * @author Johan Cwiklinski <johan@x-tnd.be>
58 * @copyright 2020 The Galette Team
59 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
60 * @link http://galette.tuxfamily.org
61 * @since Available since 0.9.4dev - 2020-06-07
64 class EntitledsController
extends CrudController
71 * @param Request $request PSR Request
72 * @param Response $response PSR Response
73 * @param array $args Request arguments
77 public function add(Request
$request, Response
$response, array $args = []) :Response
79 //no new page (included on list), just to satisfy inheritance
85 * @param Request $request PSR Request
86 * @param Response $response PSR Response
87 * @param array $args Request arguments
91 public function doAdd(Request
$request, Response
$response, array $args = []) :Response
94 return $this->store($request, $response, $args);
101 * Mailings history page
103 * @param Request $request PSR Request
104 * @param Response $response PSR Response
105 * @param array $args Request arguments
109 public function list(Request
$request, Response
$response, array $args = []) :Response
115 switch ($args['class']) {
117 $className = 'Status';
118 $class = new Status($this->zdb
);
119 $params['page_title'] = _T("User statuses");
120 $params['non_staff_priority'] = Members
::NON_STAFF_MEMBERS
;
122 case 'contributions-types':
123 $className = 'ContributionsTypes';
124 $class = new ContributionsTypes($this->zdb
);
125 $params['page_title'] = _T("Contribution types");
129 $params['class'] = $className;
130 $params['url_class'] = $args['class'];
131 $params['fields'] = $class::$fields;
133 $list = $class->getCompleteList();
134 $params['entries'] = $list;
136 if (count($class->errors
) > 0) {
137 $error_detected = array_merge($error_detected, $class->errors
);
143 'gestion_intitules.tpl',
152 * @param Request $request PSR Request
153 * @param Response $response PSR Response
157 public function filter(Request
$request, Response
$response) :Response
168 * @param Request $request PSR Request
169 * @param Response $response PSR Response
170 * @param array $args Request arguments
174 public function edit(Request
$request, Response
$response, array $args = []) :Response
180 switch ($args['class']) {
182 $className = 'Status';
183 $class = new Status($this->zdb
);
184 $params['page_title'] = _T("Edit status");
185 $params['non_staff_priority'] = Members
::NON_STAFF_MEMBERS
;
187 case 'contributions-types':
188 $className = 'ContributionsTypes';
189 $class = new ContributionsTypes($this->zdb
);
190 $params['page_title'] = _T("Edit contribution type");
194 $params['class'] = $className;
195 $params['url_class'] = $args['class'];
196 $params['fields'] = $class::$fields;
198 $entry = $class->get($args['id']);
199 $params['entry'] = $entry;
204 'editer_intitule.tpl',
213 * @param Request $request PSR Request
214 * @param Response $response PSR Response
215 * @param array $args Request arguments
219 public function doEdit(Request
$request, Response
$response, array $args = []) :Response
221 return $this->store($request, $response, $args);
227 * @param Request $request PSR Request
228 * @param Response $response PSR Response
229 * @param array $args Request arguments
233 public function store(Request
$request, Response
$response, array $args = []) :Response
235 $id = (isset($args['id']) ?
(int)$args['id'] : null);
237 $post = $request->getParsedBody();
240 switch ($args['class']) {
242 $class = new Status($this->zdb
);
244 case 'contributions-types':
245 $class = new ContributionsTypes($this->zdb
);
249 $label = trim($post[$class::$fields['libelle']]);
250 $field = trim($post[$class::$fields['third']]);
253 if ($args['action'] === 'add') {
254 $ret = $class->add($label, $field);
256 $oldlabel = $class->getLabel($id, false);
257 $ret = $class->update($id, $label, $field);
261 $msg_type = 'error_detected';
262 $msg = $args['action'] === 'add' ?
263 _T("%type has not been added :(") : _T("%type #%id has not been updated");
265 $msg_type = 'success_detected';
266 $msg = $args['action'] === 'add' ?
267 _T("%type has been successfully added!") : _T("%type #%id has been successfully updated!");
270 $this->flash
->addMessage(
274 [$class->getI18nType(), $id],
283 $this->router
->pathFor(
285 ['class' => $args['class']]
295 * Get redirection URI
297 * @param array $args Route arguments
301 public function redirectUri(array $args = [])
303 return $this->router
->pathFor('entitleds', ['class' => $args['class']]);
309 * @param array $args Route arguments
313 public function formUri(array $args = [])
315 return $this->router
->pathFor(
318 'class' => $args['class'],
325 * Get confirmation removal page title
327 * @param array $args Route arguments
331 public function confirmRemoveTitle(array $args = [])
334 switch ($args['class']) {
336 $class = new Status($this->zdb
);
338 case 'contributions-types':
339 $class = new ContributionsTypes($this->zdb
);
342 $label = $class->getLabel((int)$args['id']);
346 [$class->getI18nType(), $label],
347 _T("Remove %type '%label'")
354 * @param array $args Route arguments
355 * @param array $post POST values
359 protected function doDelete(array $args, array $post)
362 switch ($args['class']) {
364 $class = new Status($this->zdb
);
366 case 'contributions-types':
367 $class = new ContributionsTypes($this->zdb
);
371 $label = $class->getLabel((int)$args['id']);
373 if ($label !== $class::ID_NOT_EXITS
) {
374 $ret = $class->delete((int)$args['id']);
377 foreach ($class->getErrors() as $error) {
378 $this->flash
->addMessage(