Completed
Push — master ( 76271e...53242f )
by Andrii
04:45
created

RefCombo::getData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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