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