ILIAS  release_8 Revision v8.24
class.NotesManager.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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
206 // additionally all objects on the personal desktop of the user
207 // that have at least on comment
208 $fav_obj_ids = array_map(function ($i) {
209 return $i["obj_id"];
210 }, $fav_rep->getFavouritesOfUser($user_id));
211 if (count($fav_obj_ids) > 0) {
212 $fav_obj_ids = $this->db_repo->filterObjectsWithNotes($fav_obj_ids, Note::PUBLIC);
213 $ids = array_unique(array_merge($ids, $fav_obj_ids));
214 }
215
216 $ids = array_filter($ids, function ($id) {
217 return $this->commentsActive($id);
218 });
219 }
220
221 $wsp_tree = new \ilWorkspaceTree($user_id);
222
223 $ids = array_filter($ids, function ($id) use ($wsp_tree) {
225 return true;
226 }
227 if ($wsp_tree->lookupNodeId($id) > 0) {
228 return true;
229 }
230 return false;
231 });
232
233 return $ids;
234 }
235
239 public function getById(int $id): Note
240 {
241 return $this->db_repo->getById($id);
242 }
243
247 public function commentsActive(
248 int $obj_id
249 ): bool {
250 return $this->db_settings_repo->commentsActive($obj_id);
251 }
252
253 public function commentsActiveMultiple(
254 array $obj_ids
255 ): array {
256 return $this->db_settings_repo->commentsActiveMultiple($obj_ids);
257 }
258
262 public function activateComments(
263 int $obj_id,
264 bool $a_activate = true
265 ): void {
266 $this->db_settings_repo->activateComments(
267 $obj_id,
268 0,
269 \ilObject::_lookupType($obj_id),
270 $a_activate
271 );
272 }
273
277 public function getUserCount(
278 int $obj_id,
279 int $sub_obj_id,
280 string $obj_type
281 ): int {
282 return $this->db_repo->getUserCount($obj_id, $sub_obj_id, $obj_type);
283 }
284
290 array $obj_ids,
291 bool $no_sub_objs = false
292 ): array {
293 return $this->db_repo->countNotesAndCommentsMultipleObjects(
294 $obj_ids,
295 $this->domain->user()->getId(),
296 $no_sub_objs
297 );
298 }
299}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Repository internal data service.
withCreationDate(string $creation_date)
Definition: class.Note.php:57
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type
$context
Definition: webdav.php:29