3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Galette Title controller
10 * Copyright © 2019-2023 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-2023 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\Psr7\Request
;
41 use Slim\Psr7\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-2023 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
80 * @param Request $request PSR Request
81 * @param Response $response PSR Response
85 public function doAdd(Request
$request, Response
$response): Response
87 return $this->store($request, $response, null);
96 * @param Request $request PSR Request
97 * @param Response $response PSR Response
98 * @param string $option One of 'page' or 'order'
99 * @param string|integer $value Value of the option
103 public function list(Request
$request, Response
$response, $option = null, $value = null): Response
105 $titles = Titles
::getList($this->zdb
);
110 'pages/configuration_titles.html.twig',
112 'page_title' => _T("Titles management"),
113 'titles_list' => $titles
122 * @param Request $request PSR Request
123 * @param Response $response PSR Response
127 public function filter(Request
$request, Response
$response): Response
139 * @param Request $request PSR Request
140 * @param Response $response PSR Response
141 * @param integer $id Title id
145 public function edit(Request
$request, Response
$response, int $id): Response
147 $title = new Title($id);
148 $mode = $request->getHeaderLine('X-Requested-With') === 'XMLHttpRequest' ?
'ajax' : '';
153 'pages/configuration_title_form.html.twig',
155 'page_title' => _T("Edit title"),
166 * @param Request $request PSR Request
167 * @param Response $response PSR Response
168 * @param integer $id Title id
172 public function doEdit(Request
$request, Response
$response, int $id): Response
174 return $this->store($request, $response, $id);
180 * @param Request $request PSR Request
181 * @param Response $response PSR Response
182 * @param integer $id Title id
186 public function store(Request
$request, Response
$response, int $id = null): Response
188 $post = $request->getParsedBody();
190 if (isset($post['cancel'])) {
193 ->withHeader('Location', $this->cancelUri($this->getArgs($request)));
196 $error_detected = [];
199 $title = new Title($id);
200 $title->short
= $post['short_label'];
201 $title->long
= $post['long_label'];
202 if ((isset($post['short_label']) && $post['short_label'] != '') && (isset($post['long_label']) && $post['long_label'] != '')) {
203 $res = $title->store($this->zdb
);
206 $error_detected[] = _T("Missing required title's short or long form!");
208 $redirect_uri = $this->redirectUri($this->getArgs($request));
212 $error_detected[] = preg_replace(
214 $title->short
!== null ?
$title->short
: '',
215 _T("Title '%s' has not been added!")
218 $error_detected[] = preg_replace(
220 $title->short
!== null ?
$title->short
: '',
221 _T("Title '%s' has not been modified!")
224 $redirect_uri = $this->routeparser
->urlFor('editTitle', ['id' => $id]);
228 $error_detected[] = preg_replace(
231 _T("Title '%s' has been successfully added.")
237 _T("Title '%s' has been successfully modified.")
242 if (count($error_detected) > 0) {
243 foreach ($error_detected as $error) {
244 $this->flash
->addMessage(
250 $this->flash
->addMessage(
258 ->withHeader('Location', $redirect_uri);
265 * Get redirection URI
267 * @param array $args Route arguments
271 public function redirectUri(array $args)
273 return $this->routeparser
->urlFor('titles');
279 * @param array $args Route arguments
283 public function formUri(array $args)
285 return $this->routeparser
->urlFor(
287 ['id' => $args['id']]
292 * Get confirmation removal page title
294 * @param array $args Route arguments
298 public function confirmRemoveTitle(array $args)
300 $title = new Title((int)$args['id']);
302 _T('Remove title %1$s'),
310 * @param array $args Route arguments
311 * @param array $post POST values
315 protected function doDelete(array $args, array $post)
317 $title = new Title((int)$args['id']);
318 return $title->remove($this->zdb
);