-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSocialWidget.php
169 lines (139 loc) · 3.34 KB
/
SocialWidget.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
namespace co0lc0der\Lte3Widgets;
use yii\bootstrap4\Html;
/**
* Class SocialWidget
* @package co0lc0der\Lte3Widgets
*/
class SocialWidget extends \yii\base\Widget
{
use CustomCssSupportTrait;
use ColorSupportTrait;
use ShadowSupportTrait;
/**
* username
* @var string
*/
public string $name = '';
/**
* user image
* @var string
*/
public string $image = '';
/**
* user role or position
* @var string
*/
public string $position = '';
/**
* makes a gradient card, uses $color property (Bootstrap 4 colors or additional colors of AdminLTE)
* @var bool
*/
public bool $gradient = false;
/**
* list of rows
* format: title => [count, URL]
* 'Followers' => [
* '1,521',
* '#url'
* ],
* 'Following' => ['373'],
* 'Friends' => ['3,127'],
* 'Projects' => [
* '7',
* 'https://example.com'
* ],
* @var array
*/
public array $rows = [];
/**
* @return void
*/
public function init()
{
parent::init();
}
/**
* @return string
*/
public function run(): string
{
$html = Html::beginTag('div', ['class' => $this->getCardClass()]);
$html .= $this->getCardHeader();
$html .= $this->getCardFooter();
$html .= Html::endTag('div'); // the end of a card
return $html;
}
/**
* @return string
*/
protected function getCardHeader(): string
{
$html = Html::beginTag('div', ['class' => $this->getCardHeaderClass()]);
$html .= $this->getUserImage();
$html .= (!empty($this->name)) ? Html::tag('h3', $this->name, ['class' => 'widget-user-username']) : '';
$html .= (!empty($this->position)) ? Html::tag('h5', $this->position, ['class' => 'widget-user-desc']) : '';
$html .= Html::endTag('div'); // the end of a card header
return $html;
}
/**
* @return string
*/
protected function getCardFooter(): string
{
if (empty($this->rows)) return '';
$html = $this->getCardRows();
return Html::tag('div', $html, ['class' => $this->getCardFooterClass()]);
}
/**
* @return string
*/
protected function getUserImage(): string
{
if (empty($this->image)) return '';
$image = Html::img($this->image, ['class' => 'img-circle elevation-2', 'alt' => 'User avatar']);
return Html::tag('div', $image, ['class' => 'widget-user-image']);
}
/**
* @return string
*/
protected function getCardRows(): string
{
$html = '';
foreach ($this->rows as $title => $row) {
$inner = Html::encode($title);
$color = $row[2] ?? 'light';
$inner .= Html::tag('span', $row[0] ?? '0', ['class' => "float-right badge bg-{$color}"]);
$link = Html::a($inner, $row[1] ?? '#', ['class' => 'nav-link']);
$html .= Html::tag('li', $link, ['class' => 'nav-item']);
}
return Html::tag('ul', $html, ['class' => "nav flex-column"]);
}
/**
* @return string
*/
protected function getCardClass(): string
{
$class = 'card card-widget widget-user-2';
$class .= $this->getShadowClass();
return $class . $this->getCustomCssClass(0);
}
/**
* @return string
*/
protected function getCardHeaderClass(): string
{
$class = 'widget-user-header';
if ($this->isColor($this->color)) {
$class .= ($this->gradient) ? " bg-gradient-{$this->color}" : " bg-{$this->color}";
}
return $class . $this->getCustomCssClass(1);
}
/**
* @return string
*/
protected function getCardFooterClass(): string
{
return 'card-footer p-0' . $this->getCustomCssClass(4);
}
}