ISystemTagObjectMapper.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  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, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCP\SystemTag;
  26. /**
  27. * Public interface to access and manage system-wide tags.
  28. *
  29. * @since 9.0.0
  30. */
  31. interface ISystemTagObjectMapper {
  32. /**
  33. * Get a list of tag ids for the given object ids.
  34. *
  35. * This returns an array that maps object id to tag ids
  36. * [
  37. * 1 => array('id1', 'id2'),
  38. * 2 => array('id3', 'id2'),
  39. * 3 => array('id5'),
  40. * 4 => array()
  41. * ]
  42. *
  43. * Untagged objects will have an empty array associated.
  44. *
  45. * @param string|array $objIds object ids
  46. * @param string $objectType object type
  47. *
  48. * @return array with object id as key and an array
  49. * of tag ids as value
  50. *
  51. * @since 9.0.0
  52. */
  53. public function getTagIdsForObjects($objIds, string $objectType): array;
  54. /**
  55. * Get a list of objects tagged with $tagIds.
  56. *
  57. * @param string|array $tagIds Tag id or array of tag ids.
  58. * @param string $objectType object type
  59. * @param int $limit Count of object ids you want to get
  60. * @param string $offset The last object id you already received
  61. *
  62. * @return string[] array of object ids or empty array if none found
  63. *
  64. * @throws TagNotFoundException if at least one of the
  65. * given tags does not exist
  66. * @throws \InvalidArgumentException When a limit is specified together with
  67. * multiple tag ids
  68. *
  69. * @since 9.0.0
  70. */
  71. public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0, string $offset = ''): array;
  72. /**
  73. * Assign the given tags to the given object.
  74. *
  75. * If at least one of the given tag ids doesn't exist, none of the tags
  76. * will be assigned.
  77. *
  78. * If the relationship already existed, fail silently.
  79. *
  80. * @param string $objId object id
  81. * @param string $objectType object type
  82. * @param string|array $tagIds tag id or array of tag ids to assign
  83. *
  84. * @throws TagNotFoundException if at least one of the
  85. * given tags does not exist
  86. *
  87. * @since 9.0.0
  88. */
  89. public function assignTags(string $objId, string $objectType, $tagIds);
  90. /**
  91. * Unassign the given tags from the given object.
  92. *
  93. * If at least one of the given tag ids doesn't exist, none of the tags
  94. * will be unassigned.
  95. *
  96. * If the relationship did not exist in the first place, fail silently.
  97. *
  98. * @param string $objId object id
  99. * @param string $objectType object type
  100. * @param string|array $tagIds tag id or array of tag ids to unassign
  101. *
  102. * @throws TagNotFoundException if at least one of the
  103. * given tags does not exist
  104. *
  105. * @since 9.0.0
  106. */
  107. public function unassignTags(string $objId, string $objectType, $tagIds);
  108. /**
  109. * Checks whether the given objects have the given tag.
  110. *
  111. * @param string|array $objIds object ids
  112. * @param string $objectType object type
  113. * @param string $tagId tag id to check
  114. * @param bool $all true to check that ALL objects have the tag assigned,
  115. * false to check that at least ONE object has the tag.
  116. *
  117. * @return bool true if the condition set by $all is matched, false
  118. * otherwise
  119. *
  120. * @throws TagNotFoundException if the tag does not exist
  121. *
  122. * @since 9.0.0
  123. */
  124. public function haveTag($objIds, string $objectType, string $tagId, bool $all = true): bool;
  125. }