1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dameter\abstracts\models; |
4
|
|
|
|
5
|
|
|
use dameter\abstracts\interfaces\WithLanguageSettingInterface; |
6
|
|
|
use dameter\abstracts\validators\VariableNameValidator; |
7
|
|
|
use dameter\abstracts\WithLanguageSettingsModel; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class BaseQuestion |
11
|
|
|
* @property integer $question_id |
12
|
|
|
* @property integer $survey_id |
13
|
|
|
* @property string $code Question code is like eg a variable name in SPSS. A relatively short no-spaces survey-wide unique identifier |
14
|
|
|
* |
15
|
|
|
* @property BaseAnswer[] $answers |
16
|
|
|
* @property QuestionText[] $questionTexts in current language |
17
|
|
|
* @property QuestionText[] $questionHelps in current language |
18
|
|
|
* |
19
|
|
|
* @package dameter\abstracts\models |
20
|
|
|
* @author Tõnis Ormisson <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class BaseQuestion extends WithLanguageSettingsModel implements WithLanguageSettingInterface |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function rules() |
31
|
|
|
{ |
32
|
|
|
return array_merge(parent::rules(), [ |
33
|
|
|
[['code'], 'required'], |
34
|
|
|
[['code'], VariableNameValidator::class], |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return \yii\db\ActiveQuery |
40
|
|
|
*/ |
41
|
|
|
public function getAnswers() |
42
|
|
|
{ |
43
|
|
|
return $this->hasMany(BaseSurvey::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return \yii\db\ActiveQuery |
49
|
|
|
*/ |
50
|
|
|
public function getQuestionTexts() |
51
|
|
|
{ |
52
|
|
|
$query = $this->getTexts(); |
53
|
|
|
return $query->andWhere(['type_id' => QuestionText::TYPE_QUESTION]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return \yii\db\ActiveQuery |
58
|
|
|
*/ |
59
|
|
|
public function getQuestionHelps() |
60
|
|
|
{ |
61
|
|
|
$query = $this->getTexts(); |
62
|
|
|
return $query->andWhere(['type_id' => QuestionText::TYPE_HELP]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
} |