|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\Mail\Db; |
| 11 | + |
| 12 | +use OCP\AppFramework\Db\DoesNotExistException; |
| 13 | +use OCP\AppFramework\Db\QBMapper; |
| 14 | +use OCP\IDBConnection; |
| 15 | + |
| 16 | +/** |
| 17 | + * @template-extends QBMapper<Delegation> |
| 18 | + */ |
| 19 | +class DelegationMapper extends QBMapper { |
| 20 | + public function __construct(IDBConnection $db) { |
| 21 | + parent::__construct($db, 'mail_delegations'); |
| 22 | + } |
| 23 | + |
| 24 | + public function findDelegatedAccountsForUser(string $uid): array { |
| 25 | + $qb = $this->db->getQueryBuilder(); |
| 26 | + |
| 27 | + $select = $qb->select('account_id') |
| 28 | + ->from($this->getTableName()) |
| 29 | + ->where( |
| 30 | + $qb->expr()->eq('user_id', $qb->createNamedParameter($uid)) |
| 31 | + ); |
| 32 | + |
| 33 | + $rows = $this->findEntities($select); |
| 34 | + |
| 35 | + return $rows; |
| 36 | + } |
| 37 | + |
| 38 | + public function findDelegatedToUsers(string $accountId) : array { |
| 39 | + $qb = $this->db->getQueryBuilder(); |
| 40 | + |
| 41 | + $select = $qb->select('user_id') |
| 42 | + ->from($this->getTableName()) |
| 43 | + ->where( |
| 44 | + $qb->expr()->eq('account_id', $qb->createNamedParameter($accountId)) |
| 45 | + ); |
| 46 | + |
| 47 | + $rows = $this->findEntities($select); |
| 48 | + return $rows; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @throws DoesNotExistException |
| 53 | + */ |
| 54 | + public function find(int $accountId, string $uid): Actions { |
| 55 | + $qb = $this->db->getQueryBuilder(); |
| 56 | + $qb->select('*') |
| 57 | + ->from($this->getTableName()) |
| 58 | + ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($uid))) |
| 59 | + ->andWhere($qb->expr()->eq('account_id', $qb->createNamedParameter($accountId))); |
| 60 | + return $this->findEntity($qb); |
| 61 | + } |
| 62 | +} |
0 commit comments