1 |
www |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Controller;
|
|
|
5 |
|
|
|
6 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
7 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
8 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
9 |
use Laminas\Log\LoggerInterface;
|
|
|
10 |
use Laminas\View\Model\ViewModel;
|
|
|
11 |
use Laminas\View\Model\JsonModel;
|
|
|
12 |
use LeadersLinked\Library\Functions;
|
|
|
13 |
use LeadersLinked\Mapper\PostMapper;
|
|
|
14 |
use LeadersLinked\Form\PostCreateForm;
|
|
|
15 |
use LeadersLinked\Form\PostEditForm;
|
|
|
16 |
use LeadersLinked\Model\Post;
|
|
|
17 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
18 |
use LeadersLinked\Library\Image;
|
|
|
19 |
|
|
|
20 |
class PostController extends AbstractActionController
|
|
|
21 |
{
|
|
|
22 |
/**
|
|
|
23 |
*
|
|
|
24 |
* @var AdapterInterface
|
|
|
25 |
*/
|
|
|
26 |
private $adapter;
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
* @var AbstractAdapter
|
|
|
32 |
*/
|
|
|
33 |
private $cache;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
*
|
|
|
37 |
* @var LoggerInterface
|
|
|
38 |
*/
|
|
|
39 |
private $logger;
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @var array
|
|
|
45 |
*/
|
|
|
46 |
private $config;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @param AdapterInterface $adapter
|
|
|
51 |
* @param AbstractAdapter $cache
|
|
|
52 |
* @param LoggerInterface $logger
|
|
|
53 |
* @param array $config
|
|
|
54 |
*/
|
|
|
55 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
56 |
{
|
|
|
57 |
$this->adapter = $adapter;
|
|
|
58 |
$this->cache = $cache;
|
|
|
59 |
$this->logger = $logger;
|
|
|
60 |
$this->config = $config;
|
|
|
61 |
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public function indexAction()
|
|
|
65 |
{
|
15347 |
efrain |
66 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
67 |
$currentUser = $currentUserPlugin->getUser();
|
1 |
www |
68 |
|
|
|
69 |
$request = $this->getRequest();
|
|
|
70 |
if($request->isGet()) {
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
$headers = $request->getHeaders();
|
|
|
74 |
|
|
|
75 |
$isJson = false;
|
|
|
76 |
if($headers->has('Accept')) {
|
|
|
77 |
$accept = $headers->get('Accept');
|
|
|
78 |
|
|
|
79 |
$prioritized = $accept->getPrioritized();
|
|
|
80 |
|
|
|
81 |
foreach($prioritized as $key => $value) {
|
|
|
82 |
$raw = trim($value->getRaw());
|
|
|
83 |
|
|
|
84 |
if(!$isJson) {
|
|
|
85 |
$isJson = strpos($raw, 'json');
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
if($isJson) {
|
|
|
92 |
|
|
|
93 |
if($this->config['leaderslinked.runmode.sandbox']) {
|
|
|
94 |
$url_frontend = $this->config['leaderslinked.frontend.sandbox_post'];
|
|
|
95 |
} else {
|
|
|
96 |
$url_frontend = $this->config['leaderslinked.frontend.production_post'];
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
$search = $this->params()->fromQuery('search', []);
|
|
|
102 |
$search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
|
|
|
103 |
|
|
|
104 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
105 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
106 |
$order = $this->params()->fromQuery('order', []);
|
|
|
107 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
108 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
109 |
|
|
|
110 |
$fields = ['title', 'date'];
|
|
|
111 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
|
|
|
112 |
|
|
|
113 |
if(!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
114 |
$order_direction = 'ASC';
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
$postMapper = PostMapper::getInstance($this->adapter);
|
15347 |
efrain |
118 |
$paginator = $postMapper->fetchAllDataTable($search, $currentUser->network_id, $page, $records_x_page, $order_field, $order_direction);
|
1 |
www |
119 |
|
|
|
120 |
$items = [];
|
|
|
121 |
$records = $paginator->getCurrentItems();
|
|
|
122 |
foreach($records as $record)
|
|
|
123 |
{
|
|
|
124 |
$dt = \DateTime::createFromFormat('Y-m-d', $record->date);
|
|
|
125 |
|
|
|
126 |
$item = [
|
|
|
127 |
'title' => $record->title,
|
|
|
128 |
'active' => $record->status ,
|
|
|
129 |
'date' => $dt->format('d/m/Y'),
|
|
|
130 |
'actions' => [
|
|
|
131 |
'link_edit' => $this->url()->fromRoute('publications/posts/edit', ['id' => $record->uuid ]),
|
|
|
132 |
'link_delete' => $this->url()->fromRoute('publications/posts/delete', ['id' => $record->uuid ]),
|
|
|
133 |
'link_view' => str_replace('[uuid]', $record->uuid, $url_frontend),
|
|
|
134 |
]
|
|
|
135 |
];
|
|
|
136 |
|
|
|
137 |
array_push($items, $item);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
return new JsonModel([
|
|
|
141 |
'success' => true,
|
|
|
142 |
'data' => [
|
|
|
143 |
'items' => $items,
|
|
|
144 |
'total' => $paginator->getTotalItemCount(),
|
|
|
145 |
]
|
|
|
146 |
]);
|
|
|
147 |
} else {
|
|
|
148 |
$image_size = $this->config['leaderslinked.image_sizes.post'];
|
|
|
149 |
|
|
|
150 |
$formAdd = new PostCreateForm();
|
|
|
151 |
$formEdit = new PostEditForm();
|
|
|
152 |
|
|
|
153 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
154 |
$viewModel = new ViewModel();
|
|
|
155 |
$viewModel->setTemplate('leaders-linked/posts/index.phtml');
|
|
|
156 |
$viewModel->setVariables([
|
|
|
157 |
'formAdd' => $formAdd,
|
|
|
158 |
'formEdit' => $formEdit,
|
|
|
159 |
'image_size' => $image_size,
|
|
|
160 |
|
|
|
161 |
]);
|
|
|
162 |
return $viewModel ;
|
|
|
163 |
}
|
|
|
164 |
} else {
|
|
|
165 |
return new JsonModel([
|
|
|
166 |
'success' => false,
|
|
|
167 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
168 |
]);;
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
public function addAction()
|
|
|
175 |
{
|
|
|
176 |
|
|
|
177 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
178 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
179 |
|
|
|
180 |
$request = $this->getRequest();
|
|
|
181 |
if($request->isPost()) {
|
|
|
182 |
|
|
|
183 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
184 |
$dataPost['status'] = empty($dataPost['status']) ? Post::STATUS_INACTIVE : $dataPost['status'];
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
$form = new PostCreateForm();
|
|
|
188 |
$form->setData($dataPost);
|
|
|
189 |
|
|
|
190 |
if($form->isValid()) {
|
|
|
191 |
$dataPost = (array) $form->getData();
|
|
|
192 |
|
|
|
193 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
194 |
$post = new Post();
|
|
|
195 |
$hydrator->hydrate($dataPost, $post);
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
$dt = \DateTime::createFromFormat('d/m/Y', $post->date);
|
|
|
199 |
$post->date = $dt->format('Y-m-d');
|
15347 |
efrain |
200 |
$post->network_id = $currentUser->network_id;
|
1 |
www |
201 |
$post->image = '';
|
|
|
202 |
$post->file = '';
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
$postMapper = PostMapper::getInstance($this->adapter);
|
|
|
206 |
if($postMapper->insert($post)) {
|
|
|
207 |
$post = $postMapper->fetchOne($post->id);
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
211 |
|
|
|
212 |
$target_path = $this->config['leaderslinked.fullpath.post'] . $post->uuid;
|
|
|
213 |
if(!file_exists($target_path)) {
|
|
|
214 |
mkdir($target_path, 0755, true);
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
if(isset($files['file']) && empty($files['file']['error'])) {
|
|
|
219 |
$tmp_filename = $files['file']['tmp_name'];
|
|
|
220 |
$original_filename = trim(strtolower($files['file']['name']));
|
|
|
221 |
|
|
|
222 |
$original_filename = Functions::normalizeString($original_filename);
|
|
|
223 |
|
|
|
224 |
$parts = explode('.', $original_filename);
|
|
|
225 |
$original_filename = $parts[0] . '.' . $parts[ count($parts) - 1 ];
|
|
|
226 |
|
|
|
227 |
try
|
|
|
228 |
{
|
|
|
229 |
$full_filename = $target_path . DIRECTORY_SEPARATOR .$original_filename;
|
|
|
230 |
if(move_uploaded_file($tmp_filename, $full_filename)) {
|
|
|
231 |
$post->file = basename($full_filename);
|
|
|
232 |
$post->update($post);
|
|
|
233 |
}
|
|
|
234 |
} catch(\Throwable $e) {
|
|
|
235 |
error_log($e->getTraceAsString());
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
if(isset($files['image']) && empty($files['image']['error'])) {
|
|
|
240 |
$tmp_filename = $files['image']['tmp_name'];
|
|
|
241 |
|
|
|
242 |
try {
|
|
|
243 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.post']);
|
|
|
244 |
|
|
|
245 |
$filename = 'image-' .uniqid() . '.png';
|
15077 |
efrain |
246 |
// $crop_to_dimensions = true;
|
|
|
247 |
// if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
|
|
|
248 |
|
|
|
249 |
if(Image::uploadImageWithoutCompletationSize($tmp_filename, $target_path, $filename, $target_width, $target_height)) {
|
1 |
www |
250 |
$post->image = $filename;
|
|
|
251 |
$postMapper->update($post);
|
|
|
252 |
}
|
|
|
253 |
} catch(\Throwable $e) {
|
|
|
254 |
error_log($e->getTraceAsString());
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
$this->logger->info('Se agrego la noticia ' . $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
259 |
|
|
|
260 |
$data = [
|
|
|
261 |
'success' => true,
|
|
|
262 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
263 |
];
|
|
|
264 |
} else {
|
|
|
265 |
$data = [
|
|
|
266 |
'success' => false,
|
|
|
267 |
'data' => $postMapper->getError()
|
|
|
268 |
];
|
|
|
269 |
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
return new JsonModel($data);
|
|
|
273 |
|
|
|
274 |
} else {
|
|
|
275 |
$messages = [];
|
|
|
276 |
$form_messages = (array) $form->getMessages();
|
|
|
277 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
278 |
{
|
|
|
279 |
|
|
|
280 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
return new JsonModel([
|
|
|
284 |
'success' => false,
|
|
|
285 |
'data' => $messages
|
|
|
286 |
]);
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
} else {
|
|
|
290 |
$data = [
|
|
|
291 |
'success' => false,
|
|
|
292 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
293 |
];
|
|
|
294 |
|
|
|
295 |
return new JsonModel($data);
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
return new JsonModel($data);
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
/**
|
|
|
302 |
*
|
|
|
303 |
* Borrar un perfil excepto el público
|
|
|
304 |
* @return \Laminas\View\Model\JsonModel
|
|
|
305 |
*/
|
|
|
306 |
public function deleteAction()
|
|
|
307 |
{
|
|
|
308 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
309 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
310 |
|
|
|
311 |
$request = $this->getRequest();
|
|
|
312 |
$id = $this->params()->fromRoute('id');
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
|
316 |
$postMapper = PostMapper::getInstance($this->adapter);
|
15347 |
efrain |
317 |
$post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
1 |
www |
318 |
|
|
|
319 |
if(!$post) {
|
|
|
320 |
return new JsonModel([
|
|
|
321 |
'success' => false,
|
|
|
322 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
323 |
]);
|
|
|
324 |
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
if($request->isPost()) {
|
|
|
329 |
|
|
|
330 |
$post->status = Post::STATUS_DELETE;
|
|
|
331 |
|
|
|
332 |
$result = $postMapper->update($post);
|
|
|
333 |
if($result) {
|
|
|
334 |
$this->logger->info('Se borro la noticia : ' . $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
$data = [
|
|
|
338 |
'success' => true,
|
|
|
339 |
'data' => 'LABEL_POST_DELETED'
|
|
|
340 |
];
|
|
|
341 |
} else {
|
|
|
342 |
|
|
|
343 |
$data = [
|
|
|
344 |
'success' => false,
|
|
|
345 |
'data' => $postMapper->getError()
|
|
|
346 |
];
|
|
|
347 |
|
|
|
348 |
return new JsonModel($data);
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
} else {
|
|
|
352 |
$data = [
|
|
|
353 |
'success' => false,
|
|
|
354 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
355 |
];
|
|
|
356 |
|
|
|
357 |
return new JsonModel($data);
|
|
|
358 |
}
|
|
|
359 |
|
|
|
360 |
return new JsonModel($data);
|
|
|
361 |
}
|
|
|
362 |
|
|
|
363 |
|
|
|
364 |
public function editAction()
|
|
|
365 |
{
|
|
|
366 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
367 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
368 |
|
|
|
369 |
$request = $this->getRequest();
|
|
|
370 |
$id = $this->params()->fromRoute('id');
|
|
|
371 |
|
|
|
372 |
$postMapper = PostMapper::getInstance($this->adapter);
|
15347 |
efrain |
373 |
$post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
1 |
www |
374 |
|
|
|
375 |
if(!$post) {
|
|
|
376 |
return new JsonModel([
|
|
|
377 |
'success' => false,
|
|
|
378 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
379 |
]);
|
|
|
380 |
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
|
|
|
384 |
if($request->isGet()) {
|
|
|
385 |
|
|
|
386 |
$dt = \DateTime::createFromFormat('Y-m-d', $post->date);
|
|
|
387 |
|
|
|
388 |
$data = [
|
|
|
389 |
'success' => true,
|
|
|
390 |
'data' => [
|
|
|
391 |
'title' => $post->title,
|
|
|
392 |
'status' => $post->status,
|
|
|
393 |
'description' => $post->description,
|
|
|
394 |
'url' => $post->url,
|
|
|
395 |
'date' => $dt->format('d/m/Y'),
|
|
|
396 |
]
|
|
|
397 |
];
|
|
|
398 |
|
|
|
399 |
return new JsonModel($data);
|
|
|
400 |
}
|
|
|
401 |
else if($request->isPost()) {
|
|
|
402 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
403 |
$dataPost['status'] = empty($dataPost['status']) ? Post::STATUS_INACTIVE : $dataPost['status'];
|
|
|
404 |
|
|
|
405 |
$form = new PostEditForm();
|
|
|
406 |
$form->setData($dataPost);
|
|
|
407 |
|
|
|
408 |
if($form->isValid()) {
|
|
|
409 |
$dataPost = (array) $form->getData();
|
|
|
410 |
|
15078 |
efrain |
411 |
|
|
|
412 |
$post->title = $dataPost['title'];
|
|
|
413 |
$post->description = $dataPost['description'];
|
|
|
414 |
$post->url = isset($dataPost['url']) ? $dataPost['url'] : '';
|
|
|
415 |
$post->status = isset($dataPost['status']) ? $dataPost['status'] : Post::STATUS_INACTIVE;
|
|
|
416 |
|
|
|
417 |
$dt = \DateTime::createFromFormat('d/m/Y',$dataPost['date']);
|
1 |
www |
418 |
$post->date = $dt->format('Y-m-d');
|
|
|
419 |
|
|
|
420 |
|
15078 |
efrain |
421 |
|
|
|
422 |
|
1 |
www |
423 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
424 |
|
|
|
425 |
$target_path = $this->config['leaderslinked.fullpath.post'] . $post->uuid;
|
|
|
426 |
if(!file_exists($target_path)) {
|
|
|
427 |
mkdir($target_path, 0755, true);
|
|
|
428 |
}
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
if(isset($files['file']) && empty($files['file']['error'])) {
|
|
|
432 |
|
|
|
433 |
if($post->file) {
|
|
|
434 |
Functions::deleteFilename($target_path, $post->file);
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
|
|
|
438 |
$tmp_filename = $files['file']['tmp_name'];
|
|
|
439 |
$original_filename = trim(strtolower($files['file']['name']));
|
|
|
440 |
|
|
|
441 |
$original_filename = Functions::normalizeString($original_filename);
|
|
|
442 |
|
|
|
443 |
$parts = explode('.', $original_filename);
|
|
|
444 |
$original_filename = $parts[0] . '.' . $parts[ count($parts) - 1 ];
|
|
|
445 |
|
|
|
446 |
try
|
|
|
447 |
{
|
|
|
448 |
$full_filename = $target_path . DIRECTORY_SEPARATOR .$original_filename;
|
|
|
449 |
if(move_uploaded_file($tmp_filename, $full_filename)) {
|
|
|
450 |
$post->file = basename($full_filename);
|
|
|
451 |
$post->update($post);
|
|
|
452 |
}
|
|
|
453 |
} catch(\Throwable $e) {
|
|
|
454 |
error_log($e->getTraceAsString());
|
|
|
455 |
}
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
if(isset($files['image']) && empty($files['image']['error'])) {
|
|
|
459 |
|
|
|
460 |
if($post->image) {
|
|
|
461 |
Functions::deleteFilename($target_path, $post->image);
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
|
|
|
465 |
$tmp_filename = $files['image']['tmp_name'];
|
|
|
466 |
|
|
|
467 |
try {
|
|
|
468 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.post']);
|
|
|
469 |
|
|
|
470 |
$filename = 'image-' .uniqid() . '.png';
|
|
|
471 |
$crop_to_dimensions = true;
|
|
|
472 |
if(Image::uploadImage($tmp_filename, $target_path, $filename, $target_width, $target_height, $crop_to_dimensions)) {
|
|
|
473 |
$post->image = $filename;
|
|
|
474 |
$postMapper->update($post);
|
|
|
475 |
}
|
|
|
476 |
} catch(\Throwable $e) {
|
|
|
477 |
error_log($e->getTraceAsString());
|
|
|
478 |
}
|
15078 |
efrain |
479 |
}
|
|
|
480 |
|
1 |
www |
481 |
|
|
|
482 |
|
|
|
483 |
if($postMapper->update($post)) {
|
|
|
484 |
$this->logger->info('Se edito la noticia ' . $post->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
485 |
|
|
|
486 |
$data = [
|
|
|
487 |
'success' => true,
|
|
|
488 |
'data' => 'LABEL_RECORD_UPDATED'
|
|
|
489 |
];
|
|
|
490 |
} else {
|
|
|
491 |
$data = [
|
|
|
492 |
'success' => false,
|
|
|
493 |
'data' => $postMapper->getError()
|
|
|
494 |
];
|
|
|
495 |
|
|
|
496 |
}
|
|
|
497 |
|
|
|
498 |
return new JsonModel($data);
|
|
|
499 |
|
|
|
500 |
} else {
|
|
|
501 |
$messages = [];
|
|
|
502 |
$form_messages = (array) $form->getMessages();
|
|
|
503 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
504 |
{
|
|
|
505 |
|
|
|
506 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
507 |
}
|
|
|
508 |
|
|
|
509 |
return new JsonModel([
|
|
|
510 |
'success' => false,
|
|
|
511 |
'data' => $messages
|
|
|
512 |
]);
|
|
|
513 |
}
|
|
|
514 |
} else {
|
|
|
515 |
$data = [
|
|
|
516 |
'success' => false,
|
|
|
517 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
518 |
];
|
|
|
519 |
|
|
|
520 |
return new JsonModel($data);
|
|
|
521 |
}
|
|
|
522 |
|
|
|
523 |
return new JsonModel($data);
|
|
|
524 |
}
|
|
|
525 |
|
|
|
526 |
|
|
|
527 |
}
|