1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace dameter\abstracts\models; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use dameter\abstracts\TypeModel; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class QuestionType |
10
|
|
|
* |
11
|
|
|
* @property string $fieldType The type of field question needs for storing data |
12
|
|
|
* @property boolean $isText Whether the type is text (string longer than char) |
13
|
|
|
* @property boolean $isChar Whether the type is char (one-character-string) |
14
|
|
|
* @property boolean $isString Whether the type is string (text or char) |
15
|
|
|
* @property boolean $isNumeric Whether the type numeric (integer, double) |
16
|
|
|
* @property boolean $isInteger Whether the type integer |
17
|
|
|
* @property boolean $isDouble Whether the type double |
18
|
|
|
* @property boolean $hasSubSets Whether type has any sub-question sets |
19
|
|
|
* @property boolean $hasComment Whether type has additional comment field |
20
|
|
|
* |
21
|
|
|
* @package dameter\abstracts\models |
22
|
|
|
* @author Tõnis Ormisson <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class QuestionType extends TypeModel |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
const TYPE_NO_DATA = 0; |
29
|
|
|
const TYPE_SINGLE_CHOICE = 1; |
30
|
|
|
const TYPE_MULTIPLE_CHOICE = 2; |
31
|
|
|
const TYPE_STRING = 3; |
32
|
|
|
const TYPE_DATETIME = 5; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function modelsAttributes() |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
self::TYPE_NO_DATA => [ |
41
|
|
|
'id' => self::TYPE_NO_DATA, |
42
|
|
|
'order' => 0, |
43
|
|
|
'label' => \Yii::t('dmadmin', "Text display"), |
44
|
|
|
], |
45
|
|
|
self::TYPE_SINGLE_CHOICE => [ |
46
|
|
|
'id' => self::TYPE_SINGLE_CHOICE, |
47
|
|
|
'order' => 1, |
48
|
|
|
'label' => \Yii::t('dmadmin', "Single choice question"), |
49
|
|
|
], |
50
|
|
|
self::TYPE_MULTIPLE_CHOICE => [ |
51
|
|
|
'id' => self::TYPE_MULTIPLE_CHOICE, |
52
|
|
|
'order' => 2, |
53
|
|
|
'label' => \Yii::t('dmadmin', "Multiple choice question"), |
54
|
|
|
], |
55
|
|
|
self::TYPE_STRING => [ |
56
|
|
|
'id' => self::TYPE_STRING, |
57
|
|
|
'order' => 3, |
58
|
|
|
'label' => \Yii::t('dmadmin', "String question"), |
59
|
|
|
], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getFieldType() |
68
|
|
|
{ |
69
|
|
|
if ($this->isDouble) { |
70
|
|
|
return "decimal(" . Field::DEFAULT_DOUBLE_LENGTH . "," . Field::DEFAULT_DOUBLE_DECIMALS . ")"; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ($this->isText) { |
74
|
|
|
return "text"; |
75
|
|
|
} |
76
|
|
|
if ($this->isChar) { |
77
|
|
|
return "string(1)"; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($this->id === self::TYPE_DATETIME) { |
81
|
|
|
return "datetime"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if ($this->id === self::TYPE_NO_DATA) { |
85
|
|
|
return null; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
return "string(" . Field::DEFAULT_STRING_LENGTH . ")"; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
public function getIsText() |
97
|
|
|
{ |
98
|
|
|
return in_array($this->id, self::textCodes()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get all type codes of that represent data in text (string longer than char) |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
public static function textCodes() |
106
|
|
|
{ |
107
|
|
|
// TODO |
108
|
|
|
return [ |
109
|
|
|
]; |
110
|
|
|
} |
111
|
|
|
/** |
112
|
|
|
* Get all type codes of that represent data in char (one-character-string) |
113
|
|
|
* @return string[] |
114
|
|
|
*/ |
115
|
|
|
public static function charCodes() |
116
|
|
|
{ |
117
|
|
|
// TODO |
118
|
|
|
return [ |
119
|
|
|
]; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get all type codes of that represent data in string (text and char) |
124
|
|
|
* @return string[] |
125
|
|
|
*/ |
126
|
|
|
public static function stringCodes() |
127
|
|
|
{ |
128
|
|
|
return array_merge(self::textCodes(), self::charCodes()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get all type codes of that represent data as integer |
134
|
|
|
* @return string[] |
135
|
|
|
*/ |
136
|
|
|
public static function integerCodes() |
137
|
|
|
{ |
138
|
|
|
// TODO |
139
|
|
|
return [ |
140
|
|
|
]; |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get all type codes of that represent data as double |
146
|
|
|
* @return string[] |
147
|
|
|
*/ |
148
|
|
|
public static function doubleCodes() |
149
|
|
|
{ |
150
|
|
|
// TODO |
151
|
|
|
return [ |
152
|
|
|
]; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get all type codes of that represent data as double |
157
|
|
|
* @return string[] |
158
|
|
|
*/ |
159
|
|
|
public static function numericCodes() |
160
|
|
|
{ |
161
|
|
|
return array_merge(self::integerCodes(), self::doubleCodes()); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* get Codes of question Types that have additional comment field |
166
|
|
|
* @return array |
167
|
|
|
*/ |
168
|
|
|
public static function withCommentCodes() |
169
|
|
|
{ |
170
|
|
|
// TODO |
171
|
|
|
return [ |
172
|
|
|
]; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return bool |
177
|
|
|
*/ |
178
|
|
|
public function getHasComment() |
179
|
|
|
{ |
180
|
|
|
return in_array($this->id, self::withCommentCodes()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return bool |
185
|
|
|
*/ |
186
|
|
|
public function getIsChar() |
187
|
|
|
{ |
188
|
|
|
return in_array($this->id, self::charCodes()); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return bool |
193
|
|
|
*/ |
194
|
|
|
public function getIsString() |
195
|
|
|
{ |
196
|
|
|
return in_array($this->id, self::charCodes()); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return bool |
201
|
|
|
*/ |
202
|
|
|
public function getIsInteger() |
203
|
|
|
{ |
204
|
|
|
return in_array($this->id, self::integerCodes()); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return bool |
209
|
|
|
*/ |
210
|
|
|
public function getIsDouble() |
211
|
|
|
{ |
212
|
|
|
return in_array($this->id, self::doubleCodes()); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return bool |
217
|
|
|
*/ |
218
|
|
|
public function getIsNumeric() |
219
|
|
|
{ |
220
|
|
|
return in_array($this->id, self::numericCodes()); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
|
224
|
|
|
} |