ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
19 
25  var $ilias;
26  var $tpl;
27  var $lng;
28 
29  const PUBLIC_COMMENTS = "publiccomments";
30  const PRIVATE_NOTES = "privatenotes";
31 
37  function ilPDNotesGUI()
38  {
39  global $ilias, $tpl, $lng, $ilCtrl, $ilUser, $ilTabs, $ilHelp;
40 
41  $ilHelp->setScreenIdComponent("note");
42 
43  // initiate variables
44  $this->ilias =& $ilias;
45  $this->tpl =& $tpl;
46  $this->lng =& $lng;
47  $this->ctrl =& $ilCtrl;
48 
49  // link from ilPDNotesBlockGUI
50  if($_GET["rel_obj"])
51  {
52  $mode = ($_GET["note_type"] == IL_NOTE_PRIVATE) ? self::PRIVATE_NOTES : self::PUBLIC_COMMENTS;
53  $ilUser->writePref("pd_notes_mode", $mode);
54  $ilUser->writePref("pd_notes_rel_obj".$mode, $_GET["rel_obj"]);
55  }
56  // edit link
57  else if($_REQUEST["note_id"])
58  {
59  $note = new ilNote($_REQUEST["note_id"]);
60  $mode = ($note->getType() == IL_NOTE_PRIVATE) ? self::PRIVATE_NOTES : self::PUBLIC_COMMENTS;
61  $obj = $note->getObject();
62  $ilUser->writePref("pd_notes_mode", $mode);
63  $ilUser->writePref("pd_notes_rel_obj".$mode, $obj["rep_obj_id"]);
64  }
65  }
66 
70  function &executeCommand()
71  {
72  $next_class = $this->ctrl->getNextClass();
73 
74  switch($next_class)
75  {
76  case "ilnotegui":
77  // scorm2004-start
78  $this->setTabs();
79  // scorm2004-end
80  $this->displayHeader();
81  $this->view(); // forwardCommand is invoked in view() method
82  break;
83 
84  default:
85  // scorm2004-start
86  $this->setTabs();
87  // scorm2004-end
88  $cmd = $this->ctrl->getCmd("view");
89  $this->displayHeader();
90  $this->$cmd();
91  break;
92  }
93  $this->tpl->show(true);
94  return true;
95  }
96 
100  function displayHeader()
101  {
102  $this->tpl->setTitle($this->lng->txt("notes"));
103 
104  // catch feedback message
105  // display infopanel if something happened
107 
108  }
109 
110  /*
111  * display notes
112  */
113  function view()
114  {
115  global $ilUser, $lng, $ilSetting, $ilAccess, $ilToolbar;
116 
117  //$this->tpl->addBlockFile("ADM_CONTENT", "objects", "tpl.table.html")
118  include_once("Services/Notes/classes/class.ilNoteGUI.php");
119 
120  // output related item selection (if more than one)
121  include_once("Services/Notes/classes/class.ilNote.php");
122  $rel_objs = ilNote::_getRelatedObjectsOfUser($this->getMode());
123 //var_dump($rel_objs);
124  // prepend personal dektop, if first object
125 // if ($rel_objs[0]["rep_obj_id"] > 0 && $this->getMode() == ilPDNotesGUI::PRIVATE_NOTES)
126  if ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES)
127  {
128 
129  $rel_objs = array_merge(array(0), $rel_objs);
130  }
131 
132  // #9410
133  if(!$rel_objs && $this->getMode() == ilPDNotesGUI::PUBLIC_COMMENTS)
134  {
135  $lng->loadLanguageModule("notes");
136  ilUtil::sendInfo($lng->txt("msg_no_search_result"));
137  return;
138  }
139 
140  $first = true;
141  foreach ($rel_objs as $r)
142  {
143  if ($first) // take first one as default
144  {
145  $this->current_rel_obj = $r["rep_obj_id"];
146  $current_ref_ids = $r["ref_ids"];
147  }
148  if ($r["rep_obj_id"] == $ilUser->getPref("pd_notes_rel_obj".$this->getMode()))
149  {
150  $this->current_rel_obj = $r["rep_obj_id"];
151  $current_ref_ids = $r["ref_ids"];
152  }
153  $first = false;
154  }
155  if ($this->current_rel_obj > 0)
156  {
157  $notes_gui = new ilNoteGUI($this->current_rel_obj, 0,
158  ilObject::_lookupType($this->current_rel_obj),true);
159  }
160  else
161  {
162  $notes_gui = new ilNoteGUI(0, $ilUser->getId(), "pd");
163  }
164 
165  if ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES)
166  {
167  $notes_gui->enablePrivateNotes(true);
168  $notes_gui->enablePublicNotes(false);
169  }
170  else
171  {
172  $notes_gui->enablePrivateNotes(false);
173  $notes_gui->enablePublicNotes(true);
174 
175  // #13707
176  if ($this->current_rel_obj > 0 &&
177  sizeof($current_ref_ids) &&
178  $ilSetting->get("comments_del_tutor", 1))
179  {
180  foreach($current_ref_ids as $ref_id)
181  {
182  if($ilAccess->checkAccess("write", "", $ref_id))
183  {
184  $notes_gui->enablePublicNotesDeletion(true);
185  break;
186  }
187  }
188  }
189  }
190  $notes_gui->enableHiding(false);
191  $notes_gui->enableTargets(true);
192  $notes_gui->enableMultiSelection(true);
193  $notes_gui->enableAnchorJump(false);
194 
195  $next_class = $this->ctrl->getNextClass($this);
196 
197  if ($next_class == "ilnotegui")
198  {
199  $html = $this->ctrl->forwardCommand($notes_gui);
200  }
201  else
202  {
203  if ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES)
204  {
205  $html = $notes_gui->getOnlyNotesHTML();
206  }
207  else
208  {
209  $html = $notes_gui->getOnlyCommentsHTML();
210  }
211  }
212 
213  if (count($rel_objs) > 1 ||
214  ($rel_objs[0]["rep_obj_id"] > 0))
215  {
216  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
217 
218  foreach($rel_objs as $obj)
219  {
220  if ($obj["rep_obj_id"] > 0)
221  {
222  $type = ilObject::_lookupType($obj["rep_obj_id"]);
223  $type_str = (in_array($type, array("lm", "htlm", "sahs", "dbk")))
224  ? $lng->txt("learning_resource")
225  : $lng->txt("obj_".$type);
226  $caption = $type_str.": ".ilObject::_lookupTitle($obj["rep_obj_id"]);
227  }
228  else
229  {
230  $caption = $lng->txt("personal_desktop");
231  }
232 
233  $options[$obj["rep_obj_id"]] = $caption;
234  }
235 
236  include_once "Services/Form/classes/class.ilSelectInputGUI.php";
237  $rel = new ilSelectInputGUI($lng->txt("related_to"), "rel_obj");
238  $rel->setOptions($options);
239  $rel->setValue($this->current_rel_obj);
240  $ilToolbar->addInputItem($rel);
241 
242  $ilToolbar->addFormButton($lng->txt("change"), "changeRelatedObject");
243  }
244 
245  $this->tpl->setContent($html);
246  }
247 
252  {
253  global $ilUser;
254 
255  $ilUser->writePref("pd_notes_rel_obj".$this->getMode(), $_POST["rel_obj"]);
256  $this->ctrl->redirect($this);
257  }
258 
259  // scorm2004-start
263  function setTabs()
264  {
265  global $ilTabs, $ilSetting, $ilCtrl;
266 
267  $ilTabs->addTarget("private_notes",
268  $ilCtrl->getLinkTarget($this, "showPrivateNotes"), "", "", "",
269  ($this->getMode() == ilPDNotesGUI::PRIVATE_NOTES));
270  if(!$ilSetting->get("disable_comments"))
271  {
272  $ilTabs->addTarget("notes_public_comments",
273  $ilCtrl->getLinkTarget($this, "showPublicComments"), "", "", "",
274  ($this->getMode() == ilPDNotesGUI::PUBLIC_COMMENTS));
275  }
276  }
277 
281  function showPrivateNotes()
282  {
283  global $ilUser, $ilCtrl;
284 
285  $ilUser->writePref("pd_notes_mode", ilPDNotesGUI::PRIVATE_NOTES);
286  $ilCtrl->redirect($this, "");
287  }
288 
293  {
294  global $ilUser, $ilCtrl, $ilSetting;
295 
296  if($ilSetting->get("disable_comments"))
297  {
298  $ilCtrl->redirect($this, "showPrivateNotes");
299  }
300 
301  $ilUser->writePref("pd_notes_mode", ilPDNotesGUI::PUBLIC_COMMENTS);
302  $ilCtrl->redirect($this, "");
303  }
304 
308  function getMode()
309  {
310  global $ilUser, $ilSetting;
311 
312  if ($ilUser->getPref("pd_notes_mode") == ilPDNotesGUI::PUBLIC_COMMENTS &&
313  !$ilSetting->get("disable_comments"))
314  {
316  }
317  else
318  {
320  }
321  }
322 }
323 ?>