ProxyMapper.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. class ProxyMapper extends QBMapper {
  35. public const PERMISSION_READ = 1;
  36. public const PERMISSION_WRITE = 2;
  37. /**
  38. * ProxyMapper constructor.
  39. *
  40. * @param IDBConnection $db
  41. */
  42. public function __construct(IDBConnection $db) {
  43. parent::__construct($db, 'dav_cal_proxy', Proxy::class);
  44. }
  45. /**
  46. * @param string $proxyId The principal uri that can act as a proxy for the resulting calendars
  47. *
  48. * @return Proxy[]
  49. */
  50. public function getProxiesFor(string $proxyId): array {
  51. $qb = $this->db->getQueryBuilder();
  52. $qb->select('*')
  53. ->from($this->getTableName())
  54. ->where($qb->expr()->eq('proxy_id', $qb->createNamedParameter($proxyId)));
  55. return $this->findEntities($qb);
  56. }
  57. /**
  58. * @param string $ownerId The principal uri that has the resulting proxies for their calendars
  59. *
  60. * @return Proxy[]
  61. */
  62. public function getProxiesOf(string $ownerId): array {
  63. $qb = $this->db->getQueryBuilder();
  64. $qb->select('*')
  65. ->from($this->getTableName())
  66. ->where($qb->expr()->eq('owner_id', $qb->createNamedParameter($ownerId)));
  67. return $this->findEntities($qb);
  68. }
  69. }