ICommentsManager.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCP\Comments;
  25. /**
  26. * Interface ICommentsManager
  27. *
  28. * This class manages the access to comments
  29. *
  30. * @package OCP\Comments
  31. * @since 9.0.0
  32. */
  33. interface ICommentsManager {
  34. /**
  35. * @const DELETED_USER type and id for a user that has been deleted
  36. * @see deleteReferencesOfActor
  37. * @since 9.0.0
  38. *
  39. * To be used as replacement for user type actors in deleteReferencesOfActor().
  40. *
  41. * User interfaces shall show "Deleted user" as display name, if needed.
  42. */
  43. const DELETED_USER = 'deleted_users';
  44. /**
  45. * returns a comment instance
  46. *
  47. * @param string $id the ID of the comment
  48. * @return IComment
  49. * @throws NotFoundException
  50. * @since 9.0.0
  51. */
  52. public function get($id);
  53. /**
  54. * returns the comment specified by the id and all it's child comments
  55. *
  56. * @param string $id
  57. * @param int $limit max number of entries to return, 0 returns all
  58. * @param int $offset the start entry
  59. * @return array
  60. * @since 9.0.0
  61. *
  62. * The return array looks like this
  63. * [
  64. * 'comment' => IComment, // root comment
  65. * 'replies' =>
  66. * [
  67. * 0 =>
  68. * [
  69. * 'comment' => IComment,
  70. * 'replies' =>
  71. * [
  72. * 0 =>
  73. * [
  74. * 'comment' => IComment,
  75. * 'replies' => [ … ]
  76. * ],
  77. * …
  78. * ]
  79. * ]
  80. * 1 =>
  81. * [
  82. * 'comment' => IComment,
  83. * 'replies'=> [ … ]
  84. * ],
  85. * …
  86. * ]
  87. * ]
  88. */
  89. public function getTree($id, $limit = 0, $offset = 0);
  90. /**
  91. * returns comments for a specific object (e.g. a file).
  92. *
  93. * The sort order is always newest to oldest.
  94. *
  95. * @param string $objectType the object type, e.g. 'files'
  96. * @param string $objectId the id of the object
  97. * @param int $limit optional, number of maximum comments to be returned. if
  98. * not specified, all comments are returned.
  99. * @param int $offset optional, starting point
  100. * @param \DateTime $notOlderThan optional, timestamp of the oldest comments
  101. * that may be returned
  102. * @return IComment[]
  103. * @since 9.0.0
  104. */
  105. public function getForObject(
  106. $objectType,
  107. $objectId,
  108. $limit = 0,
  109. $offset = 0,
  110. \DateTime $notOlderThan = null
  111. );
  112. /**
  113. * @param $objectType string the object type, e.g. 'files'
  114. * @param $objectId string the id of the object
  115. * @param \DateTime $notOlderThan optional, timestamp of the oldest comments
  116. * that may be returned
  117. * @return Int
  118. * @since 9.0.0
  119. */
  120. public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null);
  121. /**
  122. * creates a new comment and returns it. At this point of time, it is not
  123. * saved in the used data storage. Use save() after setting other fields
  124. * of the comment (e.g. message or verb).
  125. *
  126. * @param string $actorType the actor type (e.g. 'users')
  127. * @param string $actorId a user id
  128. * @param string $objectType the object type the comment is attached to
  129. * @param string $objectId the object id the comment is attached to
  130. * @return IComment
  131. * @since 9.0.0
  132. */
  133. public function create($actorType, $actorId, $objectType, $objectId);
  134. /**
  135. * permanently deletes the comment specified by the ID
  136. *
  137. * When the comment has child comments, their parent ID will be changed to
  138. * the parent ID of the item that is to be deleted.
  139. *
  140. * @param string $id
  141. * @return bool
  142. * @since 9.0.0
  143. */
  144. public function delete($id);
  145. /**
  146. * saves the comment permanently
  147. *
  148. * if the supplied comment has an empty ID, a new entry comment will be
  149. * saved and the instance updated with the new ID.
  150. *
  151. * Otherwise, an existing comment will be updated.
  152. *
  153. * Throws NotFoundException when a comment that is to be updated does not
  154. * exist anymore at this point of time.
  155. *
  156. * @param IComment $comment
  157. * @return bool
  158. * @throws NotFoundException
  159. * @since 9.0.0
  160. */
  161. public function save(IComment $comment);
  162. /**
  163. * removes references to specific actor (e.g. on user delete) of a comment.
  164. * The comment itself must not get lost/deleted.
  165. *
  166. * A 'users' type actor (type and id) should get replaced by the
  167. * value of the DELETED_USER constant of this interface.
  168. *
  169. * @param string $actorType the actor type (e.g. 'users')
  170. * @param string $actorId a user id
  171. * @return boolean
  172. * @since 9.0.0
  173. */
  174. public function deleteReferencesOfActor($actorType, $actorId);
  175. /**
  176. * deletes all comments made of a specific object (e.g. on file delete)
  177. *
  178. * @param string $objectType the object type (e.g. 'files')
  179. * @param string $objectId e.g. the file id
  180. * @return boolean
  181. * @since 9.0.0
  182. */
  183. public function deleteCommentsAtObject($objectType, $objectId);
  184. /**
  185. * sets the read marker for a given file to the specified date for the
  186. * provided user
  187. *
  188. * @param string $objectType
  189. * @param string $objectId
  190. * @param \DateTime $dateTime
  191. * @param \OCP\IUser $user
  192. * @since 9.0.0
  193. */
  194. public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user);
  195. /**
  196. * returns the read marker for a given file to the specified date for the
  197. * provided user. It returns null, when the marker is not present, i.e.
  198. * no comments were marked as read.
  199. *
  200. * @param string $objectType
  201. * @param string $objectId
  202. * @param \OCP\IUser $user
  203. * @return \DateTime|null
  204. * @since 9.0.0
  205. */
  206. public function getReadMark($objectType, $objectId, \OCP\IUser $user);
  207. /**
  208. * deletes the read markers for the specified user
  209. *
  210. * @param \OCP\IUser $user
  211. * @return bool
  212. * @since 9.0.0
  213. */
  214. public function deleteReadMarksFromUser(\OCP\IUser $user);
  215. /**
  216. * deletes the read markers on the specified object
  217. *
  218. * @param string $objectType
  219. * @param string $objectId
  220. * @return bool
  221. * @since 9.0.0
  222. */
  223. public function deleteReadMarksOnObject($objectType, $objectId);
  224. }