-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathWatchMapper.php
More file actions
71 lines (60 loc) · 1.8 KB
/
Copy pathWatchMapper.php
File metadata and controls
71 lines (60 loc) · 1.8 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
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Polls\Db;
use OCA\Polls\UserSession;
use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;
/**
* @template-extends QBMapper<Watch>
*/
class WatchMapper extends QBMapper {
public const TABLE = Watch::TABLE;
/** @psalm-suppress PossiblyUnusedMethod */
public function __construct(
IDBConnection $db,
protected UserSession $userSession,
) {
parent::__construct($db, Watch::TABLE, Watch::class);
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Watch[]
*/
public function findUpdatesForPollId(int $pollId, int $offset): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->gt('updated', $qb->createNamedParameter($offset)))
->andWhere(
$qb->expr()->neq('session_id', $qb->createNamedParameter($this->userSession->getClientIdHashed()))
)
->andWhere($qb->expr()->orX(
$qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId)),
$qb->expr()->eq('table', $qb->createNamedParameter(Watch::OBJECT_POLLS))
));
return $this->findEntities($qb);
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Watch
*/
public function findForPollIdAndTable(int $pollId, string $table): Watch {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('poll_id', $qb->createNamedParameter($pollId))
)
->andWhere(
$qb->expr()->eq('table', $qb->createNamedParameter($table))
)
->andWhere(
$qb->expr()->eq('session_id', $qb->createNamedParameter($this->userSession->getClientIdHashed()))
);
return $this->findEntity($qb);
}
}