ITags.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. // use OCP namespace for all classes that are considered public.
  8. // This means that they should be used by apps instead of the internal Nextcloud classes
  9. namespace OCP;
  10. use OC\Tags;
  11. /**
  12. * Class for easily tagging objects by their id
  13. *
  14. * A tag can be e.g. 'Family', 'Work', 'Chore', 'Special Occation' or
  15. * anything else that is either parsed from a vobject or that the user chooses
  16. * to add.
  17. * Tag names are not case-sensitive, but will be saved with the case they
  18. * are entered in. If a user already has a tag 'family' for a type, and
  19. * tries to add a tag named 'Family' it will be silently ignored.
  20. * @since 6.0.0
  21. */
  22. interface ITags {
  23. /**
  24. * @since 19.0.0
  25. */
  26. public const TAG_FAVORITE = '_$!<Favorite>!$_';
  27. /**
  28. * Check if any tags are saved for this type and user.
  29. * @since 6.0.0
  30. */
  31. public function isEmpty(): bool;
  32. /**
  33. * Returns an array mapping a given tag's properties to its values:
  34. * ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
  35. *
  36. * @param string $id The ID of the tag that is going to be mapped
  37. * @return array|false
  38. * @since 8.0.0
  39. */
  40. public function getTag(string $id);
  41. /**
  42. * Get the tags for a specific user.
  43. *
  44. * This returns an array with id/name maps:
  45. *
  46. * ```php
  47. * [
  48. * ['id' => 0, 'name' = 'First tag'],
  49. * ['id' => 1, 'name' = 'Second tag'],
  50. * ]
  51. * ```
  52. *
  53. * @return array<array-key, array{id: int, name: string}>
  54. * @since 6.0.0
  55. */
  56. public function getTags(): array;
  57. /**
  58. * Get a list of tags for the given item ids.
  59. *
  60. * This returns an array with object id / tag names:
  61. *
  62. * ```php
  63. * [
  64. * 1 => array('First tag', 'Second tag'),
  65. * 2 => array('Second tag'),
  66. * 3 => array('Second tag', 'Third tag'),
  67. * ]
  68. * ```
  69. *
  70. * @param array $objIds item ids
  71. * @return array|false with object id as key and an array
  72. * of tag names as value or false if an error occurred
  73. * @since 8.0.0
  74. */
  75. public function getTagsForObjects(array $objIds);
  76. /**
  77. * Get a list of items tagged with $tag.
  78. *
  79. * Throws an exception if the tag could not be found.
  80. *
  81. * @param string|integer $tag Tag id or name.
  82. * @return array|false An array of object ids or false on error.
  83. * @since 6.0.0
  84. */
  85. public function getIdsForTag($tag);
  86. /**
  87. * Checks whether a tag is already saved.
  88. *
  89. * @param string $name The name to check for.
  90. * @since 6.0.0
  91. */
  92. public function hasTag(string $name): bool;
  93. /**
  94. * Checks whether a tag is saved for the given user,
  95. * disregarding the ones shared with him or her.
  96. *
  97. * @param string $name The tag name to check for.
  98. * @param string $user The user whose tags are to be checked.
  99. * @return bool
  100. * @since 8.0.0
  101. */
  102. public function userHasTag(string $name, string $user): bool;
  103. /**
  104. * Add a new tag.
  105. *
  106. * @param string $name A string with a name of the tag
  107. * @return int|false the id of the added tag or false if it already exists.
  108. * @since 6.0.0
  109. */
  110. public function add(string $name);
  111. /**
  112. * Rename tag.
  113. *
  114. * @param string|integer $from The name or ID of the existing tag
  115. * @param string $to The new name of the tag.
  116. * @return bool
  117. * @since 6.0.0
  118. */
  119. public function rename($from, string $to): bool;
  120. /**
  121. * Add a list of new tags.
  122. *
  123. * @param string|string[] $names A string with a name or an array of strings containing
  124. * the name(s) of the to add.
  125. * @param bool $sync When true, save the tags
  126. * @param int|null $id int Optional object id to add to this|these tag(s)
  127. * @return bool Returns false on error.
  128. * @since 6.0.0
  129. */
  130. public function addMultiple($names, bool $sync = false, ?int $id = null): bool;
  131. /**
  132. * Delete tag/object relations from the db
  133. *
  134. * @param array $ids The ids of the objects
  135. * @return boolean Returns false on error.
  136. * @since 6.0.0
  137. */
  138. public function purgeObjects(array $ids);
  139. /**
  140. * Get favorites for an object type
  141. *
  142. * @return array|false An array of object ids.
  143. * @since 6.0.0
  144. */
  145. public function getFavorites();
  146. /**
  147. * Add an object to favorites
  148. *
  149. * @param int $objid The id of the object
  150. * @return boolean
  151. * @since 6.0.0
  152. */
  153. public function addToFavorites($objid);
  154. /**
  155. * Remove an object from favorites
  156. *
  157. * @param int $objid The id of the object
  158. * @return boolean
  159. * @since 6.0.0
  160. */
  161. public function removeFromFavorites($objid);
  162. /**
  163. * Creates a tag/object relation.
  164. *
  165. * @param int $objid The id of the object
  166. * @param string $tag The id or name of the tag
  167. * @return boolean Returns false on database error.
  168. * @since 6.0.0
  169. */
  170. public function tagAs($objid, $tag);
  171. /**
  172. * Delete single tag/object relation from the db
  173. *
  174. * @param int $objid The id of the object
  175. * @param string $tag The id or name of the tag
  176. * @return boolean
  177. * @since 6.0.0
  178. */
  179. public function unTag($objid, $tag);
  180. /**
  181. * Delete tags from the database
  182. *
  183. * @param string[]|integer[] $names An array of tags (names or IDs) to delete
  184. * @return bool Returns false on error
  185. * @since 6.0.0
  186. */
  187. public function delete($names);
  188. }