1
0

ProxyMapper.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\CalDAV\Proxy;
  27. use OCP\AppFramework\Db\QBMapper;
  28. use OCP\IDBConnection;
  29. /**
  30. * Class ProxyMapper
  31. *
  32. * @package OCA\DAV\CalDAV\Proxy
  33. *
  34. * @template-extends QBMapper<Proxy>
  35. */
  36. class ProxyMapper extends QBMapper {
  37. public const PERMISSION_READ = 1;
  38. public const PERMISSION_WRITE = 2;
  39. /**
  40. * ProxyMapper constructor.
  41. *
  42. * @param IDBConnection $db
  43. */
  44. public function __construct(IDBConnection $db) {
  45. parent::__construct($db, 'dav_cal_proxy', Proxy::class);
  46. }
  47. /**
  48. * @param string $proxyId The principal uri that can act as a proxy for the resulting calendars
  49. *
  50. * @return Proxy[]
  51. */
  52. public function getProxiesFor(string $proxyId): array {
  53. $qb = $this->db->getQueryBuilder();
  54. $qb->select('*')
  55. ->from($this->getTableName())
  56. ->where($qb->expr()->eq('proxy_id', $qb->createNamedParameter($proxyId)));
  57. return $this->findEntities($qb);
  58. }
  59. /**
  60. * @param string $ownerId The principal uri that has the resulting proxies for their calendars
  61. *
  62. * @return Proxy[]
  63. */
  64. public function getProxiesOf(string $ownerId): array {
  65. $qb = $this->db->getQueryBuilder();
  66. $qb->select('*')
  67. ->from($this->getTableName())
  68. ->where($qb->expr()->eq('owner_id', $qb->createNamedParameter($ownerId)));
  69. return $this->findEntities($qb);
  70. }
  71. }