Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions docs/DataStructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,21 @@ A submission-object describes a single submission by a user to a form.

The actual answers of users on submission.

| Property | Type | Restrictions | Description |
| ------------ | ------- | ------------- | ----------------------------------------------- |
| id | Integer | unique | An instance-wide unique id of the submission |
| submissionId | Integer | | The id of the submission, the answer belongs to |
| questionId | Integer | | The id of the question, the answer belongs to |
| text | String | max. 4096 ch. | The actual answer text, the user submitted |

```
| Property | Type | Restrictions | Description |
| ------------ | ------- | ------------- | ---------------------------------------------------- |
| id | Integer | unique | An instance-wide unique id of the submission |
| submissionId | Integer | | The id of the submission, the answer belongs to |
| questionId | Integer | | The id of the question, the answer belongs to |
| questionName | String | | The technical name that was assigned to the question |
| text | String | max. 4096 ch. | The actual answer text, the user submitted |

```json
{
"id": 5,
"submissionId": 5,
"questionId": 1,
"text": "Option 2"
"id": 5,
"submissionId": 5,
"questionId": 1,
"questionName": "preference",
"text": "Option 2"
}
```

Expand Down
20 changes: 17 additions & 3 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,10 +1172,24 @@ public function getSubmissions(int $formId, ?string $query = null, ?int $limit =
$submissions = $this->submissionService->getSubmissions($formId, $userId, $query, $limit, $offset);
$filteredSubmissionsCount = $this->submissionMapper->countSubmissions($formId, $userId, $query);
}
$questions = $this->formsService->getQuestions($formId);
$questions = [];
foreach ($this->formsService->getQuestions($formId) as $question) {
$questions[$question['id']] = $question;
}


// Append Display Names
$submissions = array_map(function (array $submission) {
$submissions = array_map(function (array $submission) use ($questions) {
if (!empty($submission['answers'])) {
$submission['answers'] = array_map(function (array $answer) use ($questions) {
$name = $questions[$answer['questionId']]['name'];
if ($name) {
$answer['questionName'] = $name;
}
return $answer;
}, $submission['answers']);
}

if (substr($submission['userId'], 0, 10) === 'anon-user-') {
// Anonymous User
// TRANSLATORS On Results when listing the single Responses to the form, this text is shown as heading of the Response.
Expand All @@ -1202,7 +1216,7 @@ public function getSubmissions(int $formId, ?string $query = null, ?int $limit =

$response = [
'submissions' => $submissions,
'questions' => $questions,
'questions' => array_values($questions),
'filteredSubmissionsCount' => $filteredSubmissionsCount,
];

Expand Down
1 change: 1 addition & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* submissionId: int,
* fileId: ?int,
* questionId: int,
* questionName?: string,
* text: string
* }
*
Expand Down
3 changes: 3 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"type": "integer",
"format": "int64"
},
"questionName": {
"type": "string"
},
"text": {
"type": "string"
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Integration/Api/ApiV3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ public function dataGetSubmissions() {
// 'questionId' => Checked dynamically
'text' => 'Option 1',
'fileId' => null,
'questionName' => 'city',
]
]
],
Expand All @@ -1137,6 +1138,7 @@ public function dataGetSubmissions() {
// 'questionId' => Checked dynamically
'text' => 'Option 2',
'fileId' => null,
'questionName' => 'city'
]
]
],
Expand Down Expand Up @@ -1384,10 +1386,12 @@ public function testNewSubmission() {
'questionId' => $this->testForms[0]['questions'][1]['id'],
'text' => 'Option 1',
'fileId' => null,
'questionName' => 'city',
],
[
'questionId' => $this->testForms[0]['questions'][2]['id'],
'text' => 'test.txt',
'questionName' => 'file',
],
]
], $data['submissions'][0]);
Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public function dataGetSubmissions() {
'submissions' => [
['userId' => 'anon-user-1']
],
'questions' => [['name' => 'questions']],
'questions' => [['id' => 1, 'name' => 'questions']],
'expected' => [
'submissions' => [
[
Expand All @@ -233,6 +233,7 @@ public function dataGetSubmissions() {
],
'questions' => [
[
'id' => 1,
'name' => 'questions',
'extraSettings' => new \stdClass(),
],
Expand All @@ -244,7 +245,7 @@ public function dataGetSubmissions() {
'submissions' => [
['userId' => 'jdoe']
],
'questions' => [['name' => 'questions']],
'questions' => [['id' => 1, 'name' => 'questions']],
'expected' => [
'submissions' => [
[
Expand All @@ -254,6 +255,7 @@ public function dataGetSubmissions() {
],
'questions' => [
[
'id' => 1,
'name' => 'questions',
'extraSettings' => new \stdClass(),
],
Expand Down
Loading