/
QuestionType.php
553 lines (514 loc) · 19.2 KB
/
QuestionType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
<?php
/**
* Class QuestionType
* @property Question $question
* @property QuestionRenderer $questionRenderer
* @property string $fieldType The type of field question needs for storing data
* @property string $fieldDataType numeric vs string types
* @property boolean $isText Whether the type is text (string longer than char)
* @property boolean $isChar Whether the type is char (one-character-string)
* @property boolean $isString Whether the type is string (text or char)
* @property boolean $isNumeric Whether the type numeric (integer, double)
* @property boolean $isInteger Whether the type integer
*
* {@inheritdoc}
*/
class QuestionType extends StaticModel
{
const QT_1_ARRAY_MULTISCALE = '1'; //ARRAY (Flexible Labels) multi scale
const QT_5_POINT_CHOICE = '5';
const QT_A_ARRAY_5_CHOICE_QUESTIONS = 'A'; // ARRAY OF 5 POINT CHOICE QUESTIONS
const QT_B_ARRAY_10_POINT = 'B'; // ARRAY OF 10 POINT CHOICE QUESTIONS
const QT_C_ARRAY_YES_UNCERTAIN_NO = 'C'; // ARRAY OF YES\No\gT("Uncertain") QUESTIONS
const QT_D_DATE = 'D';
const QT_E_ARRAY_OF_INC_SAME_DEC_QUESTIONS = 'E';
const QT_F_ARRAY_FLEXIBLE_ROW = 'F';
const QT_G_GENDER_DROPDOWN = 'G';
const QT_H_ARRAY_FLEXIBLE_COLUMN = 'H';
const QT_I_LANGUAGE = 'I';
const QT_K_MULTIPLE_NUMERICAL_QUESTION = 'K';
const QT_L_LIST_DROPDOWN = 'L';
const QT_M_MULTIPLE_CHOICE = 'M';
const QT_N_NUMERICAL = 'N';
const QT_O_LIST_WITH_COMMENT = 'O';
const QT_P_MULTIPLE_CHOICE_WITH_COMMENTS = 'P';
const QT_Q_MULTIPLE_SHORT_TEXT = 'Q';
const QT_R_RANKING_STYLE = 'R';
const QT_S_SHORT_FREE_TEXT = 'S';
const QT_T_LONG_FREE_TEXT = 'T';
const QT_U_HUGE_FREE_TEXT = 'U';
const QT_X_BOILERPLATE_QUESTION = 'X';
const QT_Y_YES_NO_RADIO = 'Y';
const QT_Z_LIST_RADIO_FLEXIBLE = 'Z';
const QT_EXCLAMATION_LIST_DROPDOWN = '!';
const QT_VERTICAL_FILE_UPLOAD = '|';
const QT_ASTERISK_EQUATION = '*';
const QT_COLON_ARRAY_MULTI_FLEX_NUMBERS = ':';
const QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT = ';';
/** @var Question */
public $question;
/** @var string $code */
public $code;
/** @var string $description */
public $description;
/** @var string $group Group name*/
public $group;
/** @var integer $subquestions whether has subquestions //TODO make it boolean instead */
public $subquestions;
/** @var integer $assessable whether it can be used inside Assessments / Quizmode */
public $assessable;
/** @var integer $ahasdefaultvalues whether has default values */
public $hasdefaultvalues;
/** @var integer $answerscales number of answer scales*/
public $answerscales;
/** @var string $class the css class for question (container??)*/
public $class;
/**
* {@inheritdoc}
*/
public function attributeNames()
{
return ['code', 'description', 'group', 'subquestions', 'assessable',
'hasdefaultvalues', 'answerscales', 'class'];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'code' => gT("Code"),
'description' => gT("Description"),
'group' => gT("Group"),
];
}
public function applyToQuestion($oQuestion) {
$this->question = $oQuestion;
$aSettingsArray = self::modelsAttributes($oQuestion->survey->language)[$oQuestion->type];
foreach($aSettingsArray as $settingKey => $setting) {
$this->$settingKey = $setting;
}
}
/**
* @param string $language
* @return array
*
* @deprecated use the new xml-version implemented in function findQuestionMetaData($type) in QuestionTheme
*
* TODO QuestionTheme 1591616914305: Needs to be replaced by @link QuestionTheme::getAllQuestionMetaData() however translations inside the xml need to be inserted first
*/
public static function modelsAttributes($language = '')
{
return [
self::QT_1_ARRAY_MULTISCALE => [
'code' => self::QT_1_ARRAY_MULTISCALE,
'description' => gT("Array dual scale", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 1,
'assessable' => 1,
'hasdefaultvalues' => 0,
'answerscales' => 2,
'class' => 'array-flexible-duel-scale',
],
self::QT_5_POINT_CHOICE => [
'code' => self::QT_5_POINT_CHOICE,
'description' => gT("5 Point choice", "html", $language),
'group' => gT("Single choice questions"),
'subquestions' => 0,
'hasdefaultvalues' => 0,
'assessable' => 0,
'answerscales' => 0,
'class' => "choice-5-pt-radio"
],
self::QT_A_ARRAY_5_CHOICE_QUESTIONS => [
'code' => self::QT_A_ARRAY_5_CHOICE_QUESTIONS,
'description' => gT("Array (5 Point choice)", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 1,
'hasdefaultvalues' => 0,
'assessable' => 1,
'answerscales' => 0,
'class' => 'array-5-pt'
],
self::QT_B_ARRAY_10_POINT => [
'code' => self::QT_B_ARRAY_10_POINT,
'description' => gT("Array (10 Point choice)", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 1,
'hasdefaultvalues' => 0,
'assessable' => 1,
'answerscales' => 0,
'class' => 'array-10-pt'
],
self::QT_C_ARRAY_YES_UNCERTAIN_NO => [
'code' => self::QT_C_ARRAY_YES_UNCERTAIN_NO,
'description' => gT("Array (Yes/No/Uncertain)", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 1,
'hasdefaultvalues' => 0,
'assessable' => 1,
'answerscales' => 0,
'class' => 'array-yes-uncertain-no'
],
self::QT_D_DATE => [
'code' => self::QT_D_DATE,
'description' => gT("Date/Time", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0,
'class' => 'date'
],
self::QT_E_ARRAY_OF_INC_SAME_DEC_QUESTIONS => [
'code' => self::QT_E_ARRAY_OF_INC_SAME_DEC_QUESTIONS,
'description' => gT("Array (Increase/Same/Decrease)", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 1,
'hasdefaultvalues' => 0,
'assessable' => 1,
'answerscales' => 0,
'class' => 'array-increase-same-decrease'
],
self::QT_F_ARRAY_FLEXIBLE_ROW => [
'code' => self::QT_F_ARRAY_FLEXIBLE_ROW,
'description' => gT("Array", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 1,
'hasdefaultvalues' => 0,
'assessable' => 1,
'answerscales' => 1,
'class' => 'array-flexible-row'
],
self::QT_G_GENDER_DROPDOWN => [
'code' => self::QT_G_GENDER_DROPDOWN,
'description' => gT("Gender", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 0,
'assessable' => 0,
'answerscales' => 0,
'class' => 'gender'
],
self::QT_H_ARRAY_FLEXIBLE_COLUMN => [
'code' => self::QT_H_ARRAY_FLEXIBLE_COLUMN,
'description' => gT("Array by column", "html", $language),
'group' => gT('Arrays'),
'hasdefaultvalues' => 0,
'subquestions' => 1,
'assessable' => 1,
'answerscales' => 1,
'class' => 'array-flexible-column'
],
self::QT_I_LANGUAGE => [
'code' => self::QT_I_LANGUAGE,
'description' => gT("Language switch", "html", $language),
'group' => gT("Mask questions"),
'hasdefaultvalues' => 0,
'subquestions' => 0,
'assessable' => 0,
'answerscales' => 0,
'class' => 'language'
],
self::QT_K_MULTIPLE_NUMERICAL_QUESTION => [
'code' => self::QT_K_MULTIPLE_NUMERICAL_QUESTION,
'description' => gT("Multiple numerical input", "html", $language),
'group' => gT("Mask questions"),
'hasdefaultvalues' => 1,
'subquestions' => 1,
'assessable' => 1,
'answerscales' => 0,
'class' => 'numeric-multi'
],
self::QT_L_LIST_DROPDOWN => [
'code' => self::QT_L_LIST_DROPDOWN,
'description' => gT("List (Radio)", "html", $language),
'group' => gT("Single choice questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 1,
'answerscales' => 1,
'class' => 'list-radio'
],
self::QT_M_MULTIPLE_CHOICE => [
'code' => self::QT_M_MULTIPLE_CHOICE,
'description' => gT("Multiple choice", "html", $language),
'group' => gT("Multiple choice questions"),
'subquestions' => 1,
'hasdefaultvalues' => 1,
'assessable' => 1,
'answerscales' => 0,
'class' => 'multiple-opt'
],
self::QT_N_NUMERICAL => [
'code' => self::QT_N_NUMERICAL,
'description' => gT("Numerical input", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0,
'class' => 'numeric'
],
self::QT_O_LIST_WITH_COMMENT => [
'code' => self::QT_O_LIST_WITH_COMMENT,
'description' => gT("List with comment", "html", $language),
'group' => gT("Single choice questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 1,
'answerscales' => 1,
'class' => 'list-with-comment'
],
self::QT_P_MULTIPLE_CHOICE_WITH_COMMENTS => [
'code' => self::QT_P_MULTIPLE_CHOICE_WITH_COMMENTS,
'description' => gT("Multiple choice with comments", "html", $language),
'group' => gT("Multiple choice questions"),
'subquestions' => 1,
'hasdefaultvalues' => 1,
'assessable' => 1,
'answerscales' => 0,
'class' => 'multiple-opt-comments'
],
self::QT_Q_MULTIPLE_SHORT_TEXT => [
'code' => self::QT_Q_MULTIPLE_SHORT_TEXT,
'description' => gT("Multiple short text", "html", $language),
'group' => gT("Text questions"),
'subquestions' => 1,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0,
'class' => 'multiple-short-txt'
],
self::QT_R_RANKING_STYLE => [
'code' => self::QT_R_RANKING_STYLE,
'description' => gT("Ranking", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 0,
'assessable' => 1,
'answerscales' => 1,
'class' => 'ranking'
],
self::QT_S_SHORT_FREE_TEXT => [
'code' => self::QT_S_SHORT_FREE_TEXT,
'description' => gT("Short free text", "html", $language),
'group' => gT("Text questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0,
'class' => 'text-short'
],
self::QT_T_LONG_FREE_TEXT => [
'code' => self::QT_T_LONG_FREE_TEXT,
'description' => gT("Long free text", "html", $language),
'group' => gT("Text questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0,
'class' => 'text-long'
],
self::QT_U_HUGE_FREE_TEXT => [
'code' => self::QT_U_HUGE_FREE_TEXT,
'description' => gT("Huge free text", "html", $language),
'group' => gT("Text questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0,
'class' => 'text-huge'
],
self::QT_X_BOILERPLATE_QUESTION => [
'code' => self::QT_X_BOILERPLATE_QUESTION,
'description' => gT("Text display", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 0,
'assessable' => 0,
'answerscales' => 0,
'class' => 'boilerplate'
],
self::QT_Y_YES_NO_RADIO => [
'code' => self::QT_Y_YES_NO_RADIO,
'description' => gT("Yes/No", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 0,
'answerscales' => 0,
'class' => 'yes-no'
],
self::QT_EXCLAMATION_LIST_DROPDOWN => [
'code' => self::QT_EXCLAMATION_LIST_DROPDOWN,
'description' => gT("List (Dropdown)", "html", $language),
'group' => gT("Single choice questions"),
'subquestions' => 0,
'hasdefaultvalues' => 1,
'assessable' => 1,
'answerscales' => 1,
'class' => 'list-dropdown'
],
self::QT_COLON_ARRAY_MULTI_FLEX_NUMBERS => [
'code' => self::QT_COLON_ARRAY_MULTI_FLEX_NUMBERS,
'description' => gT("Array (Numbers)", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 2,
'hasdefaultvalues' => 0,
'assessable' => 1,
'answerscales' => 0,
'class' => 'array-multi-flexi'
],
self::QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT => [
'code' => self::QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT,
'description' => gT("Array (Texts)", "html", $language),
'group' => gT('Arrays'),
'subquestions' => 2,
'hasdefaultvalues' => 0,
'assessable' => 0,
'answerscales' => 0,
'class' => 'array-multi-flexi-text'
],
self::QT_VERTICAL_FILE_UPLOAD => [
'code' => self::QT_VERTICAL_FILE_UPLOAD,
'description' => gT("File upload", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 0,
'assessable' => 0,
'answerscales' => 0,
'class' => 'upload-files'
],
self::QT_ASTERISK_EQUATION => [
'code' => self::QT_ASTERISK_EQUATION,
'description' => gT("Equation", "html", $language),
'group' => gT("Mask questions"),
'subquestions' => 0,
'hasdefaultvalues' => 0,
'assessable' => 0,
'answerscales' => 0,
'class' => 'equation'
],
];
}
/**
* Get all type codes of that represent data in text (string longer than char)
* @return string[]
*/
public static function textCodes()
{
return [
self::QT_I_LANGUAGE, self::QT_S_SHORT_FREE_TEXT, self::QT_U_HUGE_FREE_TEXT,
self::QT_Q_MULTIPLE_SHORT_TEXT, self::QT_T_LONG_FREE_TEXT, self::QT_SEMICOLON_ARRAY_MULTI_FLEX_TEXT,
self::QT_COLON_ARRAY_MULTI_FLEX_NUMBERS,
];
}
/**
* Get all type codes of that represent data in char (one-character-string)
* @return string[]
*/
public static function charCodes()
{
return [
self::QT_5_POINT_CHOICE, self::QT_G_GENDER_DROPDOWN, self::QT_Y_YES_NO_RADIO,
self::QT_X_BOILERPLATE_QUESTION
];
}
/**
* Get all type codes of that represent data in string (text and char)
* @return string[]
*/
public static function stringCodes()
{
return array_merge(self::textCodes(), self::charCodes());
}
/**
* Get all type codes of that represent data as integer
* @return string[]
*/
public static function integerCodes()
{
return [
self::QT_VERTICAL_FILE_UPLOAD
];
}
/**
* Get all type codes of that represent data as double
* @return string[]
*/
public static function doubleCodes()
{
return [];
}
/**
* Get all type codes of that represent data as double
* @return string[]
*/
public static function numericCodes()
{
return array_merge(self::integerCodes(), self::doubleCodes());
}
/**
* @return bool
*/
public function getIsText()
{
return in_array($this->code, self::textCodes());
}
/**
* @return bool
*/
public function getIsChar()
{
return in_array($this->code, self::charCodes());
}
/**
* @return bool
*/
public function getIsString()
{
return in_array($this->code, self::charCodes());
}
/**
* @return bool
*/
public function getIsInteger()
{
return in_array($this->code, self::integerCodes());
}
/**
* @return bool
*/
public function getIsNumeric()
{
return in_array($this->code, self::numericCodes());
}
/**
* @return string
*/
public function getFieldType()
{
if ($this->isString) {
if ($this->isChar) {
return Field::TYPE_CHAR;
} else {
return Field::TYPE_STRING;
}
}
return $this->getFieldDataType();
}
/**
* @return string
*/
public function getFieldDataType()
{
if ($this->isString) {
return Field::TYPE_STRING;
}
if ($this->isInteger) {
return Field::TYPE_INTEGER;
}
throw new \Exception("Undefined field data type for QuestionType {$this->code}");
}
}