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

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