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