]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Controllers/TextController.php
d680b9554a49e683691a41ffdba5266f6ca07c49
[galette.git] / galette / lib / Galette / Controllers / TextController.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Galette texts controller
7 *
8 * PHP version 5
9 *
10 * Copyright © 2020-2021 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
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.
18 *
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.
23 *
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/>.
26 *
27 * @category Controllers
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2020-2021 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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9.4dev - 2020-06-08
36 */
37
38 namespace Galette\Controllers;
39
40 use Slim\Http\Request;
41 use Slim\Http\Response;
42 use Galette\Entity\Texts;
43 use Analog\Analog;
44
45 /**
46 * Galette texts controller
47 *
48 * @category Controllers
49 * @name TextController
50 * @package Galette
51 * @author Johan Cwiklinski <johan@x-tnd.be>
52 * @copyright 2020-2021 The Galette Team
53 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
54 * @link http://galette.tuxfamily.org
55 * @since Available since 0.9.4dev - 2020-06-08
56 */
57
58 class TextController extends AbstractController
59 {
60 /**
61 * List texts
62 *
63 * @param Request $request PSR Request
64 * @param Response $response PSR Response
65 * @param string $lang Language
66 * @param string $ref Ref code
67 *
68 * @return void
69 */
70 public function list(Request $request, Response $response, string $lang = null, string $ref = null)
71 {
72 if ($lang === null) {
73 $lang = $this->preferences->pref_lang;
74 }
75 if ($ref === null) {
76 $ref = Texts::DEFAULT_REF;
77 }
78
79 $texts = new Texts(
80 $this->preferences,
81 $this->router
82 );
83
84 $texts->setCurrent($ref);
85 $mtxt = $texts->getTexts($ref, $lang);
86
87 // display page
88 $this->view->render(
89 $response,
90 'gestion_textes.tpl',
91 [
92 'page_title' => _T("Automatic emails texts edition"),
93 'texts' => $texts,
94 'reflist' => $texts->getRefs($lang),
95 'langlist' => $this->i18n->getList(),
96 'cur_lang' => $lang,
97 'cur_ref' => $ref,
98 'mtxt' => $mtxt,
99 ]
100 );
101 return $response;
102 }
103
104 /**
105 * Change texts
106 *
107 * @param Request $request PSR Request
108 * @param Response $response PSR Response
109 *
110 * @return void
111 */
112 public function change(Request $request, Response $response)
113 {
114 $post = $request->getParsedBody();
115 return $response
116 ->withStatus(301)
117 ->withHeader(
118 'Location',
119 $this->router->pathFor(
120 'texts',
121 [
122 'lang' => $post['sel_lang'],
123 'ref' => $post['sel_ref']
124 ]
125 )
126 );
127 }
128
129 /**
130 * Edit text
131 *
132 * @param Request $request PSR Request
133 * @param Response $response PSR Response
134 *
135 * @return void
136 */
137 public function edit(Request $request, Response $response)
138 {
139 $post = $request->getParsedBody();
140 $texts = new Texts($this->preferences, $this->router);
141
142 //set the language
143 $cur_lang = $post['cur_lang'];
144 //set the text entry
145 $cur_ref = $post['cur_ref'];
146
147 $mtxt = $texts->getTexts($cur_ref, $cur_lang, $this->router);
148 $res = $texts->setTexts(
149 $cur_ref,
150 $cur_lang,
151 $post['text_subject'],
152 $post['text_body']
153 );
154
155 if (!$res) {
156 $this->flash->addMessage(
157 'error_detected',
158 preg_replace(
159 '(%s)',
160 $mtxt->tcomment,
161 _T("Email: '%s' has not been modified!")
162 )
163 );
164 } else {
165 $this->flash->addMessage(
166 'success_detected',
167 preg_replace(
168 '(%s)',
169 $mtxt->tcomment,
170 _T("Email: '%s' has been successfully modified.")
171 )
172 );
173 }
174
175 return $response
176 ->withStatus(301)
177 ->withHeader(
178 'Location',
179 $this->router->pathFor(
180 'texts',
181 [
182 'lang' => $cur_lang,
183 'ref' => $cur_ref
184 ]
185 )
186 );
187 }
188 }