ProxyMapper.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV\Proxy;
  8. use OCP\AppFramework\Db\QBMapper;
  9. use OCP\IDBConnection;
  10. /**
  11. * Class ProxyMapper
  12. *
  13. * @package OCA\DAV\CalDAV\Proxy
  14. *
  15. * @template-extends QBMapper<Proxy>
  16. */
  17. class ProxyMapper extends QBMapper {
  18. public const PERMISSION_READ = 1;
  19. public const PERMISSION_WRITE = 2;
  20. /**
  21. * ProxyMapper constructor.
  22. *
  23. * @param IDBConnection $db
  24. */
  25. public function __construct(IDBConnection $db) {
  26. parent::__construct($db, 'dav_cal_proxy', Proxy::class);
  27. }
  28. /**
  29. * @param string $proxyId The principal uri that can act as a proxy for the resulting calendars
  30. *
  31. * @return Proxy[]
  32. */
  33. public function getProxiesFor(string $proxyId): array {
  34. $qb = $this->db->getQueryBuilder();
  35. $qb->select('*')
  36. ->from($this->getTableName())
  37. ->where($qb->expr()->eq('proxy_id', $qb->createNamedParameter($proxyId)));
  38. return $this->findEntities($qb);
  39. }
  40. /**
  41. * @param string $ownerId The principal uri that has the resulting proxies for their calendars
  42. *
  43. * @return Proxy[]
  44. */
  45. public function getProxiesOf(string $ownerId): array {
  46. $qb = $this->db->getQueryBuilder();
  47. $qb->select('*')
  48. ->from($this->getTableName())
  49. ->where($qb->expr()->eq('owner_id', $qb->createNamedParameter($ownerId)));
  50. return $this->findEntities($qb);
  51. }
  52. }