|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created for IG Monitoring. |
|
4
|
|
|
* User: jakim <[email protected]> |
|
5
|
|
|
* Date: 01.02.2018 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace app\modules\admin\widgets\favorites; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
use app\components\ArrayHelper; |
|
12
|
|
|
use app\models\Favorite; |
|
13
|
|
|
use app\modules\admin\widgets\AjaxButton; |
|
14
|
|
|
use dmstr\widgets\Menu; |
|
15
|
|
|
use Yii; |
|
16
|
|
|
use yii\helpers\Url; |
|
17
|
|
|
|
|
18
|
|
|
class SideMenu extends Menu |
|
19
|
|
|
{ |
|
20
|
|
|
public $encodeLabels = false; |
|
21
|
|
|
public $linkTemplate = '<a href="{url}">{icon} {label} {btn-delete}</a>'; |
|
22
|
|
|
|
|
23
|
|
|
public function init() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->options = ['class' => 'sidebar-menu tree favorites', 'data-widget' => 'tree']; |
|
26
|
|
|
$this->defaultIconHtml = '<i class="fa fa-star"></i> '; |
|
27
|
|
|
parent::init(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function run() |
|
31
|
|
|
{ |
|
32
|
|
|
$favorites = Favorite::find() |
|
33
|
|
|
->andWhere([ |
|
34
|
|
|
'user_id' => Yii::$app->user->id, |
|
35
|
|
|
]) |
|
36
|
|
|
->orderBy('label ASC') |
|
37
|
|
|
->all(); |
|
38
|
|
|
foreach ($favorites as $favorite) { |
|
39
|
|
|
$this->items[] = [ |
|
40
|
|
|
'label' => $favorite->label, |
|
|
|
|
|
|
41
|
|
|
'url' => $favorite->url, |
|
|
|
|
|
|
42
|
|
|
'id' => $favorite->id, |
|
|
|
|
|
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
if ($this->items) { |
|
|
|
|
|
|
46
|
|
|
array_unshift($this->items, ['label' => 'Favorites', 'options' => ['class' => 'header']]); |
|
47
|
|
|
} |
|
48
|
|
|
parent::run(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function isItemActive($item) |
|
52
|
|
|
{ |
|
53
|
|
|
if (!isset($item['url'])) { |
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if ($item['url'] == Url::current()) { |
|
58
|
|
|
return true; |
|
59
|
|
|
} |
|
60
|
|
|
if (isset($item['url'])) { |
|
61
|
|
|
$url = Url::to(["/admin/{$this->view->context->id}/dashboard", 'id' => Yii::$app->request->get('id')]); |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
return $item['url'] == $url; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function renderItem($item) |
|
70
|
|
|
{ |
|
71
|
|
|
$tmp = $this->linkTemplate; |
|
72
|
|
|
$id = ArrayHelper::getValue($item, 'id'); |
|
73
|
|
|
$btnDelete = ''; |
|
74
|
|
|
if ($id) { |
|
75
|
|
|
$btnDelete = AjaxButton::widget([ |
|
76
|
|
|
'confirm' => true, |
|
77
|
|
|
'tag' => 'span', |
|
78
|
|
|
'text' => '<i class="fa fa-trash-o pull-right delete"></i>', |
|
79
|
|
|
'url' => ['favorite/delete', 'id' => $id], |
|
80
|
|
|
'options' => [ |
|
81
|
|
|
'class' => 'pull-right-container', |
|
82
|
|
|
'data' => [ |
|
83
|
|
|
'style' => 'slide-right', |
|
84
|
|
|
], |
|
85
|
|
|
], |
|
86
|
|
|
]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$this->linkTemplate = str_replace('{btn-delete}', $btnDelete, $this->linkTemplate); |
|
90
|
|
|
|
|
91
|
|
|
$html = parent::renderItem($item); |
|
92
|
|
|
$this->linkTemplate = $tmp; |
|
93
|
|
|
|
|
94
|
|
|
return $html; |
|
95
|
|
|
} |
|
96
|
|
|
} |