ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDNewsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
16 {
17 
23  function ilPDNewsGUI()
24  {
25  global $tpl, $lng, $ilCtrl, $ilHelp;
26 
27  $ilHelp->setScreenIdComponent("news");
28 
29  // initiate variables
30  $this->tpl =& $tpl;
31  $this->lng =& $lng;
32  $this->ctrl =& $ilCtrl;
33 
34  $lng->loadLanguageModule("news");
35 
36  $this->ctrl->saveParameter($this, "news_ref_id");
37  }
38 
42  function &executeCommand()
43  {
44  $next_class = $this->ctrl->getNextClass();
45 
46  switch($next_class)
47  {
48 
49  default:
50  $cmd = $this->ctrl->getCmd("view");
51  $this->displayHeader();
52  $this->$cmd();
53  break;
54  }
55  $this->tpl->show(true);
56  return true;
57  }
58 
62  function displayHeader()
63  {
64  $this->tpl->setTitle($this->lng->txt("news"));
65 
66  // display infopanel if something happened
68  }
69 
70  /*
71  * display notes
72  */
73  function view()
74  {
75  global $ilUser, $lng, $tpl, $ilCtrl;
76 
77  $ref_ids = array();
78  $obj_ids = array();
79  $pd_items = $ilUser->getDesktopItems();
80  foreach($pd_items as $item)
81  {
82  $ref_ids[] = $item["ref_id"];
83  $obj_ids[] = $item["obj_id"];
84  }
85 
86  $sel_ref_id = ($_GET["news_ref_id"] > 0)
87  ? $_GET["news_ref_id"]
88  : $ilUser->getPref("news_sel_ref_id");
89 
90  include_once("./Services/News/classes/class.ilNewsItem.php");
91  $per = ($_SESSION["news_pd_news_per"] != "")
92  ? $_SESSION["news_pd_news_per"]
93  : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
94  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
95 
96  // related objects (contexts) of news
97  $contexts[0] = $lng->txt("news_all_items");
98 
99  $conts = array();
100  $sel_has_news = false;
101  foreach ($ref_ids as $ref_id)
102  {
103  $obj_id = ilObject::_lookupObjId($ref_id);
104  $title = ilObject::_lookupTitle($obj_id);
105 
106  $conts[$ref_id] = $title;
107  if ($sel_ref_id == $ref_id)
108  {
109  $sel_has_news = true;
110  }
111  }
112 
113  $cnt = array();
114  $nitem = new ilNewsItem();
115  $news_items = $nitem->_getNewsItemsOfUser($ilUser->getId(), false,
116  true, $per, $cnt);
117 
118  // reset selected news ref id, if no news are given for id
119  if (!$sel_has_news)
120  {
121  $sel_ref_id = "";
122  }
123  asort($conts);
124  foreach($conts as $ref_id => $title)
125  {
126  $contexts[$ref_id] = $title." (".(int) $cnt[$ref_id].")";
127  }
128 
129 
130  if ($sel_ref_id > 0)
131  {
132  $obj_id = ilObject::_lookupObjId($sel_ref_id);
133  $obj_type = ilObject::_lookupType($obj_id);
134  $nitem->setContextObjId($obj_id);
135  $nitem->setContextObjType($obj_type);
136  $news_items = $nitem->getNewsForRefId($sel_ref_id, false,
137  false, $per, true);
138  }
139 
140  include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
141  $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id);
142  $pd_news_table->setData($news_items);
143  $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items"));
144 
145  $tpl->setContent($pd_news_table->getHTML());
146  }
147 
151  function applyFilter()
152  {
153  global $ilUser;
154 
155  $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
156  $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
157  if ($_POST["news_per"] > 0)
158  {
159  $_SESSION["news_pd_news_per"] = $_POST["news_per"];
160  }
161  $this->ctrl->redirect($this, "view");
162  }
163 
167  function resetFilter()
168  {
169  global $ilUser;
170  $this->ctrl->setParameter($this, "news_ref_id", 0);
171  $ilUser->writePref("news_sel_ref_id", 0);
172  $_SESSION["news_pd_news_per"] = "";
173  $this->ctrl->redirect($this, "view");
174  }
175 
176 }
177 ?>