-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathAnswerMapper.php
More file actions
79 lines (64 loc) · 1.87 KB
/
AnswerMapper.php
File metadata and controls
79 lines (64 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Forms\Db;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**
* @extends QBMapper<Answer>
*/
class AnswerMapper extends QBMapper {
/**
* AnswerMapper constructor.
* @param IDBConnection $db
*/
public function __construct(IDBConnection $db) {
parent::__construct($db, 'forms_v2_answers', Answer::class);
}
/**
* @param int $submissionId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Answer[]
*/
public function findBySubmission(int $submissionId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('submission_id', $qb->createNamedParameter($submissionId, IQueryBuilder::PARAM_INT))
);
return $this->findEntities($qb);
}
/**
* @param int $submissionId
*/
public function deleteBySubmission(int $submissionId): void {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where(
$qb->expr()->eq('submission_id', $qb->createNamedParameter($submissionId, IQueryBuilder::PARAM_INT))
);
$qb->executeStatement();
}
/**
* Collect all fileIds for answers of a specific submission
* @param int $submissionId
* @return int[] Array of fileIds
*/
public function findFileIdsBySubmission(int $submissionId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('file_id')
->from($this->getTableName())
->where(
$qb->expr()->eq('submission_id', $qb->createNamedParameter($submissionId, IQueryBuilder::PARAM_INT))
)
->andWhere($qb->expr()->isNotNull('file_id'));
$result = $qb->executeQuery();
$rows = $result->fetchFirstColumn();
$result->closeCursor();
return array_map('intval', $rows);
}
}