diff --git a/docs/API_v3.md b/docs/API_v3.md index 89a4d8d39..a3b127b07 100644 --- a/docs/API_v3.md +++ b/docs/API_v3.md @@ -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 ``` diff --git a/lib/Db/SubmissionMapper.php b/lib/Db/SubmissionMapper.php index a67434d3a..367d94504 100644 --- a/lib/Db/SubmissionMapper.php +++ b/lib/Db/SubmissionMapper.php @@ -33,7 +33,7 @@ public function __construct( * * @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 * @@ -41,7 +41,7 @@ public function __construct( * @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 { $qb = $this->db->getQueryBuilder(); $filters = [ @@ -61,7 +61,7 @@ public function findByForm(int $formId, ?string $userId = null, ?string $query = ->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 !== '') { $qb->join( 'submissions', $this->answerMapper->getTableName(), @@ -69,7 +69,10 @@ public function findByForm(int $formId, ?string $userId = null, ?string $query = $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 . '%')), + ), ); } @@ -156,7 +159,10 @@ protected function countSubmissionsWithFilters(int $formId, ?string $userId = nu $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 . '%')), + ), ); }