chg: [helpers:bootstrap] Formatted file

pull/93/head
Sami Mokaddem 2021-11-23 15:29:55 +01:00
parent 3c0237f387
commit 87ac0f7569
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 100 additions and 70 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Bootstrap Tabs helper * Bootstrap Tabs helper
* Options: * Options:
@ -81,7 +82,7 @@ class BootstrapHelper extends Helper
return $bsButton->button(); return $bsButton->button();
} }
public function icon($icon, $options=[]) public function icon($icon, $options = [])
{ {
$bsIcon = new BoostrapIcon($icon, $options); $bsIcon = new BoostrapIcon($icon, $options);
return $bsIcon->icon(); return $bsIcon->icon();
@ -135,7 +136,7 @@ class BootstrapHelper extends Helper
return $bsListGroup->listGroup(); return $bsListGroup->listGroup();
} }
public function genNode($node, $params=[], $content='') public function genNode($node, $params = [], $content = '')
{ {
return BootstrapGeneric::genNode($node, $params, $content); return BootstrapGeneric::genNode($node, $params, $content);
} }
@ -183,12 +184,12 @@ class BootstrapGeneric
} }
} }
public static function genNode($node, $params=[], $content="") public static function genNode($node, $params = [], $content = "")
{ {
return sprintf('<%s %s>%s</%s>', $node, BootstrapGeneric::genHTMLParams($params), $content, $node); return sprintf('<%s %s>%s</%s>', $node, BootstrapGeneric::genHTMLParams($params), $content, $node);
} }
protected static function openNode($node, $params=[]) protected static function openNode($node, $params = [])
{ {
return sprintf('<%s %s>', $node, BootstrapGeneric::genHTMLParams($params)); return sprintf('<%s %s>', $node, BootstrapGeneric::genHTMLParams($params));
} }
@ -255,7 +256,8 @@ class BootstrapTabs extends BootstrapGeneric
]; ];
private $bsClasses = null; private $bsClasses = null;
function __construct($options) { function __construct($options)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'justify' => [false, 'center', 'end'], 'justify' => [false, 'center', 'end'],
'body-variant' => array_merge(BootstrapGeneric::$variants, ['']), 'body-variant' => array_merge(BootstrapGeneric::$variants, ['']),
@ -392,29 +394,31 @@ class BootstrapTabs extends BootstrapGeneric
"border-{$this->options['header-border-variant']}" "border-{$this->options['header-border-variant']}"
] ]
)]); )]);
$html .= $this->openNode('div', ['class' => array_merge( $html .= $this->openNode('div', ['class' => array_merge(
[ [
($this->options['vertical-size'] != 'auto' ? 'col-' . $this->options['vertical-size'] : ''), ($this->options['vertical-size'] != 'auto' ? 'col-' . $this->options['vertical-size'] : ''),
($this->options['card'] ? 'card-header border-end' : '') ($this->options['card'] ? 'card-header border-end' : '')
], ],
[ [
"bg-{$this->options['header-variant']}", "bg-{$this->options['header-variant']}",
"text-{$this->options['header-text-variant']}", "text-{$this->options['header-text-variant']}",
"border-{$this->options['header-border-variant']}" "border-{$this->options['header-border-variant']}"
])]); ]
$html .= $this->genNav(); )]);
$html .= $this->closeNode('div'); $html .= $this->genNav();
$html .= $this->openNode('div', ['class' => array_merge( $html .= $this->closeNode('div');
[ $html .= $this->openNode('div', ['class' => array_merge(
($this->options['vertical-size'] != 'auto' ? 'col-' . (12 - $this->options['vertical-size']) : ''), [
($this->options['card'] ? 'card-body2' : '') ($this->options['vertical-size'] != 'auto' ? 'col-' . (12 - $this->options['vertical-size']) : ''),
], ($this->options['card'] ? 'card-body2' : '')
[ ],
"bg-{$this->options['body-variant']}", [
"text-{$this->options['body-text-variant']}" "bg-{$this->options['body-variant']}",
])]); "text-{$this->options['body-text-variant']}"
$html .= $this->genContent(); ]
$html .= $this->closeNode('div'); )]);
$html .= $this->genContent();
$html .= $this->closeNode('div');
$html .= $this->closeNode('div'); $html .= $this->closeNode('div');
return $html; return $html;
} }
@ -485,7 +489,8 @@ class BootstrapTabs extends BootstrapGeneric
} }
} }
class BoostrapAlert extends BootstrapGeneric { class BoostrapAlert extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'text' => '', 'text' => '',
'html' => null, 'html' => null,
@ -496,7 +501,8 @@ class BoostrapAlert extends BootstrapGeneric {
private $bsClasses = null; private $bsClasses = null;
function __construct($options) { function __construct($options)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => BootstrapGeneric::$variants, 'variant' => BootstrapGeneric::$variants,
]; ];
@ -547,7 +553,8 @@ class BoostrapAlert extends BootstrapGeneric {
} }
} }
class BoostrapTable extends BootstrapGeneric { class BoostrapTable extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'striped' => true, 'striped' => true,
'bordered' => true, 'bordered' => true,
@ -562,7 +569,8 @@ class BoostrapTable extends BootstrapGeneric {
private $bsClasses = null; private $bsClasses = null;
function __construct($options, $data, $btHelper) { function __construct($options, $data, $btHelper)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => array_merge(BootstrapGeneric::$variants, ['']) 'variant' => array_merge(BootstrapGeneric::$variants, [''])
]; ];
@ -651,7 +659,7 @@ class BoostrapTable extends BootstrapGeneric {
private function genRow($row) private function genRow($row)
{ {
$html = $this->openNode('tr',[ $html = $this->openNode('tr', [
'class' => [ 'class' => [
!empty($row['_rowVariant']) ? "table-{$row['_rowVariant']}" : '' !empty($row['_rowVariant']) ? "table-{$row['_rowVariant']}" : ''
] ]
@ -675,7 +683,7 @@ class BoostrapTable extends BootstrapGeneric {
return $html; return $html;
} }
private function genCell($value, $field=[], $row=[], $i=0) private function genCell($value, $field = [], $row = [], $i = 0)
{ {
if (isset($field['formatter'])) { if (isset($field['formatter'])) {
$cellContent = $field['formatter']($value, $row, $i); $cellContent = $field['formatter']($value, $row, $i);
@ -700,7 +708,8 @@ class BoostrapTable extends BootstrapGeneric {
} }
} }
class BoostrapListTable extends BootstrapGeneric { class BoostrapListTable extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'striped' => true, 'striped' => true,
'bordered' => false, 'bordered' => false,
@ -714,7 +723,8 @@ class BoostrapListTable extends BootstrapGeneric {
private $bsClasses = null; private $bsClasses = null;
function __construct($options, $data, $btHelper) { function __construct($options, $data, $btHelper)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => array_merge(BootstrapGeneric::$variants, ['']) 'variant' => array_merge(BootstrapGeneric::$variants, [''])
]; ];
@ -783,7 +793,7 @@ class BoostrapListTable extends BootstrapGeneric {
], ],
'scope' => 'row' 'scope' => 'row'
], h($field['key'])); ], h($field['key']));
$row = $this->genNode('tr',[ $row = $this->genNode('tr', [
'class' => [ 'class' => [
'd-flex', 'd-flex',
!empty($field['_rowVariant']) ? "table-{$field['_rowVariant']}" : '' !empty($field['_rowVariant']) ? "table-{$field['_rowVariant']}" : ''
@ -792,7 +802,7 @@ class BoostrapListTable extends BootstrapGeneric {
return $row; return $row;
} }
private function genCell($field=[]) private function genCell($field = [])
{ {
if (isset($field['raw'])) { if (isset($field['raw'])) {
$cellContent = h($field['raw']); $cellContent = h($field['raw']);
@ -827,7 +837,8 @@ class BoostrapListTable extends BootstrapGeneric {
private function getElementPath($type) private function getElementPath($type)
{ {
return sprintf('%s%sField', return sprintf(
'%s%sField',
$this->options['elementsRootPath'] ?? '', $this->options['elementsRootPath'] ?? '',
$type $type
); );
@ -839,7 +850,8 @@ class BoostrapListTable extends BootstrapGeneric {
} }
} }
class BoostrapButton extends BootstrapGeneric { class BoostrapButton extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'id' => '', 'id' => '',
'text' => '', 'text' => '',
@ -859,7 +871,8 @@ class BoostrapButton extends BootstrapGeneric {
private $bsClasses = []; private $bsClasses = [];
function __construct($options) { function __construct($options)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => array_merge(BootstrapGeneric::$variants, ['link', 'text']), 'variant' => array_merge(BootstrapGeneric::$variants, ['link', 'text']),
'size' => ['', 'xs', 'sm', 'lg'], 'size' => ['', 'xs', 'sm', 'lg'],
@ -952,7 +965,8 @@ class BoostrapButton extends BootstrapGeneric {
} }
} }
class BoostrapBadge extends BootstrapGeneric { class BoostrapBadge extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'text' => '', 'text' => '',
'variant' => 'primary', 'variant' => 'primary',
@ -961,7 +975,8 @@ class BoostrapBadge extends BootstrapGeneric {
'class' => [], 'class' => [],
]; ];
function __construct($options) { function __construct($options)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => BootstrapGeneric::$variants, 'variant' => BootstrapGeneric::$variants,
]; ];
@ -995,7 +1010,8 @@ class BoostrapBadge extends BootstrapGeneric {
} }
} }
class BoostrapIcon extends BootstrapGeneric { class BoostrapIcon extends BootstrapGeneric
{
private $icon = ''; private $icon = '';
private $defaultOptions = [ private $defaultOptions = [
'class' => [], 'class' => [],
@ -1003,7 +1019,8 @@ class BoostrapIcon extends BootstrapGeneric {
'params' => [], 'params' => [],
]; ];
function __construct($icon, $options=[]) { function __construct($icon, $options = [])
{
$this->icon = $icon; $this->icon = $icon;
$this->processOptions($options); $this->processOptions($options);
} }
@ -1032,7 +1049,8 @@ class BoostrapIcon extends BootstrapGeneric {
} }
} }
class BoostrapModal extends BootstrapGeneric { class BoostrapModal extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'size' => '', 'size' => '',
'centered' => true, 'centered' => true,
@ -1057,10 +1075,11 @@ class BoostrapModal extends BootstrapGeneric {
private $bsClasses = null; private $bsClasses = null;
function __construct($options) { function __construct($options)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'size' => ['sm', 'lg', 'xl', ''], 'size' => ['sm', 'lg', 'xl', ''],
'type' => ['ok-only','confirm','confirm-success','confirm-warning','confirm-danger', 'custom'], 'type' => ['ok-only', 'confirm', 'confirm-success', 'confirm-warning', 'confirm-danger', 'custom'],
'variant' => array_merge(BootstrapGeneric::$variants, ['']), 'variant' => array_merge(BootstrapGeneric::$variants, ['']),
]; ];
$this->processOptions($options); $this->processOptions($options);
@ -1079,7 +1098,7 @@ class BoostrapModal extends BootstrapGeneric {
private function genModal() private function genModal()
{ {
$this->options['modalClass'] = !empty($this->options['modalClass']) && !is_array($this->options['modalClass'])? [$this->options['modalClass']] : $this->options['modalClass']; $this->options['modalClass'] = !empty($this->options['modalClass']) && !is_array($this->options['modalClass']) ? [$this->options['modalClass']] : $this->options['modalClass'];
$dialog = $this->openNode('div', [ $dialog = $this->openNode('div', [
'class' => array_merge( 'class' => array_merge(
['modal-dialog', (!empty($this->options['size'])) ? "modal-{$this->options['size']}" : ''], ['modal-dialog', (!empty($this->options['size'])) ? "modal-{$this->options['size']}" : ''],
@ -1140,7 +1159,8 @@ class BoostrapModal extends BootstrapGeneric {
return $footer; return $footer;
} }
private function getFooterBasedOnType() { private function getFooterBasedOnType()
{
if ($this->options['type'] == 'ok-only') { if ($this->options['type'] == 'ok-only') {
return $this->getFooterOkOnly(); return $this->getFooterOkOnly();
} else if (str_contains($this->options['type'], 'confirm')) { } else if (str_contains($this->options['type'], 'confirm')) {
@ -1304,7 +1324,8 @@ class BoostrapCard extends BootstrapGeneric
} }
} }
class BoostrapSwitch extends BootstrapGeneric { class BoostrapSwitch extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'label' => '', 'label' => '',
'variant' => 'primary', 'variant' => 'primary',
@ -1315,7 +1336,8 @@ class BoostrapSwitch extends BootstrapGeneric {
'attrs' => [], 'attrs' => [],
]; ];
function __construct($options) { function __construct($options)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => BootstrapGeneric::$variants, 'variant' => BootstrapGeneric::$variants,
]; ];
@ -1358,7 +1380,8 @@ class BoostrapSwitch extends BootstrapGeneric {
} }
} }
class BoostrapProgress extends BootstrapGeneric { class BoostrapProgress extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'value' => 0, 'value' => 0,
'total' => 100, 'total' => 100,
@ -1371,7 +1394,8 @@ class BoostrapProgress extends BootstrapGeneric {
'label' => true 'label' => true
]; ];
function __construct($options) { function __construct($options)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => BootstrapGeneric::$variants, 'variant' => BootstrapGeneric::$variants,
]; ];
@ -1403,7 +1427,7 @@ class BoostrapProgress extends BootstrapGeneric {
$this->options['animated'] ? 'progress-bar-animated' : '', $this->options['animated'] ? 'progress-bar-animated' : '',
], ],
'role' => "progressbar", 'role' => "progressbar",
'aria-valuemin' => "0", 'aria-valuemax' => "100",'aria-valuenow' => $percentage, 'aria-valuemin' => "0", 'aria-valuemax' => "100", 'aria-valuenow' => $percentage,
'style' => "${widthStyle}", 'style' => "${widthStyle}",
'title' => $this->options['title'] 'title' => $this->options['title']
], $label); ], $label);
@ -1418,13 +1442,15 @@ class BoostrapProgress extends BootstrapGeneric {
} }
} }
class BoostrapCollapse extends BootstrapGeneric { class BoostrapCollapse extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'text' => '', 'text' => '',
'open' => false, 'open' => false,
]; ];
function __construct($options, $content, $btHelper) { function __construct($options, $content, $btHelper)
{
$this->allowedOptionValues = []; $this->allowedOptionValues = [];
$this->processOptions($options); $this->processOptions($options);
$this->content = $content; $this->content = $content;
@ -1565,7 +1591,8 @@ class BoostrapAccordion extends BootstrapGeneric
} }
} }
class BoostrapProgressTimeline extends BootstrapGeneric { class BoostrapProgressTimeline extends BootstrapGeneric
{
private $defaultOptions = [ private $defaultOptions = [
'steps' => [], 'steps' => [],
'selected' => 0, 'selected' => 0,
@ -1573,7 +1600,8 @@ class BoostrapProgressTimeline extends BootstrapGeneric {
'variantInactive' => 'secondary', 'variantInactive' => 'secondary',
]; ];
function __construct($options, $btHelper) { function __construct($options, $btHelper)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'variant' => BootstrapGeneric::$variants, 'variant' => BootstrapGeneric::$variants,
'variantInactive' => BootstrapGeneric::$variants, 'variantInactive' => BootstrapGeneric::$variants,
@ -1600,7 +1628,7 @@ class BoostrapProgressTimeline extends BootstrapGeneric {
!empty($step['icon']) ? h($this->btHelper->FontAwesome->getClass($step['icon'])) : '', !empty($step['icon']) ? h($this->btHelper->FontAwesome->getClass($step['icon'])) : '',
$this->getTextClassForVariant($this->options['variant']) $this->getTextClassForVariant($this->options['variant'])
], ],
], empty($step['icon']) ? h($i+1) : ''); ], empty($step['icon']) ? h($i + 1) : '');
$iconContainer = $this->genNode('span', [ $iconContainer = $this->genNode('span', [
'class' => [ 'class' => [
'd-flex', 'align-items-center', 'justify-content-center', 'd-flex', 'align-items-center', 'justify-content-center',
@ -1622,7 +1650,7 @@ class BoostrapProgressTimeline extends BootstrapGeneric {
private function getHorizontalLine($i, $nodeActive, $lineActive) private function getHorizontalLine($i, $nodeActive, $lineActive)
{ {
$stepCount = count($this->options['steps']); $stepCount = count($this->options['steps']);
if ($i == $stepCount-1) { if ($i == $stepCount - 1) {
return ''; return '';
} }
$progressBar = (new BoostrapProgress([ $progressBar = (new BoostrapProgress([
@ -1687,7 +1715,8 @@ class BootstrapListGroup extends BootstrapGeneric
private $bsClasses = null; private $bsClasses = null;
function __construct($options, $data, $btHelper) { function __construct($options, $data, $btHelper)
{
$this->data = $data; $this->data = $data;
$this->processOptions($options); $this->processOptions($options);
$this->btHelper = $btHelper; $this->btHelper = $btHelper;
@ -1789,7 +1818,8 @@ class BoostrapDropdownMenu extends BootstrapGeneric
'submenu_classes' => [], 'submenu_classes' => [],
]; ];
function __construct($options, $btHelper) { function __construct($options, $btHelper)
{
$this->allowedOptionValues = [ $this->allowedOptionValues = [
'direction' => ['start', 'end', 'up', 'down'], 'direction' => ['start', 'end', 'up', 'down'],
'alignment' => ['start', 'end'], 'alignment' => ['start', 'end'],
@ -1818,7 +1848,7 @@ class BoostrapDropdownMenu extends BootstrapGeneric
return $this->genDropdownWrapper($this->genDropdownToggleButton(), $this->genDropdownMenu($this->menu)); return $this->genDropdownWrapper($this->genDropdownToggleButton(), $this->genDropdownMenu($this->menu));
} }
public function genDropdownWrapper($toggle='', $menu='', $direction=null, $classes=null) public function genDropdownWrapper($toggle = '', $menu = '', $direction = null, $classes = null)
{ {
$classes = !is_null($classes) ? $classes : $this->options['dropdown-class']; $classes = !is_null($classes) ? $classes : $this->options['dropdown-class'];
$direction = !is_null($direction) ? $direction : $this->options['direction']; $direction = !is_null($direction) ? $direction : $this->options['direction'];
@ -1851,7 +1881,7 @@ class BoostrapDropdownMenu extends BootstrapGeneric
return $this->btHelper->button($options); return $this->btHelper->button($options);
} }
private function genDropdownMenu($entries, $alignment=null) private function genDropdownMenu($entries, $alignment = null)
{ {
$alignment = !is_null($alignment) ? $alignment : $this->options['alignment']; $alignment = !is_null($alignment) ? $alignment : $this->options['alignment'];
$html = $this->genNode('div', [ $html = $this->genNode('div', [