ILIAS  Release_4_4_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->setTitleIcon(ilUtil::getImagePath("icon_pd_b.png"),
65  // $this->lng->txt("personal_desktop"));
66 // $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.png"),
67 // "");
68  $this->tpl->setTitle($this->lng->txt("news"));
69 
70  // display infopanel if something happened
72  }
73 
74  /*
75  * display notes
76  */
77  function view()
78  {
79  global $ilUser, $lng, $tpl, $ilCtrl;
80 
81  $ref_ids = array();
82  $obj_ids = array();
83  $pd_items = $ilUser->getDesktopItems();
84  foreach($pd_items as $item)
85  {
86  $ref_ids[] = $item["ref_id"];
87  $obj_ids[] = $item["obj_id"];
88  }
89 
90  $sel_ref_id = ($_GET["news_ref_id"] > 0)
91  ? $_GET["news_ref_id"]
92  : $ilUser->getPref("news_sel_ref_id");
93 
94  include_once("./Services/News/classes/class.ilNewsItem.php");
95  $per = ($_SESSION["news_pd_news_per"] != "")
96  ? $_SESSION["news_pd_news_per"]
97  : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
98  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
99 
100  // related objects (contexts) of news
101  $contexts[0] = $lng->txt("news_all_items");
102 
103  $conts = array();
104  $sel_has_news = false;
105  foreach ($ref_ids as $ref_id)
106  {
107  $obj_id = ilObject::_lookupObjId($ref_id);
108  $title = ilObject::_lookupTitle($obj_id);
109 
110  $conts[$ref_id] = $title;
111  if ($sel_ref_id == $ref_id)
112  {
113  $sel_has_news = true;
114  }
115  }
116 
117  $cnt = array();
118  $nitem = new ilNewsItem();
119  $news_items = $nitem->_getNewsItemsOfUser($ilUser->getId(), false,
120  true, $per, $cnt);
121 
122  // reset selected news ref id, if no news are given for id
123  if (!$sel_has_news)
124  {
125  $sel_ref_id = "";
126  }
127  asort($conts);
128  foreach($conts as $ref_id => $title)
129  {
130  $contexts[$ref_id] = $title." (".(int) $cnt[$ref_id].")";
131  }
132 
133 
134  if ($sel_ref_id > 0)
135  {
136  $obj_id = ilObject::_lookupObjId($sel_ref_id);
137  $obj_type = ilObject::_lookupType($obj_id);
138  $nitem->setContextObjId($obj_id);
139  $nitem->setContextObjType($obj_type);
140  $news_items = $nitem->getNewsForRefId($sel_ref_id, false,
141  false, $per, true);
142  }
143 
144  include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
145  $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id);
146  $pd_news_table->setData($news_items);
147  $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items"));
148 
149  $tpl->setContent($pd_news_table->getHTML());
150  }
151 
155  function applyFilter()
156  {
157  global $ilUser;
158 
159  $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
160  $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
161  if ($_POST["news_per"] > 0)
162  {
163  $_SESSION["news_pd_news_per"] = $_POST["news_per"];
164  }
165  $this->ctrl->redirect($this, "view");
166  }
167 
171  function resetFilter()
172  {
173  global $ilUser;
174  $this->ctrl->setParameter($this, "news_ref_id", 0);
175  $ilUser->writePref("news_sel_ref_id", 0);
176  $_SESSION["news_pd_news_per"] = "";
177  $this->ctrl->redirect($this, "view");
178  }
179 
180 }
181 ?>