ProxyMapper.php 2.1 KB

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