1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dameter\abstracts\models; |
4
|
|
|
|
5
|
|
|
use dameter\abstracts\interfaces\Conditionable; |
6
|
|
|
use dameter\abstracts\validators\VariableNameValidator; |
7
|
|
|
use dameter\abstracts\WithLanguageSettingsModel; |
8
|
|
|
use dameter\abstracts\interfaces\Sortable; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class BaseQuestion |
12
|
|
|
* @property integer $question_id |
13
|
|
|
* @property integer $survey_id |
14
|
|
|
* @property integer $order |
15
|
|
|
* @property integer $question_type_id |
16
|
|
|
* |
17
|
|
|
* @property string $code Question code is like eg a variable name in SPSS. A relatively short no-spaces survey-wide unique identifier |
18
|
|
|
* |
19
|
|
|
* @property BaseAnswer[] $answers |
20
|
|
|
* @property QuestionText[] $questionTexts in current language |
21
|
|
|
* @property QuestionText[] $questionHelps in current language |
22
|
|
|
* @property ModelCondition $modelCondition |
23
|
|
|
* @property Condition $condition |
24
|
|
|
* @property QuestionType $questionType |
25
|
|
|
* |
26
|
|
|
* @package dameter\abstracts\models |
27
|
|
|
* @author Tõnis Ormisson <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class BaseQuestion extends WithLanguageSettingsModel implements Sortable, Conditionable |
30
|
|
|
{ |
31
|
|
|
public static $settingsClass = QuestionText::class; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public static function tableName() |
37
|
|
|
{ |
38
|
|
|
return "{{question}}"; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public static function primaryKey() |
45
|
|
|
{ |
46
|
|
|
return ["question_id"]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function rules() |
53
|
|
|
{ |
54
|
|
|
return array_merge(parent::rules(), [ |
55
|
|
|
[['code', 'order', 'question_type_id'], 'required'], |
56
|
|
|
[['code'], VariableNameValidator::class], |
57
|
|
|
[['order', 'question_type_id'], 'integer'], |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return \yii\db\ActiveQuery |
63
|
|
|
*/ |
64
|
|
|
public function getAnswers() |
65
|
|
|
{ |
66
|
|
|
return $this->hasMany(BaseSurvey::class); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return \yii\db\ActiveQuery |
72
|
|
|
*/ |
73
|
|
|
public function getQuestionTexts() |
74
|
|
|
{ |
75
|
|
|
$query = $this->getTexts(); |
76
|
|
|
return $query->andWhere(['type_id' => QuestionText::TYPE_QUESTION]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return \yii\db\ActiveQuery |
81
|
|
|
*/ |
82
|
|
|
public function getQuestionHelps() |
83
|
|
|
{ |
84
|
|
|
$query = $this->getTexts(); |
85
|
|
|
return $query->andWhere(['type_id' => QuestionText::TYPE_HELP]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return Condition |
90
|
|
|
*/ |
91
|
|
|
public function getCondition() |
92
|
|
|
{ |
93
|
|
|
if (!empty($this->modelCondition)) { |
94
|
|
|
return $this->modelCondition->child; |
95
|
|
|
} |
96
|
|
|
return null; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return \yii\db\ActiveQuery |
101
|
|
|
*/ |
102
|
|
|
public function getModelCondition() |
103
|
|
|
{ |
104
|
|
|
return $this->hasOne(ModelCondition::class); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return QuestionType |
109
|
|
|
*/ |
110
|
|
|
public function getQuestionType() |
111
|
|
|
{ |
112
|
|
|
return (new QuestionType())->findByKey($this->question_type_id); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |