0, and success if number == 0. * * @param string $label * @param string $number * @param string $style default, warning, danger or success. Optional. * @return string */ function stats($label, $number, $style = null) { if (empty($style)) { if ($number > 0) { $style = 'danger'; } else { $style = 'success'; } } return div('stats stats-' . $style, [ $label, div('number', [ $number ]) ]); } /** * Renders tabs from the array. Array key is tab name, array value is tab content. * * @param array $tabs * @param int $selected The selected tab, default 0 * @return string HTML */ function tabs($tabs, $selected = 0) { $tab_header = []; $tab_content = []; foreach ($tabs as $header => $content) { $active = false; $id = $header; $href = '#' . $id; if (count($tab_header) == $selected) { $active = true; } if (is_array($content)) { $href = $content['href']; $content = null; $id = null; } $tab_header[] = ''; $tab_content[] = $content ? '
' . $content . '
' : ''; } return div('', [ '', '
' . join($tab_content) . '
' ]); } /** * Display muted (grey) text. * * @param string $text * @return string */ function mute($text) { return '' . $text . ''; } /** * Renders a bootstrap label with given content and class. * * @param string $content The text * @param string $class default, primary, info, success, warning, danger * @return string */ function badge($content, $class = 'default') { return '' . $content . ''; } /** * @param int $valuemin * @param int $valuemax * @param int $valuenow * @param string $class * @param string $content * @return string */ function progress_bar($valuemin, $valuemax, $valuenow, $class = '', $content = '') { return '
' . '
' . $content . '' . '
' . '
'; } /** * Render bootstrap icon * * @param string $icon_name * @param string $class * * @return string */ function icon(string $icon_name, string $class = ''): string { return ' '; } /** * Renders a tick or a cross by given boolean * * @param boolean $boolean * @return string */ function icon_bool($boolean) { return '' . icon($boolean ? 'check-lg' : 'x-lg') . ''; } /** * @param string $class * @param array $content * @param string $dom_id * @return string */ function div($class, $content = [], $dom_id = '') { if (is_array($content)) { $content = join("\n", $content); } $dom_id = $dom_id != '' ? ' id="' . $dom_id . '"' : ''; return '' . $content . ''; } /** * @param string $content * @param int $number * @return string */ function heading($content, $number = 1) { return '' . $content . ''; } /** * @param string[] $items * @return string */ function toolbar_pills($items) { return ''; } /** * Render a link for a toolbar. * * @param string $href * @param string $icon * @param string $label * @param bool $active * @return string */ function toolbar_item_link($href, $icon, $label, $active = false) { return ''; } function toolbar_dropdown_item(string $href, string $label, bool $active, string $icon = null): string { return strtr( '
  • {icon} {label}
  • ', [ '{href}' => $href, '{icon}' => $icon === null ? '' : '', '{label}' => $label, '{active}' => $active ? ' active' : '' ] ); } function toolbar_dropdown_item_divider(): string { return '
  • '; } /** * @param string $icon * @param string $label * @param array $submenu * @param string $class * @return string */ function toolbar_dropdown($icon, $label, $submenu, $class = ''): string { $template =<< EOT; return strtr( $template, [ '{class}' => $class, '{label}' => $label, '{icon}' => empty($icon) ? '' : '', '{submenu}' => join("\n", $submenu) ] ); } /** * @param string $icon * @param string $label * @param string[] $content * @param string $class * * @return string */ function toolbar_popover($icon, $label, $content, $class = '') { $dom_id = md5(microtime() . $icon . $label); return ''; } /** * Generiert HTML Code für eine "Seite". * Fügt dazu die übergebenen Elemente zusammen. * * @param string[] $elements * @return string */ function page($elements) { return join($elements); } /** * Generiert HTML Code für eine "Seite" mit zentraler Überschrift * Fügt dazu die übergebenen Elemente zusammen. * * @param string $title * @param string[] $elements * @param bool $container * @return string */ function page_with_title($title, $elements, bool $container = false) { if ($container) { $html = '
    '; } 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 .= ''; } $html .= ''; $html .= ''; foreach ($rows as $row) { $html .= ''; foreach ($columns as $key => $column) { $value = " "; if (isset($row[$key])) { $value = $row[$key]; } $html .= ''; } $html .= ''; } $html .= ''; $html .= '
    ' . $column . '
    ' . $value . '
    '; return $html; } /** * Rendert einen Knopf * * @param string $href * @param string $label * @param string $class * @return string */ function button($href, $label, $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) . '
    '; }