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.

ITags.php 5.8KB

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