-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPanel.php
101 lines (87 loc) · 2.45 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* @package yii2-bootstrap-panel-widget
* @author WeArDe <[email protected]>
* @link http://wearde.pp.ua
* @version 1.0.0
*/
namespace amass\panel;
use yii\bootstrap\Widget;
use yii\helpers\Html;
class Panel extends Widget
{
/**
* @var array the HTML attributes for the widget container tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/** @var $headerTitle string the panel-title */
public $headerTitle;
/** @var $header bool showing header */
public $header = true;
/** @var $content mixed */
public $content;
/** @var $footer bool showing footer*/
public $footer = false;
/** @var $footerTitle string the panel-footer title */
public $footerTitle;
/** @var $type string Bootstrap Contextual Color Type default */
public $type = 'default';
/**
* Bootstrap Contextual Color Types
*/
const TYPE_DEFAULT = 'default'; // use default
const TYPE_PRIMARY = 'primary';
const TYPE_INFO = 'info';
const TYPE_DANGER = 'danger';
const TYPE_WARNING = 'warning';
const TYPE_SUCCESS = 'success';
/**
* @inheritdoc
*/
public function init()
{
$this->_initOptions();
echo Html::beginTag('div',$this->options);
$this->_initHeader();
echo Html::beginTag('div',['class' => 'panel-body']);
echo $this->content;
}
/**
* @inheritdoc
*/
public function run()
{
echo Html::endTag('div');
$this->_initFooter();
echo Html::endTag('div');
}
/**
* Initialize bootstrap Panel styling
*/
private function _initOptions()
{
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
if (!isset($this->options['class'])) {
$this->options['class'] = ' panel panel-'.$this->type;
}
$view = $this->getView();
PanelAsset::register($view);
}
/**
* Initialize Panel header
*/
private function _initHeader(){
if($this->header)
echo Html::tag('div', Html::tag('h3',$this->headerTitle, ['class' => 'panel-title']), ['class' => 'panel-heading']);
}
/**
* Initialize Panel header
*/
private function _initFooter(){
if($this->footer)
echo Html::tag('div', $this->footerTitle, ['class' => 'panel-footer']);
}
}