-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPanel.php
81 lines (74 loc) · 2.16 KB
/
Panel.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
<?php
namespace enigmatix\widgets;
use kartik\widgets\Select2Asset;
use yii\helpers\Html;
/**
* Class Tags
* @package frontend\widgets
* @author Joel Small
* @email [email protected]
*
* This class creates a widget that creates a list of tags in the form of a tag cloud.
*/
class Panel extends \yii\bootstrap\Widget
{
public $model;
public $attribute;
public $title;
public $name;
public $pluginOptions;
public $links = [];
public $defaultClass = 'list-group-item ';
public $titleClass = 'panel-primary';
public $panelClass = 'col-lg-4';
public function run()
{
$content = $this->buildLinks($this->links);
$content = $this->htmlWrap($content);
echo $content;
}
private function htmlWrap($content)
{
return '
<div class="'.$this->panelClass.'">
<div class="panel '.$this->titleClass.'">
<div class="panel-heading">
<h3 class="panel-title">'.$this->title.'</h3>
</div>
<div class="panel-body">
<div class="list-group">' . $content .'
</div>
</div>
</div>
</div>
';
}
private function buildLinks($links)
{
$content = '';
foreach ($this->links as $key => $value)
{
if($value == null) continue;
if(!array_key_exists('class', $value))
{
$value['class'] = $this->defaultClass;
}
if(array_key_exists('title', $value))
{
$key = $value['title'];
}
if(array_key_exists('badge', $value) && $value['badge'] != 0)
{
$key .= '<span class="badge">'.$value['badge'].'</span>';
}
if(array_key_exists('content', $value))
{
$key = "<h4 class='list-group-item-heading'>$key</h4>
<p class='list-group-item-text'>".$value['content']."</p>";
unset($value['content']);
}
$content .= Html::tag('a', $key, $value);
}
return $content;
}
}