You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemTagsRelationsCollection.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Vincent Petry <vincent@nextcloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\DAV\SystemTag;
  28. use OCP\IGroupManager;
  29. use OCP\IUserSession;
  30. use OCP\SystemTag\ISystemTagManager;
  31. use OCP\SystemTag\ISystemTagObjectMapper;
  32. use OCP\SystemTag\SystemTagsEntityEvent;
  33. use Sabre\DAV\Exception\Forbidden;
  34. use Sabre\DAV\SimpleCollection;
  35. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  36. class SystemTagsRelationsCollection extends SimpleCollection {
  37. /**
  38. * SystemTagsRelationsCollection constructor.
  39. *
  40. * @param ISystemTagManager $tagManager
  41. * @param ISystemTagObjectMapper $tagMapper
  42. * @param IUserSession $userSession
  43. * @param IGroupManager $groupManager
  44. * @param EventDispatcherInterface $dispatcher
  45. */
  46. public function __construct(
  47. ISystemTagManager $tagManager,
  48. ISystemTagObjectMapper $tagMapper,
  49. IUserSession $userSession,
  50. IGroupManager $groupManager,
  51. EventDispatcherInterface $dispatcher
  52. ) {
  53. $children = [
  54. new SystemTagsObjectTypeCollection(
  55. 'files',
  56. $tagManager,
  57. $tagMapper,
  58. $userSession,
  59. $groupManager,
  60. function ($name) {
  61. $nodes = \OC::$server->getUserFolder()->getById((int)$name);
  62. return !empty($nodes);
  63. }
  64. ),
  65. ];
  66. $event = new SystemTagsEntityEvent(SystemTagsEntityEvent::EVENT_ENTITY);
  67. $dispatcher->dispatch(SystemTagsEntityEvent::EVENT_ENTITY, $event);
  68. foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
  69. $children[] = new SystemTagsObjectTypeCollection(
  70. $entity,
  71. $tagManager,
  72. $tagMapper,
  73. $userSession,
  74. $groupManager,
  75. $entityExistsFunction
  76. );
  77. }
  78. parent::__construct('root', $children);
  79. }
  80. public function getName() {
  81. return 'systemtags-relations';
  82. }
  83. public function setName($name) {
  84. throw new Forbidden('Permission denied to rename this collection');
  85. }
  86. }