Skip to content
Snippets Groups Projects

Update renderer class

Merged Hahn Axel (hahn) requested to merge update_renderer_class into main
1 file
+ 37
1
Compare changes
  • Side-by-side
  • Inline
<?php
require_once 'htmlelements.class.php';
/**
* ======================================================================
* ______________________________________________________________________
*
* _ __ __ _
* | || \/ || |__ Institute for Medical Education
* |_||_|\/|_||____| University of Bern
*
* ______________________________________________________________________
*
* RENDERER FOR ADNINLTE template https://adminlte.io
* DOCS: https://adminlte.io/docs/3.2/
* its docs: https://adminlte.io/docs/3.2/
* https://adminlte.io/themes/v3/index3.html
*
* This is a php class to render
* - grid layout
* - navigation
* - widgets, components and forms
*
* DOCS: https://os-docs.iml.unibe.ch/adminlte-renderer/
* ----------------------------------------------------------------------
* 2023-09-11 <axel.hahn@unibe.ch> add shadows on card + callout
* 2023-09-27 <axel.hahn@unibe.ch> add form input fields
* 2023-11-17 <axel.hahn@unibe.ch> add tabbed content; "=" renders hamburger item
* 2024-05-03 <axel.hahn@unibe.ch> add line in sidebar menu; add getFormSelect
* 2024-05-10 <axel.hahn@unibe.ch> add support for bootstrap-select in getFormSelect
* 2024-05-18 <axel.hahn@unibe.ch> add variable types
* 2024-07-04 <axel.hahn@unibe.ch> added type declarations
* ======================================================================
*
* @author Axel
*/
class renderadminlte {
class renderadminlte
{
var $aPresets=[
protected array $aPresets = [
'bgcolor' => [
'description' => 'background colors',
@@ -123,7 +137,7 @@ class renderadminlte {
],
];
var $_aValueMappings=[
protected array $_aValueMappings = [
'shadow' => [
'default' => '',
'none' => 'shadow-none',
@@ -133,13 +147,13 @@ class renderadminlte {
]
];
var $_aElements=[];
protected array $_aElements = [];
/**
* instance of htmlelements
* instance of htmlelements object
* @var object
*/
var $_oHtml=false;
protected object $_oHtml;
// ----------------------------------------------------------------------
@@ -147,10 +161,11 @@ class renderadminlte {
// CONSTRUCTOR
//
// ----------------------------------------------------------------------
public function __construct() {
public function __construct()
{
$this->_oHtml = new htmlelements();
$this->_initElements();
return true;
// return true;
}
// ----------------------------------------------------------------------
@@ -162,8 +177,10 @@ class renderadminlte {
/**
* used in cosntructor
* initialize all element definitions
* @return void
*/
protected function _initElements(){
protected function _initElements(): void
{
$this->_aElements = [
// ------------------------------------------------------------
@@ -395,14 +412,11 @@ class renderadminlte {
'description' => 'label for the input field',
'example_value' => 'Enter something'
],
'type'=>['select'=> [
'type' => [
'select' => [
'description' => 'type or input field',
'group' => 'styling',
'values' => [
'text'=>'text',
'password'=>'password',
'email'=>'email',
'hidden'=>'hidden',
'button' => 'button',
'checkbox' => 'checkbox',
@@ -458,6 +472,43 @@ class renderadminlte {
]
],
// ------------------------------------------------------------
// WIP
'select' => [
'label' => 'Form: select',
'description' => 'Select box',
'method' => 'getFormSelect',
'params' => [
'label' => [
'group' => 'styling',
'description' => 'label for the select field',
'example_value' => 'Enter text'
],
'bootstrap-select' => [
'select' => [
'description' => 'Enable bootstrap-select plugin',
'group' => 'styling',
'values' => [
'0' => 'no',
'1' => 'yes',
]
]
],
'class' => [
'group' => 'styling',
'description' => 'optional: css classes',
'example_value' => 'myclass'
],
'options' => [
'example_value' => [
["value" => "1", "label" => "one"],
["value" => "2", "label" => "two"],
["value" => "3", "label" => "three"],
],
]
],
],
// ------------------------------------------------------------
'textarea' => [
'label' => 'Form: textarea',
'description' => 'textarea or html editor',
@@ -469,7 +520,8 @@ class renderadminlte {
'description' => 'label for the input field',
'example_value' => 'Enter text'
],
'type'=>['select'=> [
'type' => [
'select' => [
'description' => 'type or input field',
'group' => 'styling',
'values' => [
@@ -503,8 +555,10 @@ class renderadminlte {
* @param array $aAttributes array of its attributes
* @param string $sContent content between opening and closing tag
* @param bool $bClosetag flag: write a closing tag or not? default: true
* @return string
*/
protected function _tag($sTag, $aAttributes, $sContent=false, $bClosetag=true){
protected function _tag(string $sTag, array $aAttributes, string $sContent = '', bool $bClosetag = true): string
{
if ($sContent) {
$aAttributes['label'] = (isset($aAttributes['label']) ? $aAttributes['label'] : '') . $sContent;
}
@@ -520,8 +574,10 @@ class renderadminlte {
* render a page by using template
* @param string $stemplate html template with placeholders
* @param array $aReplace key = what to replace .. value = new value
* @return string
*/
public function render($sTemplate, $aReplace){
public function render(string $sTemplate, array $aReplace): string
{
return str_replace(
array_keys($aReplace),
array_values($aReplace),
@@ -529,16 +585,18 @@ class renderadminlte {
);
}
/**
* add a wrapper: wrap some content into a tag
*
* @param string $sTag name of html tag
* @param array $aOptions array of its attributes
* @param string $sContent html content inside
* @return string
*/
public function addWrapper($sTag, $aOptions, $sContent){
public function addWrapper(string $sTag, array $aOptions, string $sContent): string
{
$aOptions['label'] = $sContent;
return $this->_tag($sTag, $aOptions)."\n";
return $this->_tag($sTag, $aOptions) . PHP_EOL;
}
// ----------------------------------------------------------------------
@@ -547,7 +605,6 @@ class renderadminlte {
//
// ----------------------------------------------------------------------
/**
* get a single navigation item on top bar
*
@@ -555,7 +612,8 @@ class renderadminlte {
* @param integer $iLevel Menu level; 1=top bar; 2=pupup menu with subitems
* @return string
*/
public function getNavItem($aLink, $iLevel=1){
public function getNavItem(array $aLink, int $iLevel = 1): string
{
static $iCounter;
if (!isset($iCounter)) {
$iCounter = 0;
@@ -563,14 +621,20 @@ class renderadminlte {
switch ($aLink['label']) {
// special menu entry: horizontal bar (label is "-")
case '-': return '<div class="dropdown-divider"></div>'; break;
case '-':
return '<div class="dropdown-divider"></div>';
break;
// special menu entry: hamburger menu item (label is "=")
case '=': return '<li class="nav-item"><a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a></li>'; break;
case '=':
return '<li class="nav-item"><a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a></li>';
break;
// special menu entry: hamburger menu item (label is "|")
// requires css: .navbar-nav li.divider{border-left: 1px solid rgba(0,0,0,0.2);}
case '|': return '<li class="divider"></li>'; break;
case '|':
return '<li class="divider"></li>';
break;
}
$aChildren = isset($aLink['children']) && is_array($aLink['children']) && count($aLink['children']) ? $aLink['children'] : false;
@@ -615,11 +679,16 @@ class renderadminlte {
}
return $sReturn;
}
/**
* get a navigation item for top bar
* get html code for navigation on top bar
*
* @param array $aLinks array of navigation items
* @param int $iLevel current navigation level; default: 1
* @return string|bool
*/
public function getNavItems($aLinks, $iLevel=1){
public function getNavItems(array $aLinks, int $iLevel = 1): string|bool
{
$sReturn = '';
if (!$aLinks || !is_array($aLinks) || !count($aLinks)) {
return false;
@@ -629,6 +698,7 @@ class renderadminlte {
}
return $sReturn;
}
/**
* get a top left navigation for a top navigation bar
*
@@ -650,14 +720,17 @@ class renderadminlte {
* .'</nav>'
* </code>
*
* @param array $aNavitems array of navigation items/ tree
* @param array $aNavItems array of navigation items/ tree
* @param array $aUlOptions array of html attrubutes for wrapping UL tag
* @param array $aNavItemsRight array of html attrubutes for wrapping UL tag
* @param array $aUlOptionsRight array of html attrubutes for wrapping UL tag
* @return string
*/
public function getTopNavigation($aNavItems, $aUlOptions=false, $aNavItemsRight=[], $aUlOptionsRight=false){
public function getTopNavigation(array $aNavItems, array $aUlOptions = [], array $aNavItemsRight = [], array $aUlOptionsRight = []): string
{
// array_unshift($aNavItems, ['class'=>'nav-link', 'data-widget'=>'pushmenu', 'href'=>'#', 'role'=>'button', 'label'=>'<i class="fa-solid fa-bars"></i>']);
$aUlOptLeft=$aUlOptions ? $aUlOptions : ['class'=>'navbar-nav'];
$aUlOptRight=$aUlOptionsRight ? $aUlOptionsRight : ['class'=>'navbar-nav ml-auto'];
$aUlOptLeft = count($aUlOptions) ? $aUlOptions : ['class' => 'navbar-nav'];
$aUlOptRight = count($aUlOptionsRight) ? $aUlOptionsRight : ['class' => 'navbar-nav ml-auto'];
return $this->addWrapper('ul', $aUlOptLeft, $this->getNavItems($aNavItems))
. (count($aNavItemsRight)
? $this->addWrapper('ul', $aUlOptRight, $this->getNavItems($aNavItemsRight))
@@ -677,8 +750,10 @@ class renderadminlte {
* .nav-item hr{color: #505860; border-top: 1px solid; height: 1px; padding: 0; margin: 0; }
*
* @param array $aLinks list of link items
* @return string|bool
*/
public function getNavi2Items($aLinks){
public function getNavi2Items(array $aLinks): string|bool
{
$sReturn = '';
if (!$aLinks || !is_array($aLinks) || !count($aLinks)) {
return false;
@@ -704,7 +779,8 @@ class renderadminlte {
}
$aLink['label'] = $this->addWrapper('p', [], $aLink['label']);
$sReturn .= $this->addWrapper(
'li', ['class'=>$aLiClass],
'li',
['class' => $aLiClass],
$this->_tag('a', $aLink) . $sSubmenu
) . "\n";
}
@@ -712,17 +788,24 @@ class renderadminlte {
}
/**
* get html code for sidebar navigation
*
* @param array $aNavItems navigation item
* @param array $aUlOptions aatributes for UL tag
* @param string
*/
public function getSidebarNavigation($aNavItems, $aUlOptions=[
public function getSidebarNavigation(
array $aNavItems,
array $aUlOptions = [
'class' => 'nav nav-pills nav-sidebar flex-column nav-flat_ nav-child-indent',
'data-widget' => 'treeview',
'role' => 'menu',
'data-accordion' => 'false'
])
{
]
): string {
return $this->addWrapper(
'ul', $aUlOptions,
'ul',
$aUlOptions,
$this->getNavi2Items($aNavItems)
) . "\n";
}
@@ -739,7 +822,8 @@ class renderadminlte {
* @param string $sContent html content inside
* @return string
*/
public function addRow($sContent){
public function addRow(string $sContent): string
{
return $this->addWrapper('div', ['class' => 'row'], $sContent);
}
@@ -751,7 +835,8 @@ class renderadminlte {
* @param string $sFloat css value for float attribute; default=false
* @return string
*/
public function addCol($sContent, $iCols=6, $sFloat=false){
public function addCol(string $sContent, int $iCols = 6, string $sFloat = ''): string
{
return $this->addWrapper('div', ['class' => 'col-md-' . $iCols, 'style' => 'float:' . $sFloat], $sContent);
}
@@ -761,24 +846,26 @@ class renderadminlte {
//
// ----------------------------------------------------------------------
/**
* get a list of all defined components that can be rendered
* @param {bool} $bSendData flag: send including subkeys of the hash; default: false (keys only)
* @return {array}
* @param bool $bSendData flag: send including subkeys of the hash; default: false (keys only)
* @return array
*/
public function getComponents($bSendData=false){
public function getComponents(bool $bSendData = false): array
{
return $bSendData
? $this->_aElements
: array_keys($this->_aElements)
;
}
/**
* get data of a component
* @param {string} $sComponent id of the component
* @return {array}
* @param string $sComponent id of the component
* @return array|bool
*/
public function getComponent($sComponent){
public function getComponent(string $sComponent): array|bool
{
if (!isset($this->_aElements[$sComponent])) {
return false;
}
@@ -789,11 +876,12 @@ class renderadminlte {
/**
* get parameter keys of a component
* @param {string} $sComponent id of the component
* @param {bool} $bSendData flag: send including subkeys of the hash; default: false (keys only)
* @return {array}
* @param string $sComponent id of the component
* @param bool $bSendData flag: send including subkeys of the hash; default: false (keys only)
* @return array|bool
*/
public function getComponentParamkeys($sComponent, $bSendData=false){
public function getComponentParamkeys(string $sComponent, bool $bSendData = false)
{
if (!isset($this->_aElements[$sComponent])) {
return false;
}
@@ -811,11 +899,12 @@ class renderadminlte {
/**
* get information a parameter keys of a component
* @param {string} $sComponent id of the component
* @param {string} $sKey key in the options array
* @return {array}
* @param string $sComponent id of the component
* @param string $sKey key in the options array
* @return array|bool
*/
public function getComponentParamkey($sComponent, $sKey){
public function getComponentParamkey(string $sComponent, string $sKey): array|bool
{
if (!isset($this->_aElements[$sComponent]['params'][$sKey])) {
return false;
}
@@ -832,11 +921,12 @@ class renderadminlte {
/**
* get a flat list of valid parameters for a key in a component
* @param {string} $sComponent id of the component
* @param {string} $sKey key in the options array
* @return {array}
* @param string $sComponent id of the component
* @param string $sKey key in the options array
* @return array|bool
*/
public function getValidParamValues($sComponent, $sKey){
public function getValidParamValues(string $sComponent, string $sKey): array|bool
{
$aOptionkey = $this->getComponentParamkey($sComponent, $sKey);
if (!$aOptionkey || !isset($aOptionkey['select']['values'])) {
return false;
@@ -851,20 +941,26 @@ class renderadminlte {
* helper: add a css value with prefix
* this handles option keys in get[COMPONENT] methods
* if a value is set then this function returns a space + prefix (param 2) + value
* @param {string} $sValue option value
* @param {string} $sPrefix prefix in front of css value
* @return {string}
* @param string $sValue option value
* @param string $sPrefix prefix in front of css value
* @return string
*/
protected function _addClassValue($sValue, $sPrefix=''){
protected function _addClassValue(string $sValue, string $sPrefix = ''): string
{
return $sValue ? ' ' . $sPrefix . $sValue : '';
}
/**
* helper function for get[COMPONENTNAME] methods:
* ensure that all wanted keys exist in an array. Non existing keys will be added with value false
* ensure that all wanted keys exist in an array. Non existing keys will
* be added with value false
*
* @param string $sComponent id of the component
* @param array $aOptions hash with keys for all options
* @return array
*/
protected function _ensureOptions($sComponent, $aOptions=[]){
protected function _ensureOptions(string $sComponent, array $aOptions = []): array
{
$aParams = $this->getComponentParamkeys($sComponent, 0);
if (!$aParams) {
@@ -903,14 +999,15 @@ class renderadminlte {
* return a alert box
* https://adminlte.io/themes/v3/pages/UI/general.html
*
* @param type $aOptions hash with keys for all options
* @param array $aOptions hash with keys for all options
* - type - one of [none]|danger|info|primary|success|warning
* - dismissible - if dismissible - one of true|false; default: false
* - title
* - text
* @return string
*/
public function getAlert($aOptions){
public function getAlert(array $aOptions): string
{
$aOptions = $this->_ensureOptions('alert', $aOptions);
$aAlertIcons = [
'danger' => 'icon fa-solid fa-ban',
@@ -953,8 +1050,10 @@ class renderadminlte {
* - text - visible text
* - title - optional: title attribute
* - type - one of [none]|danger|dark|info|primary|secondary|success|warning
* @return string
*/
public function getBadge($aOptions){
public function getBadge(array $aOptions): string
{
$aOptions = $this->_ensureOptions('badge', $aOptions);
$aElement = [];
$aElement['class'] = 'badge'
@@ -978,7 +1077,7 @@ class renderadminlte {
* https://adminlte.io/themes/v3/pages/UI/buttons.html
*
* <button type="button" class="btn btn-block btn-default">Default</button>
* @param type $aOptions hash with keys for all options
* @param array $aOptions hash with keys for all options
* - type - one of [none]|danger|dark|info|primary|secondary|success|warning
* - size - one of [none]|lg|sm|xs|flat
* - class - any css class for customizing, eg. "disabled"
@@ -986,7 +1085,8 @@ class renderadminlte {
* - text - text on button
* @return string
*/
public function getButton($aOptions){
public function getButton(array $aOptions): string
{
$aOptions = $this->_ensureOptions('button', $aOptions);
$aElement = $aOptions;
$aElement['class'] = 'btn'
@@ -1005,7 +1105,7 @@ class renderadminlte {
* get a callout (box with coloered left border; has type, title + text)
* https://adminlte.io/themes/v3/pages/UI/general.html
*
* @param type $aOptions hash with keys for all options
* @param array $aOptions hash with keys for all options
* >> styling
* - type - one of [none]|danger|dark|info|primary|secondary|success|warning
* - class - optional css class
@@ -1015,7 +1115,8 @@ class renderadminlte {
* - text - text: content of the card
* @return string
*/
public function getCallout($aOptions){
public function getCallout(array $aOptions): string
{
$aOptions = $this->_ensureOptions('callout', $aOptions);
$sClass = 'callout'
. $this->_addClassValue($aOptions['type'], 'callout-')
@@ -1025,7 +1126,8 @@ class renderadminlte {
;
return $this->addWrapper(
'div', ['class'=>$sClass],
'div',
['class' => $sClass],
($aOptions['title'] ? $this->_tag('h5', ['label' => $aOptions['title']]) : '')
. ($aOptions['text'] ? $this->_tag('p', ['label' => $aOptions['text']]) : '')
);
@@ -1036,7 +1138,7 @@ class renderadminlte {
* https://adminlte.io/docs/3.2/components/cards.html
* https://adminlte.io/docs/3.2/javascript/card-widget.html
*
* @param type $aOptions hash with keys for all options
* @param array $aOptions hash with keys for all options
* >> styling
* - variant: "default" - titlebar is colored
* "outline" - a small stripe on top border is colored
@@ -1061,7 +1163,8 @@ class renderadminlte {
* - footer - text: footer of the card
* @return string
*/
public function getCard($aOptions){
public function getCard(array $aOptions): string
{
$aOptions = $this->_ensureOptions('card', $aOptions);
// css class prefixes based on "variant" value
$aVariants = [
@@ -1110,7 +1213,9 @@ class renderadminlte {
}
// build parts of the card
$sCardHeader = $aOptions['title']
? $this->addWrapper('div', ['class'=>'card-header'],
? $this->addWrapper(
'div',
['class' => 'card-header'],
$this->_tag('h3', ['class' => 'card-title', 'label' => $aOptions['title']])
. ($aOptions['tools'] ? $this->_tag('div', ['class' => 'card-tools', 'label' => $aOptions['tools']]) : '')
)
@@ -1144,7 +1249,8 @@ class renderadminlte {
* - progresstext - text below progress bar
* @return string
*/
public function getInfobox($aOptions){
public function getInfobox(array $aOptions): string
{
$aOptions = $this->_ensureOptions('infobox', $aOptions);
// print_r($aOptions);
@@ -1162,12 +1268,16 @@ class renderadminlte {
], $this->_tag('i', ['class' => $aOptions['icon']]))
: ''
;
$sContent=$this->addWrapper("div", ['class'=>'info-box-content'],
$sContent = $this->addWrapper(
"div",
['class' => 'info-box-content'],
''
. ($aOptions['text'] ? $this->_tag('span', ['class' => 'info-box-text', 'label' => $aOptions['text']]) : '')
. ($aOptions['number'] ? $this->_tag('span', ['class' => 'info-box-number', 'label' => $aOptions['number']]) : '')
. ($aOptions['progressvalue'] !== false && $aOptions['progressvalue'] !== ''
? $this->addWrapper('div', ['class'=>'progress'],
? $this->addWrapper(
'div',
['class' => 'progress'],
$this->_tag('div', ['class' => 'progress-bar' . ($aOptions['iconbg'] ? ' bg-' . $aOptions['iconbg'] : ''), 'style' => 'width: ' . (int) $aOptions['progressvalue'] . '%'])
)
. ($aOptions['progresstext'] ? $this->_tag('span', ['class' => 'progress-description', 'label' => $aOptions['progresstext']]) : '')
@@ -1186,7 +1296,7 @@ class renderadminlte {
* https://adminlte.io/docs/3.2/components/boxes.html
* https://adminlte.io/themes/v3/pages/widgets.html
*
* @param type $aOptions hash with keys for all options
* @param array $aOptions hash with keys for all options
* styling:
* - type - color of the box; one of [none]|danger|dark|info|primary|secondary|success|warning
* - shadow - size of shadow; one of [none] (=default: between small and regular)|none|small|regular|large
@@ -1198,7 +1308,8 @@ class renderadminlte {
* - linktext- text below progress bar
* @return string
*/
public function getSmallbox($aOptions){
public function getSmallbox(array $aOptions): string
{
$aOptions = $this->_ensureOptions('smallbox', $aOptions);
// print_r($aOptions);
$sClass = 'small-box'
@@ -1209,18 +1320,25 @@ class renderadminlte {
;
// build parts
$sContent=$this->addWrapper("div", ['class'=>'inner'],
$sContent = $this->addWrapper(
"div",
['class' => 'inner'],
''
. ($aOptions['number'] ? $this->_tag('h3', ['label' => $aOptions['number']]) : '')
. ($aOptions['text'] ? $this->_tag('p', ['class' => 'info-box-text', 'label' => $aOptions['text']]) : '')
);
$sIcon = $aOptions['icon']
? $this->addWrapper("div", ['class'=>'icon'],
$this->_tag('i',['class'=>$aOptions['icon']]))
? $this->addWrapper(
"div",
['class' => 'icon'],
$this->_tag('i', ['class' => $aOptions['icon']])
)
: ''
;
$sFooter = ($aOptions['url']
? $this->addWrapper("a", [
? $this->addWrapper(
"a",
[
'class' => 'small-box-footer',
'href' => $aOptions['url'],
],
@@ -1243,10 +1361,25 @@ class renderadminlte {
// ----------------------------------------------------------------------
public function getHorizontalFormElement($sInput, $sLabel=false, $sId=false){
/**
* Generates a horizontal form element with a label, input, and optional hint.
*
* @param string $sInput The HTML input element to be rendered.
* @param string $sLabel The label for the input element.
* @param string $sId The ID attribute for the label and input elements.
* @param string $sHint An optional hint to be displayed below the input element.
* @return string The generated HTML for the horizontal form element.
*/
public function getHorizontalFormElement(string $sInput, string $sLabel = '', string $sId = '', string $sHint=''): string
{
return '<div class="form-group row">'
. '<label for="' . $sId . '" class="col-sm-2 col-form-label">' . $sLabel . '</label>'
. '<div class="col-sm-10">'.$sInput.'</div>'
. '<div class="col-sm-10">'
. ($sHint
? '<div class="text-navy hint">' . $sHint . '</div>'
: '')
. $sInput
. '</div>'
. '</div>'
;
}
@@ -1262,9 +1395,14 @@ class renderadminlte {
* - label - label tag
* - name - name attribute for sending form
* - value - value in field
* more:
* - hint - hint to be displayed above the field
* If not set, no hint is displayed.
* css for ".row .hint" to customize look and feel
* @return string
*/
public function GetFormInput($aOptions){
public function GetFormInput(array $aOptions): string
{
// $aOptions=$this->_ensureOptions('input', $aOptions);
$aElement = $aOptions;
$aElement['class'] = ''
@@ -1275,26 +1413,31 @@ class renderadminlte {
? $aOptions['id']
: (isset($aOptions['name']) ? $aOptions['name'] : 'field') . '-' . md5(microtime(true))
);
$aElement['id'] = $sFormid;
$sLabel = isset($aOptions['label']) ? $aOptions['label'] : '';
$sHint = isset($aOptions['hint']) ? $aOptions['hint'] : '';
$sPrepend = '';
$sAppend = '';
if (isset($aOptions['prepend']) && $aOptions['prepend']) {
$sWrapperclass = 'input-group';
$sPrepend=$this->_tag('div',[ 'class'=>'input-group-prepend'],
$sPrepend = $this->_tag(
'div',
['class' => 'input-group-prepend'],
$this->_tag('span', ['class' => 'input-group-text'], $aOptions['prepend'])
);
}
if (isset($aOptions['append']) && $aOptions['append']) {
$sWrapperclass = 'input-group';
$sAppend=$this->_tag('div',[ 'class'=>'input-group-append'],
$sAppend = $this->_tag(
'div',
['class' => 'input-group-append'],
$this->_tag('span', ['class' => 'input-group-text'], $aOptions['append'])
);
}
$aElement['id']=$sFormid;
foreach (['_infos', 'label', 'append', 'prepend', 'debug'] as $sDeleteKey) {
if (isset($aElement[$sDeleteKey])) {
unset($aElement[$sDeleteKey]);
@@ -1307,17 +1450,23 @@ class renderadminlte {
case 'checkbox':
case 'radio':
$aElement['class'] = str_replace('form-control ', 'form-check-input', $aElement['class']);
return $this->_tag('div' , ['class'=>'form-check'],
$aElement['title'] = $aElement['title'] ?? $sHint;
return $this->_tag(
'div',
['class' => 'form-check'],
$this->_tag('input', $aElement, '', false) . $this->_tag('label', ['for' => $sFormid, 'label' => $sLabel], '')
);
break;
case 'hidden':
$aElement['title'] = $aElement['title'] ?? $sHint;
return $this->_tag('input', $aElement, '', false);
break;
default: return $this->getHorizontalFormElement(
default:
return $this->getHorizontalFormElement(
$sPrepend . $this->_tag('input', $aElement, '', false) . $sAppend,
$sLabel,
$sFormid
$sFormid,
$sHint
);
}
}
@@ -1331,9 +1480,14 @@ class renderadminlte {
* - label - label tag
* - name - name attribute for sending form
* - value - value in
* more:
* - hint - hint to be displayed above the field
* If not set, no hint is displayed.
* css for ".row .hint" to customize look and feel
* @return string
*/
public function getFormTextarea($aOptions){
public function getFormTextarea(array $aOptions): string
{
// $aOptions=$this->_ensureOptions('textarea', $aOptions);
$aElement = $aOptions;
$aElement['class'] = ''
@@ -1341,13 +1495,16 @@ class renderadminlte {
. ((isset($aOptions['type']) && $aOptions['type'] == 'html') ? 'summernote ' : '')
. (isset($aOptions['class']) ? $aOptions['class'] : '')
;
$sLabel=isset($aOptions['label']) ? $aOptions['label'] : '';
$sFormid = (isset($aOptions['id'])
? $aOptions['id']
: (isset($aOptions['name']) ? $aOptions['name'] : 'field') . '-' . md5(microtime(true))
);
$sLabel = isset($aOptions['label']) ? $aOptions['label'] : '';
$sHint = isset($aOptions['hint']) ? $aOptions['hint'] : '';
$aElement['id'] = $sFormid;
$value = isset($aOptions['value']) ? $aOptions['value'] : '';
foreach (['_infos', 'label', 'debug', 'type', 'value'] as $sDeleteKey) {
if (isset($aElement[$sDeleteKey])) {
unset($aElement[$sDeleteKey]);
@@ -1356,7 +1513,8 @@ class renderadminlte {
return $this->getHorizontalFormElement(
$this->_tag('textarea', $aElement, $value),
$sLabel,
$sFormid
$sFormid,
$sHint
);
}
@@ -1364,32 +1522,46 @@ class renderadminlte {
/**
* return a select box field
* @param array $aOptions hash with keys for all options
* styling:
* - class - css class
* option fields
* - options - array of options with keys per item:
* - value - value in the option
* - label - visible text in the option
* other keys are attributes in the option
* styling:
* - bootstrap-select - set true to enable select
* box with bootstrap-select and
* live search
* - class - css class
* select tag
* - label - label tag
* - name - name attribute for sending form
* other keys are attributes in the select
* more:
* - hint - hint to be displayed above the field
* If not set, no hint is displayed.
* css for ".row .hint" to customize look and feel
* @return string
*/
public function getFormSelect($aOptions){
public function getFormSelect(array $aOptions): string
{
$aElement = $aOptions;
$aElement['class'] = ''
. 'form-control '
. (isset($aOptions['class']) ? $aOptions['class']: '')
. (isset($aOptions['class']) ? $aOptions['class'] . ' ' : '')
. (isset($aOptions['bootstrap-select']) ? 'selectpicker ' : '') //$aOptions
;
if (isset($aOptions['bootstrap-select']) && $aOptions['bootstrap-select']) {
$aElement['data-live-search'] = "true";
}
$sLabel=isset($aOptions['label']) ? $aOptions['label'] : '';
$sFormid = (isset($aOptions['id'])
? $aOptions['id']
: (isset($aOptions['name']) ? $aOptions['name'] : 'field') . '-' . md5(microtime(true))
);
$aElement['id'] = $sFormid;
$sLabel = isset($aOptions['label']) ? $aOptions['label'] : '';
$sHint = isset($aOptions['hint']) ? $aOptions['hint'] : '';
$sOptionTags = '';
foreach ($aOptions['options'] as $aField) {
@@ -1404,11 +1576,14 @@ class renderadminlte {
}
}
return $this->getHorizontalFormElement(
$this->_tag('div', ['class'=>'form-group'],
$this->_tag(
'div',
['class' => 'form-group'],
$this->_tag('select', $aElement, $sOptionTags)
),
$sLabel,
$sFormid
$sFormid,
$sHint
);
}
@@ -1423,9 +1598,11 @@ class renderadminlte {
* return a box with tabbed content
* @param array $aOptions hash with keys for all options
* - tabs {array} key=tab label; value=content
* @retunr string|array
* @param bool $asArray optional flag: return hash with keys or as string
* @retunr bool|string|array
*/
public function getTabbedContent($aOptions, $asArray=false){
public function getTabbedContent(array $aOptions, bool $asArray = false): bool|string|array
{
static $iTabCounter;
if (!isset($aOptions['tabs']) || !is_array($aOptions['tabs'])) {
return false;
@@ -1446,8 +1623,12 @@ class renderadminlte {
$sTabId = $id . '-tabitem-' . $iCounter . '-tab';
$sContentId = $id . '-tabitem-' . $iCounter . '-content';
$sTabs.=$this->_tag('li', ['class'=>'nav-item'],
$this->_tag('a', [
$sTabs .= $this->_tag(
'li',
['class' => 'nav-item'],
$this->_tag(
'a',
[
'class' => 'nav-link' . ($iCounter == 1 ? ' active' : ''),
'id' => $sTabId,
'data-toggle' => 'tab',
@@ -1456,7 +1637,8 @@ class renderadminlte {
'aria-controls' => 'custom-tabs-one-profile',
'aria-selected' => ($iCounter == 1 ? true : false),
],
$sLabel)
$sLabel
)
);
$sContent .= $this->_tag('div', [
'class' => 'tab-pane fade' . ($iCounter == 1 ? ' active show' : ''),
Loading