ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
20  protected $tpl;
21 
25  protected $lng;
26 
30  protected $ctrl;
31 
35  protected $help;
36 
40  protected $user;
41 
42 
48  public function __construct()
49  {
50  global $DIC;
51 
52  $this->help = $DIC["ilHelp"];
53  $this->user = $DIC->user();
54  $tpl = $DIC["tpl"];
55  $lng = $DIC->language();
56  $ilCtrl = $DIC->ctrl();
57  $ilHelp = $DIC["ilHelp"];
58 
59  $ilHelp->setScreenIdComponent("news");
60 
61  // initiate variables
62  $this->tpl = $tpl;
63  $this->lng = $lng;
64  $this->ctrl = $ilCtrl;
65 
66  $lng->loadLanguageModule("news");
67 
68  $this->ctrl->saveParameter($this, "news_ref_id");
69  }
70 
74  public function executeCommand()
75  {
76  $next_class = $this->ctrl->getNextClass();
77 
78  switch ($next_class) {
79 
80  default:
81  $cmd = $this->ctrl->getCmd("view");
82  $this->displayHeader();
83  $this->$cmd();
84  break;
85  }
86  $this->tpl->show(true);
87  return true;
88  }
89 
93  public function displayHeader()
94  {
95  $this->tpl->setTitle($this->lng->txt("news"));
96 
97  // display infopanel if something happened
99  }
100 
101  /*
102  * display notes
103  */
104  public function view()
105  {
107  $lng = $this->lng;
108  $tpl = $this->tpl;
110 
111  $ref_ids = array();
112  $obj_ids = array();
113  $pd_items = $ilUser->getDesktopItems();
114  foreach ($pd_items as $item) {
115  $ref_ids[] = $item["ref_id"];
116  $obj_ids[] = $item["obj_id"];
117  }
118 
119  $sel_ref_id = ($_GET["news_ref_id"] > 0)
120  ? $_GET["news_ref_id"]
121  : $ilUser->getPref("news_sel_ref_id");
122 
123  include_once("./Services/News/classes/class.ilNewsItem.php");
124  $per = ($_SESSION["news_pd_news_per"] != "")
125  ? $_SESSION["news_pd_news_per"]
127  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
128 
129  // related objects (contexts) of news
130  $contexts[0] = $lng->txt("news_all_items");
131 
132  $conts = array();
133  $sel_has_news = false;
134  foreach ($ref_ids as $ref_id) {
135  $obj_id = ilObject::_lookupObjId($ref_id);
136  $title = ilObject::_lookupTitle($obj_id);
137 
138  $conts[$ref_id] = $title;
139  if ($sel_ref_id == $ref_id) {
140  $sel_has_news = true;
141  }
142  }
143 
144  $cnt = array();
145  $nitem = new ilNewsItem();
146  $news_items = $nitem->_getNewsItemsOfUser(
147  $ilUser->getId(),
148  false,
149  true,
150  $per,
151  $cnt
152  );
153 
154  // reset selected news ref id, if no news are given for id
155  if (!$sel_has_news) {
156  $sel_ref_id = "";
157  }
158  asort($conts);
159  foreach ($conts as $ref_id => $title) {
160  $contexts[$ref_id] = $title . " (" . (int) $cnt[$ref_id] . ")";
161  }
162 
163 
164  if ($sel_ref_id > 0) {
165  $obj_id = ilObject::_lookupObjId($sel_ref_id);
166  $obj_type = ilObject::_lookupType($obj_id);
167  $nitem->setContextObjId($obj_id);
168  $nitem->setContextObjType($obj_type);
169  $news_items = $nitem->getNewsForRefId(
170  $sel_ref_id,
171  false,
172  false,
173  $per,
174  true
175  );
176  }
177 
178  include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
179  $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id);
180  $pd_news_table->setData($news_items);
181  $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items"));
182 
183  $tpl->setContent($pd_news_table->getHTML());
184  }
185 
189  public function applyFilter()
190  {
192 
193  $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
194  $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
195  if ($_POST["news_per"] > 0) {
196  $_SESSION["news_pd_news_per"] = $_POST["news_per"];
197  }
198  $this->ctrl->redirect($this, "view");
199  }
200 
204  public function resetFilter()
205  {
207  $this->ctrl->setParameter($this, "news_ref_id", 0);
208  $ilUser->writePref("news_sel_ref_id", 0);
209  $_SESSION["news_pd_news_per"] = "";
210  $this->ctrl->redirect($this, "view");
211  }
212 }
executeCommand()
execute command
displayHeader()
display header and locator
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static _lookupUserPDPeriod($a_user_id)
static _lookupTitle($a_id)
lookup object title
user()
Definition: user.php:4
Personal desktop news table.
global $ilCtrl
Definition: ilias.php:18
static _lookupObjId($a_id)
static infoPanel($a_keep=true)
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
__construct()
Constructor.
static filterObjIdsPerNews($a_obj_ids, $a_time_period=0, $a_starting_date="", $a_ending_date='', $ignore_period=false)
Checks whether news are available for.
News on PD.
applyFilter()
change related object
resetFilter()
reset filter
$_POST["username"]