ILIAS  Release_4_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;
26 
27  // initiate variables
28  $this->tpl =& $tpl;
29  $this->lng =& $lng;
30  $this->ctrl =& $ilCtrl;
31 
32  $lng->loadLanguageModule("news");
33 
34  $this->ctrl->saveParameter($this, "news_ref_id");
35  }
36 
40  function &executeCommand()
41  {
42  $next_class = $this->ctrl->getNextClass();
43 
44  switch($next_class)
45  {
46 
47  default:
48  $cmd = $this->ctrl->getCmd("view");
49  $this->displayHeader();
50  $this->$cmd();
51  break;
52  }
53  $this->tpl->show(true);
54  return true;
55  }
56 
60  function displayHeader()
61  {
62  //$this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
63  // $this->lng->txt("personal_desktop"));
64  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
65  "");
66  $this->tpl->setTitle($this->lng->txt("personal_desktop"));
67 
68  // display infopanel if something happened
70  }
71 
72  /*
73  * display notes
74  */
75  function view()
76  {
77  global $ilUser, $lng, $tpl, $ilCtrl;
78 
79  $ref_ids = array();
80  $obj_ids = array();
81  $pd_items = $ilUser->getDesktopItems();
82  foreach($pd_items as $item)
83  {
84  $ref_ids[] = $item["ref_id"];
85  $obj_ids[] = $item["obj_id"];
86  }
87 
88  $sel_ref_id = ($_GET["news_ref_id"] > 0)
89  ? $_GET["news_ref_id"]
90  : $ilUser->getPref("news_sel_ref_id");
91 
92  include_once("./Services/News/classes/class.ilNewsItem.php");
93  $per = ($_SESSION["news_pd_news_per"] != "")
94  ? $_SESSION["news_pd_news_per"]
95  : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
96  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
97 
98  // related objects (contexts) of news
99  $contexts[0] = $lng->txt("news_all_items");
100 
101  $conts = array();
102  $sel_has_news = false;
103  foreach ($ref_ids as $ref_id)
104  {
105  $obj_id = ilObject::_lookupObjId($ref_id);
106  $title = ilObject::_lookupTitle($obj_id);
107 
108  $conts[$ref_id] = $title;
109  if ($sel_ref_id == $ref_id)
110  {
111  $sel_has_news = true;
112  }
113  }
114 
115  $cnt = array();
116  $nitem = new ilNewsItem();
117  $news_items = $nitem->_getNewsItemsOfUser($ilUser->getId(), false,
118  true, $per, $cnt);
119 
120  // reset selected news ref id, if no news are given for id
121  if (!$sel_has_news)
122  {
123  $sel_ref_id = "";
124  }
125  asort($conts);
126  foreach($conts as $ref_id => $title)
127  {
128  $contexts[$ref_id] = $title." (".(int) $cnt[$ref_id].")";
129  }
130 
131 
132  if ($sel_ref_id > 0)
133  {
134  $obj_id = ilObject::_lookupObjId($sel_ref_id);
135  $obj_type = ilObject::_lookupType($obj_id);
136  $nitem->setContextObjId($obj_id);
137  $nitem->setContextObjType($obj_type);
138  $news_items = $nitem->getNewsForRefId($sel_ref_id, false,
139  false, $per, true);
140  }
141 
142  include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
143  $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id);
144  $pd_news_table->setData($news_items);
145  $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items"));
146 
147  $tpl->setContent($pd_news_table->getHTML());
148  }
149 
153  function applyFilter()
154  {
155  global $ilUser;
156 
157  $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
158  $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
159  if ($_POST["news_per"] > 0)
160  {
161  $_SESSION["news_pd_news_per"] = $_POST["news_per"];
162  }
163  $this->ctrl->redirect($this, "view");
164  }
165 
169  function resetFilter()
170  {
171  global $ilUser;
172  $this->ctrl->setParameter($this, "news_ref_id", 0);
173  $ilUser->writePref("news_sel_ref_id", 0);
174  $_SESSION["news_pd_news_per"] = "";
175  $this->ctrl->redirect($this, "view");
176  }
177 
178 }
179 ?>