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