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
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.9.4dev - 2019-12-06
37 namespace Galette\Controllers\Crud
;
39 use Galette\Controllers\CrudController
;
40 use Slim\Http\Request
;
41 use Slim\Http\Response
;
42 use Galette\Repository\Titles
;
43 use Galette\Entity\Title
;
47 * Galette Titles controller
49 * @category Controllers
50 * @name TitlesController
52 * @author Johan Cwiklinski <johan@x-tnd.be>
53 * @copyright 2019-2020 The Galette Team
54 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
55 * @link http://galette.tuxfamily.org
56 * @since Available since 0.9.4dev - 2019-12-08
59 class TitlesController
extends CrudController
66 * @param Request $request PSR Request
67 * @param Response $response PSR Response
71 public function add(Request
$request, Response
$response): Response
73 //no new page (included on list), just to satisfy inheritance
79 * @param Request $request PSR Request
80 * @param Response $response PSR Response
84 public function doAdd(Request
$request, Response
$response): Response
86 return $this->store($request, $response, null);
95 * @param Request $request PSR Request
96 * @param Response $response PSR Response
97 * @param string $option One of 'page' or 'order'
98 * @param string|integer $value Value of the option
102 public function list(Request
$request, Response
$response, $option = null, $value = null): Response
104 $titles = Titles
::getList($this->zdb
);
109 'gestion_titres.tpl',
111 'page_title' => _T("Titles management"),
112 'titles_list' => $titles
121 * @param Request $request PSR Request
122 * @param Response $response PSR Response
126 public function filter(Request
$request, Response
$response): Response
137 * @param Request $request PSR Request
138 * @param Response $response PSR Response
139 * @param integer $id Title id
143 public function edit(Request
$request, Response
$response, int $id): Response
145 $title = new Title($id);
152 'page_title' => _T("Edit title"),
162 * @param Request $request PSR Request
163 * @param Response $response PSR Response
164 * @param integer $id Title id
168 public function doEdit(Request
$request, Response
$response, int $id): Response
170 return $this->store($request, $response, $id);
176 * @param Request $request PSR Request
177 * @param Response $response PSR Response
178 * @param integer $id Title id
182 public function store(Request
$request, Response
$response, int $id = null): Response
184 $post = $request->getParsedBody();
186 if (isset($post['cancel'])) {
189 ->withHeader('Location', $this->cancelUri($this->getArgs($request)));
192 $title = new Title((int)$id);
193 $title->short
= $post['short_label'];
194 $title->long
= $post['long_label'];
195 $res = $title->store($this->zdb
);
196 $redirect_uri = $this->redirectUri($this->getArgs($request));
200 $this->flash
->addMessage(
205 _T("Title '%s' has not been added!")
209 $this->flash
->addMessage(
214 _T("Title '%s' has not been modified!")
218 $redirect_uri = $this->router
->pathFor('editTitle', ['id' => $id]);
222 $this->flash
->addMessage(
227 _T("Title '%s' has been successfully added.")
231 $this->flash
->addMessage(
236 _T("Title '%s' has been successfully modified.")
243 ->withHeader('Location', $redirect_uri);
250 * Get redirection URI
252 * @param array $args Route arguments
256 public function redirectUri(array $args)
258 return $this->router
->pathFor('titles');
264 * @param array $args Route arguments
268 public function formUri(array $args)
270 return $this->router
->pathFor(
272 ['id' => $args['id']]
277 * Get confirmation removal page title
279 * @param array $args Route arguments
283 public function confirmRemoveTitle(array $args)
285 $title = new Title((int)$args['id']);
287 _T('Remove title %1$s'),
295 * @param array $args Route arguments
296 * @param array $post POST values
300 protected function doDelete(array $args, array $post)
302 $title = new Title((int)$args['id']);
303 return $title->remove($this->zdb
);