|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace backend\widgets\box; |
|
4
|
|
|
|
|
5
|
|
|
use yii\bootstrap\Widget; |
|
6
|
|
|
use yii\helpers\Html; |
|
7
|
|
|
use common\assets\IonIconsAsset; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class SmallBox |
|
11
|
|
|
* |
|
12
|
|
|
* @package backend\widgets\box |
|
13
|
|
|
*/ |
|
14
|
|
|
class SmallBox extends Widget |
|
15
|
|
|
{ |
|
16
|
|
|
const BG_GREEN = 'bg-green'; |
|
17
|
|
|
const BG_AQUA = 'bg-aqua'; |
|
18
|
|
|
const BG_YELLOW = 'bg-yellow'; |
|
19
|
|
|
const BG_RED = 'bg-red'; |
|
20
|
|
|
const BG_GRAY = 'bg-gray'; |
|
21
|
|
|
const BG_BLACK = 'bg-black'; |
|
22
|
|
|
const BG_MAROON = 'bg-maroon'; |
|
23
|
|
|
const BG_PURPLE = 'bg-purple'; |
|
24
|
|
|
const BG_TEAL = 'bg-teal'; |
|
25
|
|
|
const BG_NAVY = 'bg-navy'; |
|
26
|
|
|
const BG_PRIMARY = 'bg-primary'; |
|
27
|
|
|
const BG_SUCCESS = 'bg-success'; |
|
28
|
|
|
const BG_WARNING = 'bg-warning'; |
|
29
|
|
|
const BG_INFO = 'bg-info'; |
|
30
|
|
|
const BG_DANGER = 'bg-danger'; |
|
31
|
|
|
|
|
32
|
|
|
public $status = true; |
|
33
|
|
|
public $header; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string icon name |
|
36
|
|
|
* @see: http://ionicons.com |
|
37
|
|
|
*/ |
|
38
|
|
|
public $icon; |
|
39
|
|
|
public $content; |
|
40
|
|
|
public $link = ['label' => '', 'url' => []]; |
|
41
|
|
|
public $style; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function run() |
|
47
|
|
|
{ |
|
48
|
|
|
if ($this->status === true) { |
|
49
|
|
|
$this->registerAssets(); |
|
50
|
|
|
return $this->renderContent(); |
|
51
|
|
|
} |
|
52
|
|
|
return ''; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function renderContent() |
|
59
|
|
|
{ |
|
60
|
|
|
$str = ''; |
|
61
|
|
|
$str .= Html::beginTag('div', ['id' => $this->id, 'class' => 'small-box ' . $this->style]) . PHP_EOL; |
|
62
|
|
|
$str .= Html::beginTag('div', ['class' => 'inner']) . PHP_EOL; |
|
63
|
|
|
$str .= Html::tag('h3', $this->header) . PHP_EOL; |
|
64
|
|
|
$str .= Html::tag('p', $this->content) . PHP_EOL; |
|
65
|
|
|
$str .= Html::endTag('div') . PHP_EOL; |
|
66
|
|
|
$str .= Html::beginTag('div', ['icon']) . PHP_EOL; |
|
67
|
|
|
$str .= Html::tag('i', '', ['class' => 'icon ' . $this->icon]) . PHP_EOL; |
|
68
|
|
|
$str .= Html::endTag('div') . PHP_EOL; |
|
69
|
|
|
if (is_array($this->link)) { |
|
|
|
|
|
|
70
|
|
|
if (!empty($this->link['label']) && !empty($this->link['url'])) { |
|
71
|
|
|
$str .= Html::a($this->link['label'], $this->link['url'], [ |
|
72
|
|
|
'class' => 'small-box-footer' |
|
73
|
|
|
]) . PHP_EOL; |
|
74
|
|
|
} elseif (!empty($this->link['label'])) { |
|
75
|
|
|
$str .= Html::tag('p', $this->link['label'], ['class' => 'small-box-footer']); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
$str .= Html::endTag('div') . PHP_EOL; |
|
79
|
|
|
return $str; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Register Assets |
|
84
|
|
|
*/ |
|
85
|
|
|
public function registerAssets() |
|
86
|
|
|
{ |
|
87
|
|
|
$view = $this->getView(); |
|
88
|
|
|
IonIconsAsset::register($view); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|