1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\widgets; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\base\Widget; |
7
|
|
|
use yii\helpers\Html; |
8
|
|
|
use yii\helpers\StringHelper; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Banner trying to display banner images with a link transition. |
12
|
|
|
* It expects that it will be configured by DI in the block `definitions` and there banners will be transferred |
13
|
|
|
* to the properties `sidebarItems` and `mainItems`. The data must be of the key is the transition link |
14
|
|
|
* and the value is the link to the banner image. |
15
|
|
|
* |
16
|
|
|
* Example: |
17
|
|
|
* // to `definitions` |
18
|
|
|
* |
19
|
|
|
* \hipanel\widgets\Banner::class => [ |
20
|
|
|
* 'sidebarItems' => ['#' => 'https://cdn.hiqdev.com/hipanel/banners/cloud2.jpg', ...], |
21
|
|
|
* 'mainItems' => ['#' => 'https://cdn.hiqdev.com/hipanel/banners/cloud1.jpg', ...], |
22
|
|
|
* ], |
23
|
|
|
* |
24
|
|
|
* @package hipanel\widgets |
25
|
|
|
*/ |
26
|
|
|
class Banner extends Widget |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var boolean |
30
|
|
|
*/ |
31
|
|
|
public $isSidebar = true; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
public $sidebarItems = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
public $mainItems = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
public $sidebarImgOptions = [ |
47
|
|
|
'class' => 'img-responsive hidden-xs hidden-sm', |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
public $mainImgOptions = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
public $sidebarLinkOptions = [ |
59
|
|
|
'target' => '_blank', |
60
|
|
|
'rel' => 'noopener noreferrer', |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
public $mainLinkOptions = [ |
67
|
|
|
'target' => '_blank', |
68
|
|
|
'rel' => 'noopener noreferrer', |
69
|
|
|
]; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public function run(): string |
75
|
|
|
{ |
76
|
|
|
$html = ''; |
77
|
|
|
foreach ($this->getItems() as $url => $src) { |
78
|
|
|
$html .= Html::a(Html::img($src, $this->getImgOptions()), $url, $this->getLinkOptions()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $html; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
protected function getItems(): array |
88
|
|
|
{ |
89
|
|
|
if ($this->isSidebar === false && !StringHelper::endsWith(Yii::$app->request->url, 'dashboard/dashboard')) { |
90
|
|
|
return []; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->isSidebar ? $this->sidebarItems : $this->mainItems; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
private function getImgOptions(): array |
100
|
|
|
{ |
101
|
|
|
return $this->isSidebar ? $this->sidebarImgOptions : $this->mainImgOptions; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
private function getLinkOptions(): array |
108
|
|
|
{ |
109
|
|
|
return $this->isSidebar ? $this->sidebarLinkOptions : $this->mainLinkOptions; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|