3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette Title 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-06
38 namespace Galette\Controllers\Crud
;
40 use Galette\Controllers\CrudController
;
41 use Slim\Http\Request
;
42 use Slim\Http\Response
;
43 use Galette\Repository\Titles
;
44 use Galette\Entity\Title
;
48 * Galette Titles controller
50 * @category Controllers
51 * @name TitlesController
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-08
60 class TitlesController
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);
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 $titles = Titles
::getList($this->zdb
);
112 'gestion_titres.tpl',
114 'page_title' => _T("Titles management"),
115 'titles_list' => $titles
124 * @param Request $request PSR Request
125 * @param Response $response PSR Response
129 public function filter(Request
$request, Response
$response): Response
140 * @param Request $request PSR Request
141 * @param Response $response PSR Response
142 * @param array $args Request arguments
146 public function edit(Request
$request, Response
$response, array $args = []): Response
148 $id = (int)$args['id'];
149 $title = new Title($id);
156 'page_title' => _T("Edit title"),
166 * @param Request $request PSR Request
167 * @param Response $response PSR Response
168 * @param array $args Request arguments
172 public function doEdit(Request
$request, Response
$response, array $args = []): Response
174 return $this->store($request, $response, $args);
180 * @param Request $request PSR Request
181 * @param Response $response PSR Response
182 * @param array $args Request arguments
186 public function store(Request
$request, Response
$response, array $args = []): Response
188 $id = $args['id'] ??
null;
189 $post = $request->getParsedBody();
191 if (isset($post['cancel'])) {
194 ->withHeader('Location', $this->cancelUri());
197 $title = new Title((int)$id);
198 $title->short
= $post['short_label'];
199 $title->long
= $post['long_label'];
200 $res = $title->store($this->zdb
);
201 $redirect_uri = $this->redirectUri();
205 $this->flash
->addMessage(
210 _T("Title '%s' has not been added!")
214 $this->flash
->addMessage(
219 _T("Title '%s' has not been modified!")
223 $redirect_uri = $this->router
->pathFor('editTitle', ['id' => $id]);
227 $this->flash
->addMessage(
232 _T("Title '%s' has been successfully added.")
236 $this->flash
->addMessage(
241 _T("Title '%s' has been successfully modified.")
248 ->withHeader('Location', $redirect_uri);
255 * Get redirection URI
257 * @param array $args Route arguments
261 public function redirectUri(array $args = [])
263 return $this->router
->pathFor('titles');
269 * @param array $args Route arguments
273 public function formUri(array $args = [])
275 return $this->router
->pathFor(
277 ['id' => $args['id']]
282 * Get confirmation removal page title
284 * @param array $args Route arguments
288 public function confirmRemoveTitle(array $args = [])
290 $title = new Title((int)$args['id']);
292 _T('Remove title %1$s'),
300 * @param array $args Route arguments
301 * @param array $post POST values
305 protected function doDelete(array $args, array $post)
307 $title = new Title((int)$args['id']);
308 return $title->remove($this->zdb
);