ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_nwss.svg"));
103
104 // display infopanel if something happened
106 }
107
108 /*
109 * display notes
110 */
111 public function view()
112 {
116 $ilCtrl = $this->ctrl;
117
118 $ref_ids = array();
119 $obj_ids = array();
120 $pd_items = $this->fav_manager->getFavouritesOfUser($ilUser->getId());
121 foreach ($pd_items as $item) {
122 $ref_ids[] = $item["ref_id"];
123 $obj_ids[] = $item["obj_id"];
124 }
125
126 $sel_ref_id = ($_GET["news_ref_id"] > 0)
127 ? $_GET["news_ref_id"]
128 : $ilUser->getPref("news_sel_ref_id");
129
130 include_once("./Services/News/classes/class.ilNewsItem.php");
131 $per = ($_SESSION["news_pd_news_per"] != "")
132 ? $_SESSION["news_pd_news_per"]
134 $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
135
136 // related objects (contexts) of news
137 $contexts[0] = $lng->txt("news_all_items");
138
139 $conts = array();
140 $sel_has_news = false;
141 foreach ($ref_ids as $ref_id) {
142 $obj_id = ilObject::_lookupObjId($ref_id);
143 $title = ilObject::_lookupTitle($obj_id);
144
145 $conts[$ref_id] = $title;
146 if ($sel_ref_id == $ref_id) {
147 $sel_has_news = true;
148 }
149 }
150
151 $cnt = array();
152 $nitem = new ilNewsItem();
153 $news_items = $nitem->_getNewsItemsOfUser(
154 $ilUser->getId(),
155 false,
156 true,
157 $per,
158 $cnt
159 );
160
161 // reset selected news ref id, if no news are given for id
162 if (!$sel_has_news) {
163 $sel_ref_id = "";
164 }
165 asort($conts);
166 foreach ($conts as $ref_id => $title) {
167 $contexts[$ref_id] = $title . " (" . (int) $cnt[$ref_id] . ")";
168 }
169
170
171 if ($sel_ref_id > 0) {
172 $obj_id = ilObject::_lookupObjId($sel_ref_id);
173 $obj_type = ilObject::_lookupType($obj_id);
174 $nitem->setContextObjId($obj_id);
175 $nitem->setContextObjType($obj_type);
176 $news_items = $nitem->getNewsForRefId(
177 $sel_ref_id,
178 false,
179 false,
180 $per,
181 true
182 );
183 }
184
185 include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
186 $pd_news_table = new ilPDNewsTableGUI($this, "view", $contexts, $sel_ref_id);
187 $pd_news_table->setData($news_items);
188 $pd_news_table->setNoEntriesText($lng->txt("news_no_news_items"));
189
190 $tpl->setContent($pd_news_table->getHTML());
191 }
192
196 public function applyFilter()
197 {
199
200 $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
201 $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
202 if ($_POST["news_per"] > 0) {
203 $_SESSION["news_pd_news_per"] = $_POST["news_per"];
204 }
205 $this->ctrl->redirect($this, "view");
206 }
207
211 public function resetFilter()
212 {
214 $this->ctrl->setParameter($this, "news_ref_id", 0);
215 $ilUser->writePref("news_sel_ref_id", 0);
216 $_SESSION["news_pd_news_per"] = "";
217 $this->ctrl->redirect($this, "view");
218 }
219}
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 getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static infoPanel($a_keep=true)
global $DIC
Definition: goto.php:24
help()
Definition: help.php:2
$ilUser
Definition: imgupload.php:18