-
Notifications
You must be signed in to change notification settings - Fork 2
/
ListGroup.php
92 lines (81 loc) · 2.29 KB
/
ListGroup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace enigmatix\widgets;
use yii\helpers\Html;
/**
* Class Tags
* @package frontend\widgets
* @author Joel Small
* @email joel.small@biscon.com.au
*
* This class creates a widget that creates a list of tags in the form of a tag cloud.
*/
class ListGroup extends \yii\bootstrap\Widget
{
public $model;
public $attribute;
public $title;
public $name;
public $pluginOptions;
public $items = [];
public $defaultClass = 'list-group-item list-group-item-text list-group-item-info bottom-buffer';
public $titleClass = 'panel-primary';
private $content = '';
public function run()
{
$this->content = $this->buildItems($this->items);
$this->content = $this->buildContent();
echo $this->content;
}
private function buildContent()
{
return $this->htmlWrap();
}
private function htmlWrap()
{
return Html::tag('div',$this->panelBody(),['class' => 'row']);
}
private function panelBody()
{
return Html::tag('div', $this->listGroup(), ['class' => 'panel-body']);
}
private function listGroup()
{
return Html::tag('div', $this->content,['class' => 'list-group']);
}
private function buildItems($items)
{
$content = '';
foreach ($items as $value)
{
$content .= $this->buildItem($value);
}
return $content;
}
private function buildItem($value)
{
$key = '';
$titleSuffix = '';
$class = $this->defaultClass;
if(array_key_exists('class', $value) && $value['class'] != '')
{
$class .= " " .$value['class'];
}
$value['class'] = $class;
if(array_key_exists('small', $value))
{
$titleSuffix = Html::tag('small',Html::encode($value['small']),['class' => 'pull-right']);
unset($value['small']);
}
if(array_key_exists('title', $value))
{
$key .= Html::tag('p',"From: ".Html::encode($value['title']).$titleSuffix).Html::tag("hr");
unset($value['title']);
}
if(array_key_exists('content', $value))
{
$key .= $value['content'];
unset($value['content']);
}
return Html::tag('div', $key, $value);
}
}