class AjaxController extends AbstractController
{
/**
- * Messages
+ * Messages as JSON array
*
* @param Request $request PSR Request
* @param Response $response PSR Response
*/
public function messages(Request $request, Response $response): Response
{
- $this->view->render(
- $response,
- 'elements/ajax_messages.html.twig'
- );
- return $response;
+ $messages = [];
+
+ $errors = $this->flash->getMessage('loginfault') ?? [];
+ $errors = array_merge($errors, $this->flash->getMessage('error_detected') ?? []);
+ $errors = array_merge($errors, $this->flash->getMessage('error') ?? []);
+
+ if (count($errors) > 0) {
+ $messages['error'] = [
+ 'title' => _T('- ERROR -'),
+ 'icon' => 'exclamation circle',
+ 'messages' => $errors
+ ];
+ }
+
+ $warnings = $this->flash->getMessage('warning_detected') ?? [];
+ $warnings = array_merge($warnings, $this->flash->getMessage('warning') ?? []);
+
+ if (count($warnings) > 0) {
+ $messages['warning'] = [
+ 'title' => _T('- WARNING -'),
+ 'icon' => 'exclamation triangle',
+ 'messages' => $warnings
+ ];
+ }
+
+ $info = $this->flash->getMessage('info_detected') ?? [];
+ $info = array_merge($info, $this->flash->getMessage('info') ?? []);
+
+ if (count($info) > 0) {
+ $messages['info'] = [
+ 'title' => '',
+ 'icon' => 'info',
+ 'messages' => $info
+ ];
+ }
+
+ $success = $this->flash->getMessage('success_detected') ?? [];
+ $success = array_merge($success, $this->flash->getMessage('succes') ?? []);
+
+ if (count($success) > 0) {
+ $messages['success'] = [
+ 'title' => '',
+ 'icon' => 'check circle outline',
+ 'messages' => $success
+ ];
+ }
+
+ return $this->withJson($response, $messages);
}
/**