Completed
Push — master ( d1e17e...bb461e )
by Dmitry
02:59
created

RefCombo::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * HiPanel core package.
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\widgets;
12
13
use hipanel\models\Ref;
14
use hiqdev\combo\StaticCombo;
15
16
/**
17
 * Class RefCombo widget.
18
 *
19
 * Usage:
20
 * RefCombo::widget([
21
 *      'attribute'   => 'state',
22
 *      'model'       => $searchModel,
23
 *      'gtype'       => 'state,domain',
24
 *      'findOptions' => [],
25
 * ]);
26
 */
27
class RefCombo extends StaticCombo
28
{
29
    /**
30
     * @var string
31
     */
32
    public $gtype;
33
34
    /**
35
     * @var array additional find options that will be passed to [[Ref]] model
36
     */
37
    public $findOptions = [];
38
39
    /**
40
     * @var string Dictionary name for i18n module to translate refs
41
     */
42
    public $i18nDictionary;
43
44
    public $_hasId = true;
45
46
    public function init()
47
    {
48
        $this->data = $this->prepareData();
49
50
        parent::init();
51
    }
52
53
    public function prepareData()
54
    {
55
        $refs = Ref::getList($this->gtype, $this->i18nDictionary, $this->findOptions);
56
        return $refs;
57
    }
58
}
59