ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
46 protected $fav_manager;
47
53 public function __construct()
54 {
55 global $DIC;
56
57 $this->help = $DIC["ilHelp"];
58 $this->user = $DIC->user();
59 $tpl = $DIC["tpl"];
60 $lng = $DIC->language();
61 $ilCtrl = $DIC->ctrl();
62 $ilHelp = $DIC["ilHelp"];
63
64 $ilHelp->setScreenIdComponent("news");
65
66 // initiate variables
67 $this->tpl = $tpl;
68 $this->lng = $lng;
69 $this->ctrl = $ilCtrl;
70
71 $lng->loadLanguageModule("news");
72
73 $this->ctrl->saveParameter($this, "news_ref_id");
74 $this->fav_manager = new ilFavouritesManager();
75 }
76
80 public function executeCommand()
81 {
82 $next_class = $this->ctrl->getNextClass();
83
84 switch ($next_class) {
85
86 default:
87 $cmd = $this->ctrl->getCmd("view");
88 $this->displayHeader();
89 $this->$cmd();
90 break;
91 }
92 $this->tpl->printToStdout();
93 return true;
94 }
95
99 public function displayHeader()
100 {
101 $this->tpl->setTitle($this->lng->txt("news"));
102
103 // display infopanel if something happened
105 }
106
107 /*
108 * display notes
109 */
110 public function view()
111 {
116
117 $ref_ids = array();
118 $obj_ids = array();
119 $pd_items = $this->fav_manager->getFavouritesOfUser($ilUser->getId());
120 foreach ($pd_items as $item) {
121 $ref_ids[] = $item["ref_id"];
122 $obj_ids[] = $item["obj_id"];
123 }
124
125 $sel_ref_id = ($_GET["news_ref_id"] > 0)
126 ? $_GET["news_ref_id"]
127 : $ilUser->getPref("news_sel_ref_id");
128
129 include_once("./Services/News/classes/class.ilNewsItem.php");
130 $per = ($_SESSION["news_pd_news_per"] != "")
131 ? $_SESSION["news_pd_news_per"]
133 $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
134
135 // related objects (contexts) of news
136 $contexts[0] = $lng->txt("news_all_items");
137
138 $conts = array();
139 $sel_has_news = false;
140 foreach ($ref_ids as $ref_id) {
141 $obj_id = ilObject::_lookupObjId($ref_id);
142 $title = ilObject::_lookupTitle($obj_id);
143
144 $conts[$ref_id] = $title;
145 if ($sel_ref_id == $ref_id) {
146 $sel_has_news = true;
147 }
148 }
149
150 $cnt = array();
151 $nitem = new ilNewsItem();
152 $news_items = $nitem->_getNewsItemsOfUser(
153 $ilUser->getId(),
154 false,
155 true,
156 $per,
157 $cnt
158 );
159
160 // reset selected news ref id, if no news are given for id
161 if (!$sel_has_news) {
162 $sel_ref_id = "";
163 }
164 asort($conts);
165 foreach ($conts as $ref_id => $title) {
166 $contexts[$ref_id] = $title . " (" . (int) $cnt[$ref_id] . ")";
167 }
168
169
170 if ($sel_ref_id > 0) {
171 $obj_id = ilObject::_lookupObjId($sel_ref_id);
172 $obj_type = ilObject::_lookupType($obj_id);
173 $nitem->setContextObjId($obj_id);
174 $nitem->setContextObjType($obj_type);
175 $news_items = $nitem->getNewsForRefId(
176 $sel_ref_id,
177 false,
178 false,
179 $per,
180 true
181 );
182 }
183
184 include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
185 $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id);
186 $pd_news_table->setData($news_items);
187 $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items"));
188
189 $tpl->setContent($pd_news_table->getHTML());
190 }
191
195 public function applyFilter()
196 {
198
199 $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
200 $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
201 if ($_POST["news_per"] > 0) {
202 $_SESSION["news_pd_news_per"] = $_POST["news_per"];
203 }
204 $this->ctrl->redirect($this, "view");
205 }
206
210 public function resetFilter()
211 {
213 $this->ctrl->setParameter($this, "news_ref_id", 0);
214 $ilUser->writePref("news_sel_ref_id", 0);
215 $_SESSION["news_pd_news_per"] = "";
216 $this->ctrl->redirect($this, "view");
217 }
218}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Manages favourites, currently the interface for other components, needs discussion.
static filterObjIdsPerNews($a_obj_ids, $a_time_period=0, $a_starting_date="", $a_ending_date='', $ignore_period=false)
Checks whether news are available for.
static _lookupUserPDPeriod($a_user_id)
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
applyFilter()
change related object
executeCommand()
execute command
resetFilter()
reset filter
__construct()
Constructor.
displayHeader()
display header and locator
Personal desktop news table.
static infoPanel($a_keep=true)
help()
Definition: help.php:2
global $ilCtrl
Definition: ilias.php:18
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46