ITags.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Reiter <ockham@raz.or.at>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Tanghus <thomas@tanghus.net>
  11. * @author Vincent Petry <vincent@nextcloud.com>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. // use OCP namespace for all classes that are considered public.
  29. // This means that they should be used by apps instead of the internal ownCloud classes
  30. namespace OCP;
  31. use OC\Tags;
  32. /**
  33. * Class for easily tagging objects by their id
  34. *
  35. * A tag can be e.g. 'Family', 'Work', 'Chore', 'Special Occation' or
  36. * anything else that is either parsed from a vobject or that the user chooses
  37. * to add.
  38. * Tag names are not case-sensitive, but will be saved with the case they
  39. * are entered in. If a user already has a tag 'family' for a type, and
  40. * tries to add a tag named 'Family' it will be silently ignored.
  41. * @since 6.0.0
  42. */
  43. interface ITags {
  44. /**
  45. * @since 19.0.0
  46. */
  47. public const TAG_FAVORITE = '_$!<Favorite>!$_';
  48. /**
  49. * Check if any tags are saved for this type and user.
  50. * @since 6.0.0
  51. */
  52. public function isEmpty(): bool;
  53. /**
  54. * Returns an array mapping a given tag's properties to its values:
  55. * ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
  56. *
  57. * @param string $id The ID of the tag that is going to be mapped
  58. * @return array|false
  59. * @since 8.0.0
  60. */
  61. public function getTag(string $id);
  62. /**
  63. * Get the tags for a specific user.
  64. *
  65. * This returns an array with id/name maps:
  66. *
  67. * ```php
  68. * [
  69. * ['id' => 0, 'name' = 'First tag'],
  70. * ['id' => 1, 'name' = 'Second tag'],
  71. * ]
  72. * ```
  73. *
  74. * @return array<array-key, array{id: int, name: string}>
  75. * @since 6.0.0
  76. */
  77. public function getTags(): array;
  78. /**
  79. * Get a list of tags for the given item ids.
  80. *
  81. * This returns an array with object id / tag names:
  82. *
  83. * ```php
  84. * [
  85. * 1 => array('First tag', 'Second tag'),
  86. * 2 => array('Second tag'),
  87. * 3 => array('Second tag', 'Third tag'),
  88. * ]
  89. * ```
  90. *
  91. * @param array $objIds item ids
  92. * @return array|false with object id as key and an array
  93. * of tag names as value or false if an error occurred
  94. * @since 8.0.0
  95. */
  96. public function getTagsForObjects(array $objIds);
  97. /**
  98. * Get a list of items tagged with $tag.
  99. *
  100. * Throws an exception if the tag could not be found.
  101. *
  102. * @param string|integer $tag Tag id or name.
  103. * @return array|false An array of object ids or false on error.
  104. * @since 6.0.0
  105. */
  106. public function getIdsForTag($tag);
  107. /**
  108. * Checks whether a tag is already saved.
  109. *
  110. * @param string $name The name to check for.
  111. * @since 6.0.0
  112. */
  113. public function hasTag(string $name): bool;
  114. /**
  115. * Checks whether a tag is saved for the given user,
  116. * disregarding the ones shared with him or her.
  117. *
  118. * @param string $name The tag name to check for.
  119. * @param string $user The user whose tags are to be checked.
  120. * @return bool
  121. * @since 8.0.0
  122. */
  123. public function userHasTag(string $name, string $user): bool;
  124. /**
  125. * Add a new tag.
  126. *
  127. * @param string $name A string with a name of the tag
  128. * @return int|false the id of the added tag or false if it already exists.
  129. * @since 6.0.0
  130. */
  131. public function add(string $name);
  132. /**
  133. * Rename tag.
  134. *
  135. * @param string|integer $from The name or ID of the existing tag
  136. * @param string $to The new name of the tag.
  137. * @return bool
  138. * @since 6.0.0
  139. */
  140. public function rename($from, string $to): bool;
  141. /**
  142. * Add a list of new tags.
  143. *
  144. * @param string|string[] $names A string with a name or an array of strings containing
  145. * the name(s) of the to add.
  146. * @param bool $sync When true, save the tags
  147. * @param int|null $id int Optional object id to add to this|these tag(s)
  148. * @return bool Returns false on error.
  149. * @since 6.0.0
  150. */
  151. public function addMultiple($names, bool $sync = false, ?int $id = null): bool;
  152. /**
  153. * Delete tag/object relations from the db
  154. *
  155. * @param array $ids The ids of the objects
  156. * @return boolean Returns false on error.
  157. * @since 6.0.0
  158. */
  159. public function purgeObjects(array $ids);
  160. /**
  161. * Get favorites for an object type
  162. *
  163. * @return array|false An array of object ids.
  164. * @since 6.0.0
  165. */
  166. public function getFavorites();
  167. /**
  168. * Add an object to favorites
  169. *
  170. * @param int $objid The id of the object
  171. * @return boolean
  172. * @since 6.0.0
  173. */
  174. public function addToFavorites($objid);
  175. /**
  176. * Remove an object from favorites
  177. *
  178. * @param int $objid The id of the object
  179. * @return boolean
  180. * @since 6.0.0
  181. */
  182. public function removeFromFavorites($objid);
  183. /**
  184. * Creates a tag/object relation.
  185. *
  186. * @param int $objid The id of the object
  187. * @param string $tag The id or name of the tag
  188. * @return boolean Returns false on database error.
  189. * @since 6.0.0
  190. */
  191. public function tagAs($objid, $tag);
  192. /**
  193. * Delete single tag/object relation from the db
  194. *
  195. * @param int $objid The id of the object
  196. * @param string $tag The id or name of the tag
  197. * @return boolean
  198. * @since 6.0.0
  199. */
  200. public function unTag($objid, $tag);
  201. /**
  202. * Delete tags from the database
  203. *
  204. * @param string[]|integer[] $names An array of tags (names or IDs) to delete
  205. * @return bool Returns false on error
  206. * @since 6.0.0
  207. */
  208. public function delete($names);
  209. }