Completed
Push — master ( 199d88...287b45 )
by Tõnis
02:10
created

BaseSurvey::surveyLanguages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace dameter\abstracts\models;
4
5
use dameter\abstracts\DActiveRecord;
6
use yii\helpers\ArrayHelper;
7
8
/**
9
 * Class BaseSurvey
10
 *
11
 * @property int $survey_id
12
 * @property string $name Survey name. Primarily meant for back-end usage.
13
 *
14
 * @property BaseQuestion[] $questions
15
 * @property Language[] $languages
16
 * @property Language $language
17
 *
18
 * @package dameter\abstracts\models
19
 * @author Tõnis Ormisson <[email protected]>
20
 */
21
abstract class BaseSurvey extends DActiveRecord
22
{
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function rules()
28
    {
29
        return [
30
             [['name'], 'string', 'max' => 254],
31
        ];
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getQuestions()
38
    {
39
        return $this->hasMany(BaseQuestion::class);
40
    }
41
42
    /**
43
     * @return \yii\db\ActiveQuery
44
     * @throws \yii\base\NotSupportedException
45
     */
46
    public function getLanguages()
47
    {
48
        $relations = $this->surveyLanguages();
49
        $ids = ArrayHelper::getColumn($relations, SurveyLanguage::primaryKeySingle());
50
        return Language::find()->andWhere(['in', Language::primaryKeySingle(), $ids]);
51
    }
52
53
    /**
54
     * @return SurveyLanguage[]
55
     * @throws \yii\base\NotSupportedException
56
     */
57
    private function surveyLanguages()
58
    {
59
        return SurveyLanguage::getChildren($this);
60
    }
61
62
}