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
3 changes: 3 additions & 0 deletions docs/API_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,9 @@ Get all Submissions to a Form
|-----------|---------|-------------|
| _formId_ | Integer | ID of the form to get the submissions for |
| _submissionId_ | Integer | ID of the submission to get |
| _query_ | Integer | Search string for full-text search. Can be a username |
| _limit_ | Integer | How many submissions to fetch |
| _offset_ | Integer | Offset for the pagination |
- Response: The submission

```
Expand Down
16 changes: 11 additions & 5 deletions lib/Db/SubmissionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
*
* @param int $formId The ID of the form whose submissions are being retrieved.
* @param string|null $userId An optional user ID to filter the submissions.
* @param string|null $query An optional search query to filter the submissions.
* @param string|null $searchString An optional search query to filter the submissions.
* @param int|null $limit The maximum number of submissions to retrieve, default: all submissions
* @param int $offset The number of submissions to skip before starting to retrieve, default: 0
*
* @return Submission[] An array of Submission objects.
* @throws DoesNotExistException If no submissions are found for the given form ID.
*
*/
public function findByForm(int $formId, ?string $userId = null, ?string $query = null, ?int $limit = null, int $offset = 0): array {
public function findByForm(int $formId, ?string $userId = null, ?string $searchString = null, ?int $limit = null, int $offset = 0): array {

Check warning on line 44 in lib/Db/SubmissionMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/SubmissionMapper.php#L44

Added line #L44 was not covered by tests
$qb = $this->db->getQueryBuilder();

$filters = [
Expand All @@ -61,15 +61,18 @@
->setMaxResults($limit);

// If a query is provided, join the answers table and filter by the query text
if (!is_null($query) && $query !== '') {
if (!is_null($searchString) && $searchString !== '') {

Check warning on line 64 in lib/Db/SubmissionMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/SubmissionMapper.php#L64

Added line #L64 was not covered by tests
$qb->join(
'submissions',
$this->answerMapper->getTableName(),
'answers',
$qb->expr()->eq('submissions.id', 'answers.submission_id')
)
->andWhere(
$qb->expr()->like('answers.text', $qb->createNamedParameter('%' . $query . '%'))
$qb->expr()->orX(
$qb->expr()->iLike('submissions.user_id', $qb->createNamedParameter('%' . $searchString . '%')),
$qb->expr()->iLike('answers.text', $qb->createNamedParameter('%' . $searchString . '%')),
),

Check warning on line 75 in lib/Db/SubmissionMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/SubmissionMapper.php#L72-L75

Added lines #L72 - L75 were not covered by tests
);
}

Expand Down Expand Up @@ -156,7 +159,10 @@
$qb->expr()->eq('submissions.id', 'answers.submission_id')
)
->andWhere(
$qb->expr()->like('answers.text', $qb->createNamedParameter('%' . $searchString . '%'))
$qb->expr()->orX(
$qb->expr()->iLike('submissions.user_id', $qb->createNamedParameter('%' . $searchString . '%')),
$qb->expr()->iLike('answers.text', $qb->createNamedParameter('%' . $searchString . '%')),
),

Check warning on line 165 in lib/Db/SubmissionMapper.php

View check run for this annotation

Codecov / codecov/patch

lib/Db/SubmissionMapper.php#L162-L165

Added lines #L162 - L165 were not covered by tests
);
}

Expand Down
Loading