Skip to content

Commit 42a3fc6

Browse files
committed
feat: introduce Grid as a new question type
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent 2c8f1dd commit 42a3fc6

4 files changed

Lines changed: 6 additions & 3 deletions

File tree

lib/Controller/ApiController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,6 @@ private function storeAnswersForQuestion(Form $form, $submissionId, array $quest
17041704

17051705
$answerText = '';
17061706
$uploadedFile = null;
1707-
// fixme: properly handle grid values (consider create new column)
17081707
// Are we using answer ids as values
17091708
if (in_array($question['type'], Constants::ANSWER_TYPES_PREDEFINED) && $question['type'] !== Constants::ANSWER_TYPE_LINEARSCALE) {
17101709
// Search corresponding option, skip processing if not found
@@ -1733,6 +1732,8 @@ private function storeAnswersForQuestion(Form $form, $submissionId, array $quest
17331732
$file->move($folder->getPath() . '/' . $name);
17341733

17351734
$answerText = $name;
1735+
} elseif ($question['type'] === Constants::ANSWER_TYPE_GRID) {
1736+
$answerText = json_encode($answer);
17361737
} else {
17371738
$answerText = $answer; // Not a multiple-question, answerText is given answer
17381739
}

lib/ResponseDefinitions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
* timeMin?: int,
4040
* timeRange?: bool,
4141
* validationRegex?: string,
42-
* validationType?: string
42+
* validationType?: string,
43+
* questionType?: string,
4344
* }
4445
*
4546
* @psalm-type FormsQuestionType = "dropdown"|"multiple"|"multiple_unique"|"date"|"time"|"short"|"long"|"file"|"datetime"|"grid"

lib/Service/SubmissionService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ public function validateSubmission(array $questions, array $answers, string $for
432432
throw new \InvalidArgumentException(sprintf('Question "%s" can only have two answers.', $question['text']));
433433
} elseif ($answersCount > 1
434434
&& $question['type'] !== Constants::ANSWER_TYPE_FILE
435-
// todo: improve this for grid, add mandatory?
436435
&& $question['type'] !== Constants::ANSWER_TYPE_GRID
437436
&& !($question['type'] === Constants::ANSWER_TYPE_DATE && isset($question['extraSettings']['dateRange'])
438437
|| $question['type'] === Constants::ANSWER_TYPE_TIME && isset($question['extraSettings']['timeRange']))) {

tests/Unit/Service/FormsServiceTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,14 @@ public function dataGetForm() {
212212
'questionId' => 1,
213213
'text' => 'Option 1',
214214
'order' => null,
215+
'optionType' => null,
215216
],
216217
[
217218
'id' => 2,
218219
'questionId' => 1,
219220
'text' => 'Option 2',
220221
'order' => null,
222+
'optionType' => null,
221223
]
222224
],
223225
'accept' => [],

0 commit comments

Comments
 (0)