Completed
Push — master ( 64677c...534891 )
by Tõnis
02:45
created

WithLanguageSettingsModel::getTexts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace dameter\abstracts;
4
5
use dameter\abstracts\models\BaseLanguageSetting;
6
use dameter\abstracts\models\Language;
7
8
/**
9
 * Class WithLanguageSettingsModel
10
 * @property BaseLanguageSetting[] $languageSettings
11
 *
12
 * @package dameter\abstracts\models
13
 * @author Tõnis Ormisson <[email protected]>
14
 */
15
class WithLanguageSettingsModel extends WithSurveyModel
16
{
17
18
    /** @var string */
19
    public static $settingsClass;
20
21
    /** @var Language */
22
    public $language;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function init()
28
    {
29
        parent::init();
30
        if (empty($this->language)) {
31
            $this->language = $this->survey->language;
32
        }
33
    }
34
35
    /**
36
     * @return \yii\db\ActiveQuery
37
     */
38
    public function getLanguageSettings() {
39
        return $this->hasMany(self::$settingsClass);
40
    }
41
42
    /**
43
     * @return \yii\db\ActiveQuery
44
     */
45
    public function getTexts()
46
    {
47
        $query = $this->hasMany(static::$settingsClass, ['parent_id' => 'question_id']);
48
        return $query->andWhere(['language_id' => $this->language->primaryKey]);
49
    }
50
51
}