Completed
Push — master ( 196bfd...794470 )
by Tõnis
02:15
created

BaseSurvey::getConditions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 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
 * @property int $language_id base language id
14
 *
15
 * @property BaseQuestion[] $questions
16
 * @property Language[] $languages
17
 * @property Language $language
18
 * @property Condition[] $conditions All survey conditions
19
 *
20
 * @package dameter\abstracts\models
21
 * @author Tõnis Ormisson <[email protected]>
22
 */
23
abstract class BaseSurvey extends DActiveRecord
24
{
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function rules()
30
    {
31
        return [
32
            [['name'], 'string', 'max' => 254],
33
            [['language_id'], 'integer'],
34
            [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::class, 'targetAttribute' => ['language_id' => 'language_id']],
35
        ];
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getLanguage()
42
    {
43
        return $this->hasMany(Language::class);
44
    }
45
46
    /**
47
     * @return \yii\db\ActiveQuery
48
     * @throws \yii\base\NotSupportedException
49
     */
50
    public function getLanguages()
51
    {
52
        $relations = $this->surveyLanguages();
53
        $ids = ArrayHelper::getColumn($relations, SurveyLanguage::primaryKeySingle());
54
        return Language::find()->andWhere(['in', Language::primaryKeySingle(), $ids]);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getQuestions()
61
    {
62
        return $this->hasMany(BaseQuestion::class);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getConditions()
69
    {
70
        return $this->hasMany(Condition::class);
71
    }
72
73
74
    /**
75
     * @return SurveyLanguage[]
76
     * @throws \yii\base\NotSupportedException
77
     */
78
    private function surveyLanguages()
79
    {
80
        return SurveyLanguage::getChildren($this);
81
    }
82
83
}