ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPDNotesGUI.php
Go to the documentation of this file.
1<?php
2
23
30{
31 protected int $note_type;
32 protected string $search_text = "";
33 protected ?FilterAdapterGUI $filter = null;
34 protected \ILIAS\Notes\InternalGUIService $gui;
35 protected \ILIAS\DI\UIServices $ui;
37
38 protected ?int $current_rel_obj = null;
40
41 protected ilCtrl $ctrl;
42 protected ilObjUser $user;
43 protected ilTabsGUI $tabs;
44 protected ilHelpGUI $help;
50 protected ?array $related_objects = null;
51
52 public function __construct()
53 {
54 global $DIC;
55
56 $this->user = $DIC->user();
57 $this->tabs = $DIC->tabs();
58 $this->help = $DIC["ilHelp"];
59 $this->settings = $DIC->settings();
60 $this->access = $DIC->access();
61 $this->toolbar = $DIC->toolbar();
62 $tpl = $DIC["tpl"];
63 $lng = $DIC->language();
64 $ilCtrl = $DIC->ctrl();
65 $ilUser = $DIC->user();
66 $ilHelp = $DIC["ilHelp"];
67 $this->ui = $DIC->ui();
68
69 $this->request = $DIC->notes()
70 ->internal()
71 ->gui()
72 ->standardRequest();
73
74 $ilHelp->setScreenIdComponent("note");
75
76 $lng->loadLanguageModule("notes");
77
78 // initiate variables
79 $this->tpl = $tpl;
80 $this->lng = $lng;
81 $this->ctrl = $ilCtrl;
82
83 $this->notes_manager = $DIC->notes()->internal()->domain()->notes();
84 $this->gui = $DIC->notes()->internal()->gui();
85
86 // link from ilPDNotesBlockGUI
87 $rel_obj = $this->request->getRelatedObjId();
88 $this->note_type = ($this->request->getNoteType() === Note::PRIVATE || $ilCtrl->getCmd() === "getNotesHTML")
89 ? Note::PRIVATE
90 : Note::PUBLIC;
91 if ($ilCtrl->getCmd() === "getCommentsHTML") {
92 $this->note_type = Note::PUBLIC;
93 }
94 $this->ctrl->setParameter($this, "note_type", $this->note_type);
95 if ($rel_obj > 0) {
96 $ilUser->writePref("pd_notes_rel_obj" . $this->note_type, (string) $rel_obj);
97 }
98 // edit link
99 elseif ($this->request->getNoteId() > 0) {
100 $note = $this->notes_manager->getById($this->request->getNoteId());
101 $context = $note->getContext();
102 $ilUser->writePref("pd_notes_rel_obj" . $this->note_type, $context->getObjId());
103 }
104 $this->readFilter();
105 $ajax_url = $this->ctrl->getLinkTargetByClass(
106 ["ildashboardgui", "ilpdnotesgui", "ilnotegui"],
107 "",
108 "",
109 true,
110 false
111 );
112 $this->gui->initJavascript($ajax_url);
113 }
114
115 protected function readFilter(): void
116 {
117 $data = $this->getFilter()->getData();
118 if (!isset($data["object"]) || $data["object"] === "") {
119 $this->current_rel_obj = null;
120 } else {
121 $this->current_rel_obj = (int) $data["object"];
122 }
123 $this->search_text = $data["text"] ?? "";
124 }
125
126 public function executeCommand(): void
127 {
128 $next_class = $this->ctrl->getNextClass();
129 switch ($next_class) {
130 case "ilnotegui":
131 $this->displayHeader();
132 $this->view(); // forwardCommand is invoked in view() method
133 break;
134
135 case "ilcommentgui":
136 $this->displayHeader();
137 $this->view(); // forwardCommand is invoked in view() method
138 break;
139
140 default:
141 $cmd = $this->ctrl->getCmd("view");
142 $this->displayHeader();
143 $this->$cmd();
144 break;
145 }
146 $this->tpl->printToStdout(true);
147 }
148
149 public function displayHeader(): void
150 {
152
153 $t = $this->lng->txt("notes");
154 if (!$ilSetting->get("disable_notes") && !$ilSetting->get("disable_comments")) {
155 $t = $this->lng->txt("notes_and_comments");
156 }
157 if ($ilSetting->get("disable_notes")) {
158 $t = $this->lng->txt("notes_comments");
159 }
160
161 if ($this->note_type === Note::PRIVATE) {
162 $t = $this->lng->txt("private_notes");
163 $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_nots.svg"));
164 } else {
165 $t = $this->lng->txt("notes_public_comments");
166 $this->tpl->setTitleIcon(ilUtil::getImagePath("standard/icon_coms.svg"));
167 }
168
169 $this->tpl->setTitle($t);
170 }
171
172 protected function getRelatedObjects(): array
173 {
174 if (is_null($this->related_objects)) {
175 $this->related_objects = $this->notes_manager->getRelatedObjectsOfUser(
176 $this->note_type
177 );
178 }
180 }
181
182 public function view(): void
183 {
184 $ilUser = $this->user;
187 $ilAccess = $this->access;
188 $ilToolbar = $this->toolbar;
189
190 $rel_objs = $this->getRelatedObjects();
191 $this->setToolbar();
192
193 if ($this->note_type === Note::PRIVATE) {
194 $rel_objs = array_merge(
195 [0],
196 $rel_objs
197 );
198 }
199
200 // #9410
201 if (count($rel_objs) === 0 && $this->note_type === Note::PUBLIC) {
202 $lng->loadLanguageModule("notes");
203 $this->tpl->setOnScreenMessage('info', $lng->txt("msg_no_search_result"));
204 return;
205 }
206 $notes_gui = $this->getGui();
207
208 if ($this->note_type === Note::PRIVATE) {
209 $notes_gui->enablePrivateNotes(true);
210 $notes_gui->enablePublicNotes(false);
211 } else {
212 $notes_gui->enablePrivateNotes(false);
213 $notes_gui->enablePublicNotes(true);
214 // #13707
215 if ($this->current_rel_obj > 0 &&
216 $ilSetting->get("comments_del_tutor", '1')) {
217 foreach (\ilObject::_getAllReferences($this->current_rel_obj) as $ref_id) {
218 if ($ilAccess->checkAccess("write", "", $ref_id)) {
219 $notes_gui->enablePublicNotesDeletion(true);
220 break;
221 }
222 }
223 }
224 }
225 $notes_gui->enableTargets(true);
226
227 $next_class = $this->ctrl->getNextClass($this);
228
229 if (in_array($next_class, ["ilnotegui", "ilcommentgui"])) {
230 $html = $this->ctrl->forwardCommand($notes_gui);
231 } elseif ($this->note_type === Note::PRIVATE) {
232 $html = $notes_gui->getNotesHTML();
233 } else {
234 $html = $notes_gui->getListHTML();
235 }
236
237 $filter_html = $this->getFilter()->render();
238
239 $this->tpl->setContent($filter_html . $html);
240 }
241
242 protected function getGui(): ilNoteGUI
243 {
244 $rel_objs = $this->getRelatedObjects();
245 if ($this->current_rel_obj === null) {
246 $rep_objs = $rel_objs;
247 $type = "";
248 $include_subs = true;
249 $obj_id = 0;
250 } elseif ($this->current_rel_obj > 0) {
251 $rep_objs = $this->current_rel_obj;
252 $type = \ilObject::_lookupType($this->current_rel_obj);
253 $include_subs = true;
254 $obj_id = 0;
255 } else {
256 $rep_objs = 0;
257 $type = "pd";
258 $include_subs = false;
259 $obj_id = $this->user->getId();
260 }
261 if ($this->note_type === Note::PRIVATE) {
262 $gui = new ilNoteGUI(
263 $rep_objs,
264 $obj_id,
265 $type,
266 $include_subs,
267 0,
268 false,
269 $this->search_text
270 );
271 } else {
272 $gui = $this->gui->getCommentsGUI(
273 $rep_objs,
274 $obj_id,
275 $type,
276 0,
277 $include_subs,
278 false,
279 $this->search_text
280 );
281 }
282 return $gui;
283 }
284
285 public function changeRelatedObject(): void
286 {
287 $ilUser = $this->user;
288
289 $ilUser->writePref(
290 "pd_notes_rel_obj" . $this->note_type,
291 (string) $this->request->getRelatedObjId()
292 );
293 $this->ctrl->redirect($this);
294 }
295
296 public function showPrivateNotes(): void
297 {
298 $ilUser = $this->user;
299 $ilCtrl = $this->ctrl;
300
301 $ilCtrl->redirectByClass(ilNoteGUI::class, "getNotesHTML");
302 }
303
304 public function showPublicComments(): void
305 {
306 $ilUser = $this->user;
307 $ilCtrl = $this->ctrl;
309
310 if ($ilSetting->get("disable_comments")) {
311 $ilCtrl->redirect($this, "showPrivateNotes");
312 }
313
314 $ilCtrl->redirectByClass(ilCommentGUI::class, "getListHTML");
315 }
316
317 protected function setSortation(): void
318 {
319 $this->notes_manager->setSortAscending($this->gui->standardRequest()->getSortation() === "asc");
320 $this->view();
321 }
322
323 protected function getFilter(): FilterAdapterGUI
324 {
327 if (is_null($this->filter)) {
328 $options = [];
329
330 if ($this->note_type === Note::PRIVATE) {
331 $options[-1] = $this->lng->txt("note_without_object");
332 }
333
334 foreach ($this->getRelatedObjects() as $k) {
335 $options[$k] = ilObject::_lookupTitle($k);
336 }
337 $this->filter = $gui->filter(
338 "notes_filter_" . $this->note_type,
339 self::class,
340 "view",
341 false,
342 false
343 )
344 ->text("text", $lng->txt("notes_text"))
345 ->select("object", $lng->txt("notes_origin"), $options);
346 }
347 return $this->filter;
348 }
349
350 protected function setToolbar(): void
351 {
353
354 // sortation
355 $c = $this->lng->txt("create_date") . ", ";
356 $options = [
357 'desc' => $c . $this->lng->txt("sorting_desc"),
358 'asc' => $c . $this->lng->txt("sorting_asc")
359 ];
360 $select_option = ($this->notes_manager->getSortAscending())
361 ? 'asc'
362 : 'desc';
363 $s = $this->ui->factory()->viewControl()->sortation($options, $select_option)
364 ->withTargetURL($ctrl->getLinkTarget($this, "setSortation"), 'sortation');
365 $this->toolbar->addComponent($s);
366
367 // print selection
368 $pv = $this->gui->print();
369 $modal_elements = $pv->getModalElements(
370 $ctrl->getLinkTarget($this, "printSelection")
371 );
372 $this->toolbar->addComponent($modal_elements->button);
373 $this->toolbar->addComponent($modal_elements->modal);
374
375 // export html
376 $b = $this->ui->factory()->button()->standard(
377 $this->lng->txt("notes_html_export"),
378 $ctrl->getLinkTargetByClass("ilNoteGUI", "exportNotesHTML")
379 );
380 $this->toolbar->addComponent($b);
381 }
382
386 public function printSelection(): void
387 {
388 $pv = $this->gui->print();
389 $pv->sendForm();
390 }
391}
Class ilCtrl provides processing control methods.
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
Help GUI class.
language handling
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
@ilCtrl_Calls ilNoteGUI: ilCommentGUI
User class.
writePref(string $keyword, string $value)
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
Private Notes on PD.
StandardGUIRequest $request
ilAccessHandler $access
ILIAS DI UIServices $ui
ILIAS Notes InternalGUIService $gui
ilToolbarGUI $toolbar
FilterAdapterGUI $filter
NotesManager $notes_manager
ilGlobalTemplateInterface $tpl
ILIAS Setting Class.
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...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$c
Definition: deliver.php:25
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$context
Definition: webdav.php:31