2013-09-18 01:38:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Returns messages from session and removes them from the stack
|
2022-12-08 17:40:24 +01:00
|
|
|
* @param bool $includeMessagesFromNewProcedure
|
|
|
|
* If set, the messages from the new procedure are also included.
|
|
|
|
* The output will be similar to how it would be with messages.twig.
|
|
|
|
* @see \Engelsystem\Controllers\HasUserNotifications
|
2017-01-03 03:22:48 +01:00
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
2022-12-08 17:40:24 +01:00
|
|
|
function msg(bool $includeMessagesFromNewProcedure = false)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-08-30 19:57:01 +02:00
|
|
|
$session = session();
|
|
|
|
|
|
|
|
$message = $session->get('msg', '');
|
|
|
|
$session->set('msg', '');
|
|
|
|
|
2022-12-08 17:40:24 +01:00
|
|
|
if ($includeMessagesFromNewProcedure) {
|
|
|
|
foreach (session()->get('errors', []) as $msg) {
|
|
|
|
$message .= error(__($msg), true);
|
|
|
|
}
|
|
|
|
foreach (session()->get('warnings', []) as $msg) {
|
|
|
|
$message .= warning(__($msg), true);
|
|
|
|
}
|
|
|
|
foreach (session()->get('information', []) as $msg) {
|
|
|
|
$message .= info(__($msg), true);
|
|
|
|
}
|
|
|
|
foreach (session()->get('messages', []) as $msg) {
|
|
|
|
$message .= success(__($msg), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (['errors', 'warnings', 'information', 'messages'] as $type) {
|
|
|
|
session()->remove($type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 19:57:01 +02:00
|
|
|
return $message;
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Renders an information message
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
2017-01-03 03:22:48 +01:00
|
|
|
function info($msg, $immediately = false)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-01-03 03:22:48 +01:00
|
|
|
return alert('info', $msg, $immediately);
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Renders a warning message
|
|
|
|
*
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function warning($msg, $immediately = false)
|
|
|
|
{
|
|
|
|
return alert('warning', $msg, $immediately);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders an error message
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
2017-01-03 03:22:48 +01:00
|
|
|
function error($msg, $immediately = false)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-01-03 03:22:48 +01:00
|
|
|
return alert('danger', $msg, $immediately);
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Renders a success message
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
|
|
|
* @return string
|
2013-09-18 01:38:36 +02:00
|
|
|
*/
|
2017-01-03 03:22:48 +01:00
|
|
|
function success($msg, $immediately = false)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-01-03 03:22:48 +01:00
|
|
|
return alert('success', $msg, $immediately);
|
2016-09-29 09:49:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-26 14:35:01 +01:00
|
|
|
* Renders an alert message with the given alert-* class.
|
2017-01-03 03:22:48 +01:00
|
|
|
*
|
|
|
|
* @param string $class
|
|
|
|
* @param string $msg
|
|
|
|
* @param bool $immediately
|
2017-08-31 12:25:06 +02:00
|
|
|
* @return string
|
2016-09-29 09:49:25 +02:00
|
|
|
*/
|
2017-01-03 03:22:48 +01:00
|
|
|
function alert($class, $msg, $immediately = false)
|
2017-01-02 03:57:23 +01:00
|
|
|
{
|
2017-08-31 12:25:06 +02:00
|
|
|
if (empty($msg)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2017-01-03 03:22:48 +01:00
|
|
|
if ($immediately) {
|
2023-01-17 15:05:47 +01:00
|
|
|
return '<div class="alert alert-' . $class . '" role="alert">' . $msg . '</div>';
|
2016-09-29 09:49:25 +02:00
|
|
|
}
|
2017-01-02 15:43:36 +01:00
|
|
|
|
2018-08-11 23:46:28 +02:00
|
|
|
$session = session();
|
2017-08-30 19:57:01 +02:00
|
|
|
$message = $session->get('msg', '');
|
|
|
|
$message .= alert($class, $msg, true);
|
|
|
|
$session->set('msg', $message);
|
2017-01-03 03:22:48 +01:00
|
|
|
|
2017-08-31 12:25:06 +02:00
|
|
|
return '';
|
2013-09-18 01:38:36 +02:00
|
|
|
}
|