Skip to content
Snippets Groups Projects
Commit 8e360a9b authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update components

parent 1bf9126d
Branches
No related tags found
No related merge requests found
...@@ -354,6 +354,26 @@ class renderadminlte { ...@@ -354,6 +354,26 @@ class renderadminlte {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/**
* helper function for get[COMPONENTNAME] functions:
* ensure that all wanted keys exist in an array. Non existing keys will be added with value false
* @param array $aOptions options array of the method
* @param array $aKeys required keys
* @return array
*/
protected function _ensureOptions($aOptions, $aKeys){
foreach ($aKeys as $sKey){
if(!isset($aOptions[$sKey])){
$aOptions[$sKey]=false;
if(!isset($aOptions['_infos'])){
$aOptions['_infos']=[];
}
$aOptions['_infos'][]="added missing key: $sKey";
}
$this->_checkValue($sKey, $aOptions[$sKey]);
}
return $aOptions;
}
/** /**
* return a alert box * return a alert box
...@@ -366,12 +386,7 @@ class renderadminlte { ...@@ -366,12 +386,7 @@ class renderadminlte {
* @return string * @return string
*/ */
public function getAlert($aOptions){ public function getAlert($aOptions){
foreach (array('type','dismissible', 'title', 'text') as $sKey){ $aOptions=$this->_ensureOptions($aOptions, ['type','dismissible', 'title', 'text']);
if(!isset($aOptions[$sKey])){
$aOptions[$sKey]=false;
}
$this->_checkValue($sKey, $aOptions[$sKey]);
}
$aAlertIcons=[ $aAlertIcons=[
'danger'=>'icon fas fa-ban', 'danger'=>'icon fas fa-ban',
'info'=>'icon fas fa-info', 'info'=>'icon fas fa-info',
...@@ -386,10 +401,12 @@ class renderadminlte { ...@@ -386,10 +401,12 @@ class renderadminlte {
, ,
'label'=>'' 'label'=>''
. ($aOptions['dismissible'] ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' : '') . ($aOptions['dismissible'] ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' : '')
. $this->_oHtml->getTag('h5', [], . $this->_oHtml->getTag('h5', [
(isset($aAlertIcons[$aOptions['type']]) ? '<i class=""></i> ' : '') 'label'=> ''
.(isset($aAlertIcons[$aOptions['type']]) ? '<i class="'.$aAlertIcons[$aOptions['type']].'"></i> ' : '')
.$aOptions['title']
])
.$aOptions['text'] .$aOptions['text']
)
]; ];
return $this->_oHtml->getTag('div', $aElement); return $this->_oHtml->getTag('div', $aElement);
...@@ -413,13 +430,7 @@ class renderadminlte { ...@@ -413,13 +430,7 @@ class renderadminlte {
* - type - one of [none]|danger|dark|info|primary|secondary|success|warning * - type - one of [none]|danger|dark|info|primary|secondary|success|warning
*/ */
public function getBadge($aOptions){ public function getBadge($aOptions){
$_aParams=['bgcolor', 'class', 'id', 'text', 'title', 'type']; $aOptions=$this->_ensureOptions($aOptions, ['bgcolor', 'class', 'id', 'text', 'title', 'type']);
foreach ($_aParams as $sKey){
if(!isset($aOptions[$sKey])){
$aOptions[$sKey]=false;
}
$this->_checkValue($sKey, $aOptions[$sKey]);
}
$aElement=[]; $aElement=[];
$aElement['class']='badge' $aElement['class']='badge'
. ($aOptions['class'] ? ' badge-'.$aOptions['class'] : '') . ($aOptions['class'] ? ' badge-'.$aOptions['class'] : '')
...@@ -447,12 +458,7 @@ class renderadminlte { ...@@ -447,12 +458,7 @@ class renderadminlte {
* @return string * @return string
*/ */
public function getButton($aOptions){ public function getButton($aOptions){
foreach (array('type', 'size', 'class', 'text', 'icon') as $sKey){ $aOptions=$this->_ensureOptions($aOptions, ['type', 'size', 'class', 'text', 'icon']);
if(!isset($aOptions[$sKey])){
$aOptions[$sKey]=false;
}
$this->_checkValue($sKey, $aOptions[$sKey]);
}
$aElement=[ $aElement=[
'class'=>'btn ' 'class'=>'btn '
.(isset($aOptions['class']) ? ' '.$aOptions['class'] : '') .(isset($aOptions['class']) ? ' '.$aOptions['class'] : '')
...@@ -465,35 +471,40 @@ class renderadminlte { ...@@ -465,35 +471,40 @@ class renderadminlte {
} }
/** /**
* get a card * get a calout (box with coloered left border; has type, title + text)
* *
* <div class="card"> * @param type $aOptions hash with keys for all options
* <div class="card-header"> * >> styling
* <h3 class="card-title">Default Card Example</h3> * - type - one of [none]|danger|dark|info|primary|secondary|success|warning
* <div class="card-tools"> * - class - optional css class
* <!-- Buttons, labels, and many other things can be placed here! --> *
* <!-- Here is a label for example --> * >> texts/ html content
* <span class="badge badge-primary">Label</span> * - title - text: title of the card
* </div> * - text - text: content of the card
* <!-- /.card-tools --> * @return string
* </div> */
* <!-- /.card-header --> public function getCallout($aOptions){
* <div class="card-body"> $aOptions=$this->_ensureOptions($aOptions, ['type', 'class', 'title', 'text']);
* The body of the card $sClass='callout'
* </div> .($aOptions['class'] ? ' '.$aOptions['class'] : '')
* <!-- /.card-body --> .($aOptions['type'] ? ' callout-'.$aOptions['type'] : '')
* <div class="card-footer"> ;
* The footer of the card
* </div> return $this->addWrapper(
* <!-- /.card-footer --> 'div', ['class'=>$sClass],
* </div> ($aOptions['title'] ? $this->_oHtml->getTag('h5', ['label'=>$aOptions['title']]) : '')
* <!-- /.card --> .($aOptions['text'] ? $this->_oHtml->getTag('p', ['label'=>$aOptions['text']]) : '')
);
}
/**
* get a card
* *
* @param type $aOptions hash with keys for all options * @param type $aOptions hash with keys for all options
* >> styling * >> styling
* - variant: "default" - titlebar is colored * - variant: "default" - titlebar is colored
* "outline" - small stripe on top border is colored * "outline" - small stripe on top border is colored
* "fill" - whole card is colored * "solid" - whole card is colored
* "gradient" - whole card is colored with a gradient * "gradient" - whole card is colored with a gradient
* - type - one of [none]|danger|dark|info|primary|secondary|success|warning * - type - one of [none]|danger|dark|info|primary|secondary|success|warning
* - class - any css class for customizing, eg. "disabled" * - class - any css class for customizing, eg. "disabled"
...@@ -506,18 +517,12 @@ class renderadminlte { ...@@ -506,18 +517,12 @@ class renderadminlte {
* @return string * @return string
*/ */
public function getCard($aOptions){ public function getCard($aOptions){
foreach (array('variant', 'type', 'class', 'text', 'icon') as $sKey){ $aOptions=$this->_ensureOptions($aOptions, ['variant', 'type', 'class', 'title', 'tools', 'text', 'footer']);
if(!isset($aOptions[$sKey])){
$aOptions[$sKey]=false;
}
$this->_checkValue($sKey, $aOptions[$sKey]);
}
// css class prefixes based on "variant" value // css class prefixes based on "variant" value
$aVariants=[ $aVariants=[
'default' => 'card-', 'default' => 'card-',
'outline' => 'card-outline card-', 'outline' => 'card-outline card-',
'fill' => 'bg-', 'solid' => 'bg-',
'gradient' => 'bg-gradient-', 'gradient' => 'bg-gradient-',
]; ];
...@@ -562,6 +567,7 @@ class renderadminlte { ...@@ -562,6 +567,7 @@ class renderadminlte {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
...@@ -656,7 +662,7 @@ class renderadminlte { ...@@ -656,7 +662,7 @@ class renderadminlte {
* - text * - text
* @return string * @return string
*/ */
public function getCallout($aOptions){ public function MIGRATED__getCallout($aOptions){
foreach (array('type', 'title', 'text') as $sKey){ foreach (array('type', 'title', 'text') as $sKey){
if(!isset($aOptions[$sKey])){ if(!isset($aOptions[$sKey])){
$aOptions[$sKey]=false; $aOptions[$sKey]=false;
......
...@@ -11,7 +11,12 @@ function showExample($sPhpcode){ ...@@ -11,7 +11,12 @@ function showExample($sPhpcode){
<pre>'.htmlentities($sPhpcode).'</pre> <pre>'.htmlentities($sPhpcode).'</pre>
<h3>Output</h3> <h3>Output</h3>
visual output:<br>
<br>
'.$sOut.' '.$sOut.'
<br>
generated html code (line breaks were added here):
<pre>'.htmlentities(str_replace([">", "</"], [">\n", "\n</"], $sOut)).'</pre>
'; ';
} }
\ No newline at end of file
<?php
$aOptions=[
'type'=>'warning',
'title'=>'I need your attention',
'dismissible'=>1,
'text'=>'Please check it. Maybe there is something wrong here.',
];
echo $renderAdminLTE->addRow(
'<h2>Alert</h2>'
)
.$renderAdminLTE->addRow(
'<h3>Syntax</h3>
<pre>
echo $renderAdminLTE->getAlert($aOptions)
</pre>
'
)
.showExample('$renderAdminLTE->getAlert('.var_export($aOptions, 1).')')
;
\ No newline at end of file
<?php <?php
$aCard=[ $aCard=[
'type'=>'primary', 'type'=>'success',
'variant'=>'fill', 'title'=>'I am a success callout',
'title'=>'I am a card', 'text'=>'This is a gren callout.',
'tools'=>'123',
'text'=>'Hello everybody out there!',
'footer'=>'&copy; Axel',
]; ];
echo $renderAdminLTE->addRow( echo $renderAdminLTE->addRow(
'<h2>Cards</h2>' '<h2>Callouts</h2>'
) )
.$renderAdminLTE->addRow( .$renderAdminLTE->addRow(
'<h3>Syntax</h3> '<h3>Syntax</h3>
<pre> <pre>
echo $renderAdminLTE->getCard($aOptions) echo $renderAdminLTE->getCallout($aOptions)
</pre> </pre>
' '
) )
// .showExample('"hello"') .showExample('$renderAdminLTE->getCallout('.var_export($aCard, 1).')')
// .showExample('"'.var_export($aCard, 1).'"')
.showExample('$renderAdminLTE->getCard('.var_export($aCard, 1).')')
/* /*
.$renderAdminLTE->addRow( .$renderAdminLTE->addRow(
......
<?php
$aOptions=[
'type'=>'primary',
'variant'=>'solid',
'title'=>'I am a card',
'tools'=>'123',
'text'=>'Hello everybody out there!',
'footer'=>'&copy; Axel',
];
echo $renderAdminLTE->addRow(
'<h2>Card</h2>'
)
.$renderAdminLTE->addRow(
'<h3>Syntax</h3>
<pre>
echo $renderAdminLTE->getCard($aOptions)
</pre>
'
)
.showExample('$renderAdminLTE->getCard('.var_export($aOptions, 1).')')
;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment