Completed
Push — master ( fe0e5d...8d9fc1 )
by Tõnis
02:04
created

BaseAnswer::primaryKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 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
 *
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 static function tableName()
32
    {
33
        return "answer";
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public static function primaryKey()
40
    {
41
        return ["answer_id"];
42
    }
43
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function rules()
49
    {
50
        return array_merge(parent::rules(), [
51
            [['question_id', 'code', 'order'], 'required'],
52
            [['question_id', 'order'], 'integer'],
53
            [['code'], 'string', 'max' => 64],
54
        ]);
55
    }
56
57
    /**
58
     * @return \yii\db\ActiveQuery
59
     */
60
    public function getQuestion()
61
    {
62
        return $this->hasOne(BaseQuestion::class);
63
    }
64
65
    /**
66
     * @return Condition
67
     */
68
    public function getCondition()
69
    {
70
        if (!empty($this->modelCondition)) {
71
            return $this->modelCondition->child;
72
        }
73
        return null;
74
    }
75
76
    /**
77
     * @return \yii\db\ActiveQuery
78
     */
79
    public function getModelCondition()
80
    {
81
        return $this->hasOne(ModelCondition::class);
82
    }
83
84
}