diff --git a/src/View/Helper/BootstrapHelper.php b/src/View/Helper/BootstrapHelper.php index 90f2ff4..05ce6fe 100644 --- a/src/View/Helper/BootstrapHelper.php +++ b/src/View/Helper/BootstrapHelper.php @@ -111,6 +111,12 @@ class BootstrapHelper extends Helper return $bsProgressTimeline->progressTimeline(); } + public function listGroup($options, $data) + { + $bsListGroup = new BootstrapListGroup($options, $data, $this); + return $bsListGroup->listGroup(); + } + public function genNode($node, $params=[], $content='') { return BootstrapGeneric::genNode($node, $params, $content); @@ -1276,4 +1282,100 @@ class BoostrapProgressTimeline extends BootstrapGeneric { ], $ulIcons . $ulText); return $html; } +} + +class BootstrapListGroup extends BootstrapGeneric +{ + private $defaultOptions = [ + 'hover' => false, + ]; + + private $bsClasses = null; + + function __construct($options, $data, $btHelper) { + $this->data = $data; + $this->processOptions($options); + $this->btHelper = $btHelper; + } + + private function processOptions($options) + { + $this->options = array_merge($this->defaultOptions, $options); + } + + public function listGroup() + { + return $this->genListGroup(); + } + + private function genListGroup() + { + $html = $this->openNode('div', [ + 'class' => ['list-group',], + ]); + foreach ($this->data as $item) { + $html .= $this->genItem($item); + } + $html .= $this->closeNode('div'); + return $html; + } + + private function genItem($item) + { + if (!empty($item['heading'])) { // complex layout with heading, badge and body + $html = $this->genNode('a', [ + 'class' => ['list-group-item', (!empty($this->options['hover']) ? 'list-group-item-action' : ''),], + ], implode('', [ + $this->genHeadingGroup($item), + $this->genBody($item), + ])); + } else { // simple layout with just