1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace andmemasin\surveybasemodels; |
4
|
|
|
|
5
|
|
|
use andmemasin\myabstract\ModelWithHasStatus; |
6
|
|
|
use yii; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This is the model class for a generic Survey. This describes common |
10
|
|
|
* parameters all Survey models must have regardless of the methodology. |
11
|
|
|
* All Surveys in multiple modes (CATI, CAPI, PANEL, WEB etc.) must extend |
12
|
|
|
* this class. |
13
|
|
|
* |
14
|
|
|
* @property int $survey_id |
15
|
|
|
* @property string $key |
16
|
|
|
* @property string $status |
17
|
|
|
* @property string $name |
18
|
|
|
* @property string $options The options as json string. Contains the Collector authentication information (or any other info) |
19
|
|
|
* |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
class Survey extends ModelWithHasStatus |
23
|
|
|
{ |
24
|
|
|
public static $hasStatusClassName = SurveyHasStatus::class; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function rules() |
31
|
|
|
{ |
32
|
|
|
return array_merge([ |
33
|
|
|
[['name','status'], 'required'], |
34
|
|
|
[['name', 'status'], 'string', 'max' => 255], |
35
|
|
|
[['name'], 'string','max' => 500], |
36
|
|
|
[['options'], 'string','max' => 1024 * 10], |
37
|
|
|
], parent::rules()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
|
|
public function attributeLabels() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
'survey_id' => Yii::t('app', 'ID'), |
47
|
|
|
'name' => Yii::t('app', 'Survey name'), |
48
|
|
|
'status' => Yii::t('app', 'Status'), |
49
|
|
|
'options' => Yii::t('app', 'Options JSON'), |
50
|
|
|
'key' => Yii::t('app', 'Survey key'), |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function attributeHints() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
'key' => Yii::t('app', 'Survey key is a cross-platform multi-mode unique id for survey.'), |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return mixed |
66
|
|
|
*/ |
67
|
|
|
public function getOptionsDecoded(){ |
68
|
|
|
return json_decode($this->options); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $key survey uuid |
74
|
|
|
* @return static|array|null|yii\db\ActiveRecord |
75
|
|
|
*/ |
76
|
|
|
public static function findByKey($key) |
77
|
|
|
{ |
78
|
|
|
return static::find()->andWhere("key=:key", [":key" => $key])->one(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
} |