engelsystem/includes/helper/message_helper.php

92 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/**
* Returns messages from session and removes them from the stack
2017-01-03 03:22:48 +01:00
*
* @return string
*/
2017-01-02 03:57:23 +01:00
function msg()
{
2017-08-30 19:57:01 +02:00
$session = session();
$message = $session->get('msg', '');
$session->set('msg', '');
return $message;
}
/**
* Renders an information message
2017-01-03 03:22:48 +01:00
*
* @param string $msg
* @param bool $immediately
* @return string
*/
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);
}
/**
* 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
*/
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);
}
/**
* Renders a success message
2017-01-03 03:22:48 +01:00
*
* @param string $msg
* @param bool $immediately
* @return string
*/
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);
}
/**
* 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
* @return string
*/
2017-01-03 03:22:48 +01:00
function alert($class, $msg, $immediately = false)
2017-01-02 03:57:23 +01:00
{
2017-08-30 19:57:01 +02:00
$session = session();
if (empty($msg)) {
return '';
}
2017-01-03 03:22:48 +01:00
if ($immediately) {
2017-01-02 03:57:23 +01:00
return '<div class="alert alert-' . $class . '">' . $msg . '</div>';
}
2017-01-02 15:43:36 +01:00
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
return '';
}