3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette payment types controller
10 * Copyright © 2019-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
;
41 use Slim\Http\Request
;
42 use Slim\Http\Response
;
43 use Galette\Repository\PaymentTypes
;
44 use Galette\Entity\PaymentType
;
48 * Galette payment types controller
50 * @category Controllers
51 * @name PaymentTypeController
53 * @author Johan Cwiklinski <johan@x-tnd.be>
54 * @copyright 2019-2020 The Galette Team
55 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
56 * @link http://galette.tuxfamily.org
57 * @since Available since 0.9.4dev - 2019-12-09
60 class PaymentTypeController
extends CrudController
67 * @param Request $request PSR Request
68 * @param Response $response PSR Response
69 * @param array $args Request arguments
73 public function add(Request
$request, Response
$response, array $args = []): Response
75 //no new page (included on list), just to satisfy inheritance
81 * @param Request $request PSR Request
82 * @param Response $response PSR Response
83 * @param array $args Request arguments
87 public function doAdd(Request
$request, Response
$response, array $args = []): Response
90 return $this->store($request, $response, $args);
97 * Mailings history page
99 * @param Request $request PSR Request
100 * @param Response $response PSR Response
101 * @param array $args Request arguments
105 public function list(Request
$request, Response
$response, array $args = []): Response
107 $ptypes = new PaymentTypes(
112 $list = $ptypes->getList();
117 'gestion_paymentstypes.tpl',
119 'page_title' => _T("Payment types management"),
129 * @param Request $request PSR Request
130 * @param Response $response PSR Response
134 public function filter(Request
$request, Response
$response): Response
145 * @param Request $request PSR Request
146 * @param Response $response PSR Response
147 * @param array $args Request arguments
151 public function edit(Request
$request, Response
$response, array $args = []): Response
153 $id = (int)$args['id'];
154 $ptype = new PaymentType($this->zdb
, $id);
159 'edit_paymenttype.tpl',
161 'page_title' => _T("Edit payment type"),
171 * @param Request $request PSR Request
172 * @param Response $response PSR Response
173 * @param array $args Request arguments
177 public function doEdit(Request
$request, Response
$response, array $args = []): Response
179 return $this->store($request, $response, $args);
185 * @param Request $request PSR Request
186 * @param Response $response PSR Response
187 * @param array $args Request arguments
191 public function store(Request
$request, Response
$response, array $args = []): Response
193 $id = (isset($args['id']) ?
(int)$args['id'] : null);
194 $post = $request->getParsedBody();
196 if (isset($post['cancel'])) {
199 ->withHeader('Location', $this->cancelUri());
202 $ptype = new PaymentType($this->zdb
, $id);
203 $ptype->name
= $post['name'];
204 $res = $ptype->store();
205 $redirect_uri = $this->redirectUri();
209 $this->flash
->addMessage(
214 _T("Payment type '%s' has not been added!")
218 $this->flash
->addMessage(
223 _T("Payment type '%s' has not been modified!")
226 //redirect to payment type edition
227 $redirect_uri = $this->router
->pathFor('editPaymentType', ['id' => $id]);
231 $this->flash
->addMessage(
236 _T("Payment type '%s' has been successfully added.")
240 $this->flash
->addMessage(
245 _T("Payment type '%s' has been successfully modified.")
251 $warning_detected = $ptype->getWarnings();
252 if (count($warning_detected)) {
253 foreach ($warning_detected as $warning) {
254 $this->flash
->addMessage(
263 ->withHeader('Location', $redirect_uri);
271 * Get redirection URI
273 * @param array $args Route arguments
277 public function redirectUri(array $args = [])
279 return $this->router
->pathFor('paymentTypes');
285 * @param array $args Route arguments
289 public function formUri(array $args = [])
291 return $this->router
->pathFor(
292 'doRemovePaymentType',
293 ['id' => $args['id'] ??
null]
298 * Get confirmation removal page title
300 * @param array $args Route arguments
304 public function confirmRemoveTitle(array $args = [])
306 $ptype = new PaymentType($this->zdb
, (int)$args['id']);
308 _T('Remove payment type %1$s'),
316 * @param array $args Route arguments
317 * @param array $post POST values
321 protected function doDelete(array $args, array $post)
323 $ptype = new PaymentType($this->zdb
, (int)$args['id']);
324 return $ptype->remove();