ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.NotesManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Notes;
22
27{
36
37 public function __construct(
41 ) {
42 $this->data = $data;
43 $this->repo = $repo;
44 $this->domain = $domain;
45 $this->sess_repo = $repo->notesSession();
46 $this->db_repo = $repo->note();
47 $this->db_settings_repo = $repo->settings();
48 $this->note_access = $domain->noteAccess();
49 $this->notification = $domain->notification();
50 }
51
52 public function setSortAscending(bool $asc): void
53 {
54 $this->sess_repo->setSortAscending($asc);
55 }
56
57 public function getSortAscending(): bool
58 {
59 return $this->sess_repo->getSortAscending();
60 }
61
62 public function createNote(
63 Note $note,
64 array $observer,
65 bool $use_provided_creation_date = false
66 ): void {
67 if (!$use_provided_creation_date) {
68 $note = $note->withCreationDate(\ilUtil::now());
69 }
70 $note = $this->db_repo->createNote($note);
71 $this->notification->sendNotifications($note, false);
72 $this->notification->notifyObserver($observer, "new", $note);
73 }
74
75 public function deleteNote(Note $note, int $user_id, $public_deletion_enabled = false): void
76 {
77 if ($this->note_access->canDelete($note, $user_id, $public_deletion_enabled)) {
78 $this->db_repo->deleteNote($note->getId());
79 }
80 }
81
82 public function updateNoteText(
83 int $id,
84 string $text,
85 array $observer
86 ): void {
87 $note = $this->db_repo->getById($id);
88 if ($this->note_access->canEdit($note)) {
89 $this->db_repo->updateNoteText($id, $text);
90 $note = $this->db_repo->getById($id);
91 $this->notification->sendNotifications($note, true);
92 $this->notification->notifyObserver($observer, "update", $note);
93 }
94 }
95
100 public function getNotesForContext(
102 int $type = Note::PRIVATE,
103 bool $incl_sub = false,
104 int $author = 0,
105 bool $ascending = false,
106 string $since = "",
107 string $search_text = ""
108 ): array {
109 return $this->db_repo->getNotesForContext(
110 $context,
111 $type,
112 $incl_sub,
113 $author,
114 $ascending,
115 $since,
116 $search_text
117 );
118 }
119
125 int $obj_id,
126 int $type = Note::PRIVATE,
127 bool $incl_sub = false,
128 int $author = 0,
129 bool $ascending = false,
130 string $since = ""
131 ): array {
132 $context = $this->data->context(
133 $obj_id,
134 0,
135 ""
136 );
137 return $this->db_repo->getNotesForContext(
138 $context,
139 $type,
140 $incl_sub,
141 $author,
142 $ascending,
143 $since
144 );
145 }
146
153 array $obj_ids,
154 int $type = Note::PRIVATE,
155 bool $incl_sub = false,
156 int $author = 0,
157 bool $ascending = false,
158 string $since = "",
159 string $search_text = ""
160 ): array {
161 return $this->db_repo->getNotesForObjIds(
162 $obj_ids,
163 $type,
164 $incl_sub,
165 $author,
166 $ascending,
167 $since,
168 $search_text
169 );
170 }
171
172
173 public function getNrOfNotesForContext(
175 int $type = Note::PRIVATE,
176 bool $incl_sub = false,
177 int $author = 0
178 ): int {
179 return $this->db_repo->getNrOfNotesForContext(
180 $context,
181 $type,
182 $incl_sub,
183 $author
184 );
185 }
186
193 public function getRelatedObjectsOfUser(int $type): array
194 {
195 $tree = $this->domain->repositoryTree();
196 $user_id = $this->domain->user()->getId();
197 $fav_rep = new \ilFavouritesDBRepository();
198
199 $ids = $this->db_repo->getRelatedObjIdsOfUser($user_id, $type);
200 $ids = array_filter($ids, function ($id) {
201 return \ilObject::_exists($id);
202 });
203
204 if ($type === Note::PUBLIC) {
205 // additionally all objects on the personal desktop of the user
206 // that have at least on comment
207 $fav_obj_ids = array_map(function ($i) {
208 return $i["obj_id"];
209 }, $fav_rep->getFavouritesOfUser($user_id));
210 if (count($fav_obj_ids) > 0) {
211 $fav_obj_ids = $this->db_repo->filterObjectsWithNotes($fav_obj_ids, Note::PUBLIC);
212 $ids = array_unique(array_merge($ids, $fav_obj_ids));
213 }
214
215 $ids = array_filter($ids, function ($id) {
216 return $this->commentsActive($id);
217 });
218 }
219
220 $wsp_tree = new \ilWorkspaceTree($user_id);
221
222 $ids = array_filter($ids, function ($id) use ($wsp_tree) {
224 return true;
225 }
226 if ($wsp_tree->lookupNodeId($id) > 0) {
227 return true;
228 }
229 return false;
230 });
231
232 return $ids;
233 }
234
238 public function getById(int $id): Note
239 {
240 return $this->db_repo->getById($id);
241 }
242
246 public function commentsActive(
247 int $obj_id
248 ): bool {
249 return $this->db_settings_repo->commentsActive($obj_id);
250 }
251
252 public function commentsActiveMultiple(
253 array $obj_ids
254 ): array {
255 return $this->db_settings_repo->commentsActiveMultiple($obj_ids);
256 }
257
261 public function activateComments(
262 int $obj_id,
263 bool $a_activate = true
264 ): void {
265 $this->db_settings_repo->activateComments(
266 $obj_id,
267 0,
268 \ilObject::_lookupType($obj_id),
269 $a_activate
270 );
271 }
272
276 public function getUserCount(
277 int $obj_id,
278 int $sub_obj_id,
279 string $obj_type
280 ): int {
281 return $this->db_repo->getUserCount($obj_id, $sub_obj_id, $obj_type);
282 }
283
289 array $obj_ids,
290 bool $no_sub_objs = false
291 ): array {
292 return $this->db_repo->countNotesAndCommentsMultipleObjects(
293 $obj_ids,
294 $this->domain->user()->getId(),
295 $no_sub_objs
296 );
297 }
298}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
withCreationDate(string $creation_date)
Definition: class.Note.php:61
createNote(Note $note, array $observer, bool $use_provided_creation_date=false)
getNrOfNotesForContext(Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0)
deleteNote(Note $note, int $user_id, $public_deletion_enabled=false)
getNotesForRepositoryObjId(int $obj_id, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, string $since="")
Get all notes related to a specific repository object.
updateNoteText(int $id, string $text, array $observer)
getNotesForContext(Context $context, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, string $since="", string $search_text="")
Get all notes related to a specific context.
InternalDataService $data
activateComments(int $obj_id, bool $a_activate=true)
Activate notes feature.
InternalDomainService $domain
__construct(InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain)
NotificationsManager $notification
commentsActiveMultiple(array $obj_ids)
InternalRepoService $repo
getRelatedObjectsOfUser(int $type)
Get all untrashed objects that have either notes/comments of the user attached, or are favourites of ...
countNotesAndCommentsMultipleObjects(array $obj_ids, bool $no_sub_objs=false)
Get all notes related to multiple repository objects (current user)
getNotesForRepositoryObjIds(array $obj_ids, int $type=Note::PRIVATE, bool $incl_sub=false, int $author=0, bool $ascending=false, string $since="", string $search_text="")
Get all notes related to a specific repository object.
getUserCount(int $obj_id, int $sub_obj_id, string $obj_type)
How many users have attached a note/comment to a given object?
NoteSettingsDBRepository $db_settings_repo
commentsActive(int $obj_id)
Are comments activated for object?
NotesSessionRepository $sess_repo
Class ilObject Basic functions for all objects.
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static now()
Return current timestamp in Y-m-d H:i:s format.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))
$context
Definition: webdav.php:31