1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dameter\abstracts\models; |
4
|
|
|
|
5
|
|
|
use dameter\abstracts\DActiveRecord; |
6
|
|
|
use yii\helpers\ArrayHelper; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class BaseSurvey |
10
|
|
|
* |
11
|
|
|
* @property int $survey_id |
12
|
|
|
* @property string $name Survey name. Primarily meant for back-end usage. |
13
|
|
|
* @property int $language_id base language id |
14
|
|
|
* |
15
|
|
|
* @property BaseQuestion[] $questions |
16
|
|
|
* @property Language[] $languages |
17
|
|
|
* @property Language $language |
18
|
|
|
* @property Condition[] $conditions All survey conditions |
19
|
|
|
* |
20
|
|
|
* @package dameter\abstracts\models |
21
|
|
|
* @author Tõnis Ormisson <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
abstract class BaseSurvey extends DActiveRecord |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function rules() |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
[['name'], 'string', 'max' => 254], |
33
|
|
|
[['language_id'], 'integer'], |
34
|
|
|
[['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::class, 'targetAttribute' => ['language_id' => 'language_id']], |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
|
|
public function getLanguage() |
42
|
|
|
{ |
43
|
|
|
return $this->hasMany(Language::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return \yii\db\ActiveQuery |
48
|
|
|
* @throws \yii\base\NotSupportedException |
49
|
|
|
*/ |
50
|
|
|
public function getLanguages() |
51
|
|
|
{ |
52
|
|
|
$relations = $this->surveyLanguages(); |
53
|
|
|
$ids = ArrayHelper::getColumn($relations, SurveyLanguage::primaryKeySingle()); |
54
|
|
|
return Language::find()->andWhere(['in', Language::primaryKeySingle(), $ids]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function getQuestions() |
61
|
|
|
{ |
62
|
|
|
return $this->hasMany(BaseQuestion::class); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function getConditions() |
69
|
|
|
{ |
70
|
|
|
return $this->hasMany(Condition::class); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return SurveyLanguage[] |
76
|
|
|
* @throws \yii\base\NotSupportedException |
77
|
|
|
*/ |
78
|
|
|
private function surveyLanguages() |
79
|
|
|
{ |
80
|
|
|
return SurveyLanguage::getChildren($this); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
} |