Passed
Push — master ( ead853...557cfb )
by Alexey
03:41
created

Map::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace backend\widgets\map\jvector;
4
5
use yii\base\Widget;
6
use yii\helpers\Html;
7
use yii\helpers\ArrayHelper;
8
use backend\widgets\map\jvector\assets\MapAsset;
9
use yii\helpers\Json;
10
11
/**
12
 * Class Map
13
 *
14
 * @package backend\widgets\map\jvector
15
 */
16
class Map extends Widget
17
{
18
    /** @var bool */
19
    public $status = true;
20
    /** @var array */
21
    public $containerOptions = [];
22
    /** @var array */
23
    public $clientOptions = [];
24
25
    /**
26
     * @inheritDoc
27
     */
28
    public function init()
29
    {
30
        parent::init();
31
        if ($this->status === true) {
32
            $this->registerAsset();
33
        }
34
        $this->id = $this->id ?: $this->getId();
35
        ArrayHelper::setValue($this->containerOptions, 'id', $this->id);
36
    }
37
38
    /**
39
     * Run
40
     *
41
     * @return string
42
     */
43
    public function run()
44
    {
45
        return Html::tag('div', '', $this->containerOptions);
46
    }
47
48
    /**
49
     * Client Options
50
     *
51
     * @return array
52
     */
53
    public function getClientOptions()
54
    {
55
        $clientOptions = [
56
            'map' => 'world_mill_en',
57
        ];
58
        return ArrayHelper::merge($clientOptions, $this->clientOptions);
59
    }
60
61
    /**
62
     * Register Asset
63
     */
64
    public function registerAsset()
65
    {
66
        $view = $this->getView();
67
        MapAsset::register($view);
68
        $id = $this->id;
69
        $clientOptions = Json::encode($this->getClientOptions());
70
        $script = "
71
            let map_{$id} = $('#{$id}').vectorMap({$clientOptions});
72
        ";
73
        $view->registerJs($script);
74
    }
75
}
76