';
} else {
$html = '
';
}
return $html . '
' . $title . '
' . join($elements) . '';
}
/**
* Renders a description based on the data arrays key and values as label an description.
*
* @param array $data
* @return string
*/
function description($data)
{
$elements = [];
foreach ($data as $label => $description) {
if (!empty($label) && !empty($description)) {
$elements[] = '
' . $label . '' . $description . '';
}
}
return '
' . join($elements) . '
';
}
/**
* Rendert eine Datentabelle
*
* @param array|string $columns
* @param array[] $rows_raw
* @param bool $data
* @return string
*/
function table($columns, $rows_raw, $data = true)
{
// If only one column is given
if (!is_array($columns)) {
$rows = [];
foreach ($rows_raw as $row) {
$rows[] = [
'col' => $row
];
}
return render_table([
'col' => $columns
], $rows, $data);
}
return render_table($columns, $rows_raw, $data);
}
/**
* Helper for rendering a html-table.
* use table()
*
* @param string[] $columns
* @param array[] $rows
* @param bool $data
* @return string
*/
function render_table($columns, $rows, $data = true)
{
if (count($rows) == 0) {
return info(__('No data found.'), true);
}
$html = '
';
$html .= '';
foreach ($columns as $key => $column) {
$html .= '' . $column . ' | ';
}
$html .= '
';
$html .= '';
foreach ($rows as $row) {
$html .= '';
foreach ($columns as $key => $column) {
$value = " ";
if (isset($row[$key])) {
$value = $row[$key];
}
$html .= '' . $value . ' | ';
}
$html .= '
';
}
$html .= '';
$html .= '
';
return $html;
}
/**
* Rendert einen Knopf
*
* @param string $href
* @param string $label
* @param string $class
* @return string
*/
function button($href, $label, $class = '')
{
if (!Str::contains(str_replace(['btn-sm', 'btn-xl'], '', $class), 'btn-')) {
$class = 'btn-secondary' . ($class ? ' ' . $class : '');
}
return '
' . $label . '';
}
/**
* Rendert einen Knopf mit JavaScript onclick Handler
*
* @param string $javascript
* @param string $label
* @param string $class
* @return string
*/
function button_js($javascript, $label, $class = '')
{
return '
' . $label . '';
}
/**
* Renders a button with an icon
*
* @param string $href
* @param string $icon
* @param string $class
*
* @return string
*/
function button_icon($href, $icon, $class = '')
{
return button($href, icon($icon), $class);
}
/**
* Rendert einen Knopf, der zur Hilfe eines bestimmten Themas führt.
*
* @param string $topic documentation resource (like user/), is appended to documentation url.
* @return string
*/
function button_help($topic = '')
{
return button(config('documentation_url') . $topic, icon('question-circle'), 'btn-sm');
}
/**
* Rendert eine Toolbar mit Knöpfen
*
* @param array $buttons
* @return string
*/
function buttons($buttons = [])
{
return '
' . table_buttons($buttons) . '
';
}
/**
* @param array $buttons
* @return string
*/
function table_buttons($buttons = [])
{
return '
' . join(' ', $buttons) . '
';
}