Completed
Push — master ( 24eece...f7f242 )
by Dmitry
14:14 queued 29s
created

ApplyToAllWidget   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 6
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 16 1
1
<?php
2
3
4
namespace hipanel\widgets;
5
6
7
use hipanel\assets\ApplyToAllAsset;
8
use yii\base\Widget;
9
use yii\helpers\Inflector;
10
11
/**
12
 * Class AssignAttributesWidget
13
 * @package hipanel\widgets
14
 */
15
class ApplyToAllWidget extends Widget
16
{
17
    /**
18
     * @var \hipanel\base\Model[]
19
     */
20
    public $models;
21
22
    /**
23
     * @var string[]
24
     */
25
    public $attributes;
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function run()
31
    {
32
        ApplyToAllAsset::register($this->view);
33
        $commonFormName = reset($this->models)->formName();
34
        $formId = Inflector::camel2id($commonFormName);
35
        $formName = strtolower($commonFormName);
36
        $options = \yii\helpers\Json::htmlEncode([
37
            'formId' => $formId,
38
            'formName' => $formName,
39
            'attributes' => $this->attributes,
40
            'linkText' => \Yii::t('hipanel', 'Apply to all'),
41
        ]);
42
        $this->view->registerJs("\$('#$formId').applyToAll($options);");
43
44
        return parent::run();
45
    }
46
}
47