Skip to content

Commit 2cc6943

Browse files
jekuaitkrimi-itk
andauthored
Apply suggestions from code review
Co-authored-by: Mikkel Ricky <[email protected]>
1 parent 055846d commit 2cc6943

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ api users.
1818
A user can access the Webform REST API if
1919

2020
1. it has the “OS2Form REST API user” (`os2forms_rest_api_user`) role,
21-
2. has been granted access to the formular
21+
2. has been granted access to the form
2222
(see [Custom access control](#custom-access-control) )
2323
3. has a generated key (User > Edit > Key authentication; `/user/«user
2424
id»/key-auth`).
@@ -131,16 +131,16 @@ Response:
131131
### Webform submissions
132132

133133
You can filter results based on submission time by
134-
adding query parameters to the url:
134+
adding query parameters to the URL:
135135

136136
| Name | Value | Example |
137137
|-------------|----------------------|--------------|
138-
| `starttime` | PHP DateTime formats | `yesterday` |
138+
| `starttime` | [PHP Date and Time Formats](https://www.php.net/manual/en/datetime.formats.php) | `yesterday` |
139139
| `endtime` | PHP DateTime formats | `2023-10-23` |
140140

141141
If left out, filtering upon the left out parameter will not be done.
142142

143-
The example beneath requests all submissions after October 1. 2023.
143+
This example requests all submissions after on or after October 1st, 2023:
144144

145145
Request:
146146

@@ -151,13 +151,14 @@ Request:
151151
Response:
152152

153153
```json
154-
{"webform_id":"some_webform_id",
155-
"starttime":"2023-10-01",
156-
"submissions":{
157-
"123":"https:\/\/127.0.0.1:8000\/da\/webform_rest\/some_webform_id\/submission\/44b1fe1b-ee96-481e-b941-d1219d1dcb55",
158-
"124":"https:\/\/127.0.0.1:8000\/da\/webform_rest\/some_webform_id\/submission\/3652836d-3dab-4919-b880-e82cbbf3c24c"
154+
{
155+
"webform_id": "some_webform_id",
156+
"starttime": "2023-10-01",
157+
"submissions": {
158+
"123": "https://127.0.0.1:8000/da/webform_rest/some_webform_id/submission/44b1fe1b-ee96-481e-b941-d1219d1dcb55",
159+
"124": "https://127.0.0.1:8000/da/webform_rest/some_webform_id/submission/3652836d-3dab-4919-b880-e82cbbf3c24c"
159160
}
160-
}
161+
}```
161162
```
162163

163164
## Custom access control

src/Plugin/rest/resource/WebformAllFormSubmissions.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,13 @@ public function get(string $webform_id): ModifiedResourceResponse {
175175
* @phpstan-return array<string, mixed>
176176
*/
177177
private function updateSubmissionQuery(Request $request, QueryInterface $submissionQuery, string $parameter, string $operator, array &$result): array {
178-
// Handle starttime request query.
179-
$timeQuery = $request->query->get($parameter);
178+
$value = $request->query->get($parameter);
180179

181180
if (!empty($timeQuery)) {
182181
try {
183-
$startTime = new \DateTime($timeQuery);
182+
$startTime = new \DateTimeImmutable($timeQuery);
184183
$submissionQuery->condition('created', $startTime->getTimestamp(), $operator);
185-
$result[$parameter] = $timeQuery;
184+
$result[$parameter] = $timeQuery->format(\DateTimeImmutable::ATOM);
186185
}
187186
catch (\Exception $e) {
188187
$errors = [

0 commit comments

Comments
 (0)