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

BaseAnswer::getModelCondition()   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\interfaces\Conditionable;
6
use dameter\abstracts\WithLanguageSettingsModel;
7
use dameter\abstracts\interfaces\Sortable;
8
9
10
/**
11
 * Class BaseAnswer
12
 * @property integer $answer_id
13
 * @property integer $question_id
14
 * @property integer $order
15
 *
16
 * @property BaseQuestion $question
17
 * @property ModelCondition $modelCondition
18
 * @property Condition $condition
19
 *K
20
 * @package dameter\abstracts\models
21
 * @author Tõnis Ormisson <[email protected]>
22
 */
23
class BaseAnswer extends WithLanguageSettingsModel implements Sortable, Conditionable
24
{
25
26
    public static $settingsClass = AnswerText::class;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function rules()
32
    {
33
        return array_merge(parent::rules(), [
34
            [['question_id', 'code', 'order'], 'required'],
35
            [['question_id', 'order'], 'integer'],
36
            [['code'], 'string', 'max' => 64],
37
        ]);
38
    }
39
40
    /**
41
     * @return \yii\db\ActiveQuery
42
     */
43
    public function getQuestion()
44
    {
45
        return $this->hasOne(BaseQuestion::class);
46
    }
47
48
    /**
49
     * @return Condition
50
     */
51
    public function getCondition()
52
    {
53
        if (!empty($this->modelCondition)) {
54
            return $this->modelCondition->child;
55
        }
56
        return null;
57
    }
58
59
    /**
60
     * @return \yii\db\ActiveQuery
61
     */
62
    public function getModelCondition()
63
    {
64
        return $this->hasOne(ModelCondition::class);
65
    }
66
67
}