1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created for IG Monitoring. |
4
|
|
|
* User: jakim <[email protected]> |
5
|
|
|
* Date: 06.02.2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace app\modules\admin\widgets; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use app\components\ArrayHelper; |
12
|
|
|
use app\components\CategoryManager; |
13
|
|
|
use app\dictionaries\TrackerType; |
14
|
|
|
use app\models\Proxy; |
15
|
|
|
use app\modules\admin\models\MonitoringForm; |
16
|
|
|
use app\modules\admin\widgets\base\ModalWidget; |
17
|
|
|
use Yii; |
18
|
|
|
|
19
|
|
|
class CreateMonitoringModal extends ModalWidget |
20
|
|
|
{ |
21
|
|
|
public $trackerType = TrackerType::ACCOUNT; |
22
|
|
|
|
23
|
|
|
public $title; |
24
|
|
|
public $form; |
25
|
|
|
public $modalHeader = 'Create monitoring'; |
26
|
|
|
public $modalToggleButton = ['label' => 'Create']; |
27
|
|
|
|
28
|
|
|
protected static $categories; |
29
|
|
|
protected static $proxies; |
30
|
|
|
|
31
|
|
|
public function run() |
32
|
|
|
{ |
33
|
|
|
$this->form = $this->form ?: new MonitoringForm(['scenario' => $this->trackerType]); |
34
|
|
|
parent::run(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function renderModalContent() |
38
|
|
|
{ |
39
|
|
|
echo $this->render('create-monitoring', [ |
40
|
|
|
'formAction' => ["monitoring/create-{$this->trackerType}"], |
41
|
|
|
'model' => $this->form, |
42
|
|
|
'categories' => $this->getCategories(), |
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function getCategories() |
47
|
|
|
{ |
48
|
|
|
if ($this->trackerType == TrackerType::ACCOUNT) { |
49
|
|
|
if (!isset(static::$categories)) { |
50
|
|
|
$categoryManager = Yii::createObject(CategoryManager::class); |
51
|
|
|
/** @var \app\models\User $identity */ |
52
|
|
|
$identity = Yii::$app->user->identity; |
53
|
|
|
static::$categories = ArrayHelper::map($categoryManager->getForUser($identity), 'name', 'name'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return static::$categories; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
} |