ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPDNotesGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
6 include_once("Services/Notes/classes/class.ilNote.php");
7 
18 {
22  protected $ctrl;
23 
27  protected $user;
28 
32  protected $tabs;
33 
37  protected $help;
38 
42  protected $settings;
43 
47  protected $access;
48 
52  protected $toolbar;
53 
54  public $tpl;
55  public $lng;
56 
57  const PUBLIC_COMMENTS = "publiccomments";
58  const PRIVATE_NOTES = "privatenotes";
59 
65  public function __construct()
66  {
67  global $DIC;
68 
69  $this->user = $DIC->user();
70  $this->tabs = $DIC->tabs();
71  $this->help = $DIC["ilHelp"];
72  $this->settings = $DIC->settings();
73  $this->access = $DIC->access();
74  $this->toolbar = $DIC->toolbar();
75  $tpl = $DIC["tpl"];
76  $lng = $DIC->language();
77  $ilCtrl = $DIC->ctrl();
78  $ilUser = $DIC->user();
79  $ilTabs = $DIC->tabs();
80  $ilHelp = $DIC["ilHelp"];
81 
82  $ilHelp->setScreenIdComponent("note");
83 
84  $lng->loadLanguageModule("notes");
85 
86  // initiate variables
87  $this->tpl = $tpl;
88  $this->lng = $lng;
89  $this->ctrl = $ilCtrl;
90 
91  // link from ilPDNotesBlockGUI
92  if ($_GET["rel_obj"]) {
93  $mode = ($_GET["note_type"] == IL_NOTE_PRIVATE) ? self::PRIVATE_NOTES : self::PUBLIC_COMMENTS;
94  $ilUser->writePref("pd_notes_mode", $mode);
95  $ilUser->writePref("pd_notes_rel_obj" . $mode, $_GET["rel_obj"]);
96  }
97  // edit link
98  elseif ($_REQUEST["note_id"]) {
99  $note = new ilNote($_REQUEST["note_id"]);
100  $mode = ($note->getType() == IL_NOTE_PRIVATE) ? self::PRIVATE_NOTES : self::PUBLIC_COMMENTS;
101  $obj = $note->getObject();
102  $ilUser->writePref("pd_notes_mode", $mode);
103  $ilUser->writePref("pd_notes_rel_obj" . $mode, $obj["rep_obj_id"]);
104  }
105  }
106 
110  public function executeCommand()
111  {
112  $next_class = $this->ctrl->getNextClass();
113  switch ($next_class) {
114  case "ilnotegui":
115  // scorm2004-start
116  $this->setTabs();
117  // scorm2004-end
118  $this->displayHeader();
119  $this->view(); // forwardCommand is invoked in view() method
120  break;
121 
122  default:
123  // scorm2004-start
124  $this->setTabs();
125  // scorm2004-end
126  $cmd = $this->ctrl->getCmd("view");
127  $this->displayHeader();
128  $this->$cmd();
129  break;
130  }
131  $this->tpl->printToStdout(true);
132  return true;
133  }
134 
138  public function displayHeader()
139  {
141 
142  $t = $this->lng->txt("notes");
143  if (!$ilSetting->get("disable_notes") && !$ilSetting->get("disable_comments")) {
144  $t = $this->lng->txt("notes_and_comments");
145  }
146  if ($ilSetting->get("disable_notes")) {
147  $t = $this->lng->txt("notes_comments");
148  }
149 
150  if ($this->getMode() == self::PRIVATE_NOTES) {
151  $t = $this->lng->txt("private_notes");
152  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_nots.svg"));
153  } else {
154  $t = $this->lng->txt("notes_public_comments");
155  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_coms.svg"));
156  }
157 
158  $this->tpl->setTitle($t);
159 
160  // catch feedback message
161  // display infopanel if something happened
163  }
164 
165  /*
166  * display notes
167  */
168  public function view()
169  {
171  $lng = $this->lng;
173  $ilAccess = $this->access;
174  $ilToolbar = $this->toolbar;
175 
176  //$this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.table.html")
177  include_once("Services/Notes/classes/class.ilNoteGUI.php");
178 
179  // output related item selection (if more than one)
180  include_once("Services/Notes/classes/class.ilNote.php");
181  $rel_objs = ilNote::_getRelatedObjectsOfUser($this->getMode());
182  //var_dump($rel_objs);
183  // prepend personal dektop, if first object
184  // if ($rel_objs[0]["rep_obj_id"] > 0 && $this->getMode() == ilPDNotesGUI::PRIVATE_NOTES)
185  if ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES) {
186  $rel_objs = array_merge(array(0), $rel_objs);
187  }
188 
189  // #9410
190  if (!$rel_objs && $this->getMode() == ilPDNotesGUI::PUBLIC_COMMENTS) {
191  $lng->loadLanguageModule("notes");
192  ilUtil::sendInfo($lng->txt("msg_no_search_result"));
193  return;
194  }
195 
196  $first = true;
197  $current_ref_ids = [];
198  foreach ($rel_objs as $r) {
199  if ($first) { // take first one as default
200  $this->current_rel_obj = $r["rep_obj_id"];
201  $current_ref_ids = $r["ref_ids"];
202  }
203  if ($r["rep_obj_id"] == $ilUser->getPref("pd_notes_rel_obj" . $this->getMode())) {
204  $this->current_rel_obj = $r["rep_obj_id"];
205  $current_ref_ids = $r["ref_ids"];
206  }
207  $first = false;
208  }
209  if ($this->current_rel_obj > 0) {
210  $notes_gui = new ilNoteGUI(
211  $this->current_rel_obj,
212  0,
213  ilObject::_lookupType($this->current_rel_obj),
214  true
215  );
216  } else {
217  $notes_gui = new ilNoteGUI(0, $ilUser->getId(), "pd");
218  }
219 
220  if ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES) {
221  $notes_gui->enablePrivateNotes(true);
222  $notes_gui->enablePublicNotes(false);
223  } else {
224  $notes_gui->enablePrivateNotes(false);
225  $notes_gui->enablePublicNotes(true);
226  // #13707
227  if ($this->current_rel_obj > 0 &&
228  count($current_ref_ids) > 0 &&
229  $ilSetting->get("comments_del_tutor", 1)) {
230  foreach ($current_ref_ids as $ref_id) {
231  if ($ilAccess->checkAccess("write", "", $ref_id)) {
232  $notes_gui->enablePublicNotesDeletion(true);
233  break;
234  }
235  }
236  }
237  }
238  $notes_gui->enableHiding(false);
239  $notes_gui->enableTargets(true);
240  $notes_gui->enableMultiSelection(true);
241  $notes_gui->enableAnchorJump(false);
242 
243  $next_class = $this->ctrl->getNextClass($this);
244 
245  if ($next_class == "ilnotegui") {
246  $html = $this->ctrl->forwardCommand($notes_gui);
247  } else {
248  if ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES) {
249  $html = $notes_gui->getOnlyNotesHTML();
250  } else {
251  $html = $notes_gui->getOnlyCommentsHTML();
252  }
253  }
254 
255  if (count($rel_objs) > 1 ||
256  ($rel_objs[0]["rep_obj_id"] > 0)) {
257  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
258 
259  foreach ($rel_objs as $obj) {
260  if ($obj["rep_obj_id"] > 0) {
261  $type = ilObject::_lookupType($obj["rep_obj_id"]);
262  $type_str = (in_array($type, array("lm", "htlm", "sahs")))
263  ? $lng->txt("obj_lm")
264  : $lng->txt("obj_" . $type);
265  $caption = $type_str . ": " . ilObject::_lookupTitle($obj["rep_obj_id"]);
266  } else {
267  $caption = $lng->txt("note_without_object");
268  }
269 
270  $options[$obj["rep_obj_id"]] = $caption;
271  }
272 
273  include_once "Services/Form/classes/class.ilSelectInputGUI.php";
274  $rel = new ilSelectInputGUI($lng->txt("related_to"), "rel_obj");
275  $rel->setOptions($options);
276  $rel->setValue($this->current_rel_obj);
277  $ilToolbar->addStickyItem($rel);
278 
280  $btn->setCaption('change');
281  $btn->setCommand('changeRelatedObject');
282  $ilToolbar->addStickyItem($btn);
283  }
284 
285  $this->tpl->setContent($html);
286  }
287 
291  public function changeRelatedObject()
292  {
294 
295  $ilUser->writePref("pd_notes_rel_obj" . $this->getMode(), $_POST["rel_obj"]);
296  $this->ctrl->redirect($this);
297  }
298 
299  // scorm2004-start
303  public function setTabs()
304  {
305  $ilTabs = $this->tabs;
308 
309  /*
310  if(!$ilSetting->get("disable_notes"))
311  {
312  $ilTabs->addTarget("private_notes",
313  $ilCtrl->getLinkTarget($this, "showPrivateNotes"), "", "", "",
314  ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES));
315  }
316 
317  if(!$ilSetting->get("disable_comments"))
318  {
319  $ilTabs->addTarget("notes_public_comments",
320  $ilCtrl->getLinkTarget($this, "showPublicComments"), "", "", "",
321  ($this->getMode() == ilPDNotesGUI::PUBLIC_COMMENTS));
322  }*/
323  }
324 
328  public function showPrivateNotes()
329  {
332 
333  $ilUser->writePref("pd_notes_mode", ilPDNotesGUI::PRIVATE_NOTES);
334  $ilCtrl->redirect($this, "");
335  }
336 
340  public function showPublicComments()
341  {
345 
346  if ($ilSetting->get("disable_comments")) {
347  $ilCtrl->redirect($this, "showPrivateNotes");
348  }
349 
350  $ilUser->writePref("pd_notes_mode", ilPDNotesGUI::PUBLIC_COMMENTS);
351  $ilCtrl->redirect($this, "");
352  }
353 
357  public function getMode()
358  {
361 
362  if ($ilUser->getPref("pd_notes_mode") == ilPDNotesGUI::PUBLIC_COMMENTS &&
363  !$ilSetting->get("disable_comments")) {
365  } else {
367  }
368  }
369 }
settings()
Definition: settings.php:2
const IL_NOTE_PRIVATE
Definition: class.ilNote.php:5
executeCommand()
execute command
$type
$_GET["client_id"]
Private Notes on PD.
showPublicComments()
Show public comments.
static _lookupTitle($a_id)
lookup object title
changeRelatedObject()
change related object
user()
Definition: user.php:4
Note class.
Notes GUI class.
global $ilCtrl
Definition: ilias.php:18
help()
Definition: help.php:2
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
__construct()
Constructor.
setTabs()
Show subtabs.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static infoPanel($a_keep=true)
$ilUser
Definition: imgupload.php:18
static _getRelatedObjectsOfUser($a_mode)
get all related objects for user
static _lookupType($a_id, $a_reference=false)
lookup object type
displayHeader()
display header and locator
getMode()
Get current mode.
global $ilSetting
Definition: privfeed.php:17
$DIC
Definition: xapitoken.php:46
enablePrivateNotes($a_enable=true)
enable private notes
$_POST["username"]
showPrivateNotes()
Show private notes.