engelsystem/includes/view/UserHintsRenderer.php

69 lines
1.4 KiB
PHP
Raw Normal View History

2016-11-15 16:28:20 +01:00
<?php
namespace Engelsystem;
2017-01-02 03:57:23 +01:00
class UserHintsRenderer
{
2017-01-03 03:22:48 +01:00
/** @var string[] */
2017-01-02 03:57:23 +01:00
private $hints = [];
2016-11-15 16:28:20 +01:00
2017-01-02 03:57:23 +01:00
private $important = false;
2016-11-15 16:28:20 +01:00
2017-01-02 15:43:36 +01:00
/**
* Render the added hints to a popover for the toolbar.
2017-01-03 03:22:48 +01:00
*
* @return string
2017-01-02 15:43:36 +01:00
*/
public function render()
{
if (count($this->hints) > 0) {
$hint_class = $this->important ? 'danger' : 'info';
$icon = $this->important ? 'exclamation-triangle' : 'info-circle';
2017-01-02 15:43:36 +01:00
2017-12-25 23:12:52 +01:00
return toolbar_popover(
2021-07-24 12:38:23 +02:00
$icon . ' text-white', '', $this->hints, 'bg-' . $hint_class
2017-12-25 23:12:52 +01:00
);
2017-01-02 15:43:36 +01:00
}
return '';
}
/**
* Add a hint to the list, if its not null and a not empty string.
*
2017-01-03 03:22:48 +01:00
* @param string $hint The hint
* @param boolean $important Is the hint important?
2017-01-02 15:43:36 +01:00
*/
public function addHint($hint, $important = false)
{
2018-01-14 17:47:26 +01:00
if (!empty($hint)) {
2017-01-02 15:43:36 +01:00
if ($important) {
$this->important = true;
$this->hints[] = error($hint, true);
} else {
$this->hints[] = info($hint, true);
}
}
}
/**
* Get all hints.
2017-01-03 03:22:48 +01:00
*
* @return string[]
2017-01-02 15:43:36 +01:00
*/
public function getHints()
{
return $this->hints;
}
/**
* Are there important hints? This leads to a more intensive icon.
2017-01-03 03:22:48 +01:00
*
* @return bool
2017-01-02 15:43:36 +01:00
*/
public function isImportant()
{
return $this->important;
}
2016-11-15 16:28:20 +01:00
}