ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDNewsGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
36 {
37 
43  function ilPDNewsGUI()
44  {
45  global $tpl, $lng, $ilCtrl;
46 
47  // initiate variables
48  $this->tpl =& $tpl;
49  $this->lng =& $lng;
50  $this->ctrl =& $ilCtrl;
51 
52  $lng->loadLanguageModule("news");
53 
54  $this->ctrl->saveParameter($this, "news_ref_id");
55  }
56 
60  function &executeCommand()
61  {
62  $next_class = $this->ctrl->getNextClass();
63 
64  switch($next_class)
65  {
66 
67  default:
68  $cmd = $this->ctrl->getCmd("view");
69  $this->displayHeader();
70  $this->$cmd();
71  break;
72  }
73  $this->tpl->show(true);
74  return true;
75  }
76 
80  function displayHeader()
81  {
82  $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_pd_b.gif"),
83  $this->lng->txt("personal_desktop"));
84  $this->tpl->setTitle($this->lng->txt("personal_desktop"));
85 
86  // catch feedback message
88  // display infopanel if something happened
90  }
91 
92  /*
93  * display notes
94  */
95  function view()
96  {
97  global $ilUser, $lng, $tpl, $ilCtrl;
98 
99  $news_tpl = new ilTemplate("tpl.pd_news.html", true, true, "Services/News");
100 
101  include_once("Services/News/classes/class.ilNewsSubscription.php");
102  include_once("Services/News/classes/class.ilNewsItem.php");
103 
104  // period
105  $per = ($_SESSION["news_pd_news_per"] != "")
106  ? $_SESSION["news_pd_news_per"]
107  : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
108  $news_set = new ilSetting("news");
109  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
110  $allow_longer_periods = $news_set->get("allow_longer_periods");
111  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
112 
113  $per_opts = array(
114  2 => sprintf($lng->txt("news_period_x_days"), 2),
115  3 => sprintf($lng->txt("news_period_x_days"), 3),
116  5 => sprintf($lng->txt("news_period_x_days"), 5),
117  7 => $lng->txt("news_period_1_week"),
118  14 => sprintf($lng->txt("news_period_x_weeks"), 2),
119  30 => $lng->txt("news_period_1_month"),
120  60 => sprintf($lng->txt("news_period_x_months"), 2),
121  120 => sprintf($lng->txt("news_period_x_months"), 4),
122  180 => sprintf($lng->txt("news_period_x_months"), 6),
123  366 => $lng->txt("news_period_1_year"));
124 
125  $unset = array();
126  foreach($per_opts as $k => $opt)
127  {
128  if (!$allow_shorter_periods && ($k < $default_per)) $unset[$k] = $k;
129  if (!$allow_longer_periods && ($k > $default_per)) $unset[$k] = $k;
130  }
131  foreach($unset as $k)
132  {
133  unset($per_opts[$k]);
134  }
135  foreach($per_opts as $k => $v)
136  {
137  $news_tpl->setCurrentBlock("per_option");
138  $news_tpl->setVariable("VAL_PER", $k);
139  $news_tpl->setVariable("TXT_PER", $v);
140  if ($k == $per)
141  {
142  $news_tpl->setVariable("SEL_PER", ' selected="selected" ');
143  }
144  $news_tpl->parseCurrentBlock();
145  }
146 
147  $ref_ids = array();
148  $obj_ids = array();
149  //if ($ilUser->prefs["pd_items_news"] != "n")
150  //{
151  $pd_items = $ilUser->getDesktopItems();
152  foreach($pd_items as $item)
153  {
154  $ref_ids[] = $item["ref_id"];
155  $obj_ids[] = $item["obj_id"];
156  }
157  //}
158 
159  $sel_ref_id = ($_GET["news_ref_id"] > 0)
160  ? $_GET["news_ref_id"]
161  : $ilUser->getPref("news_sel_ref_id");
162 
163  $news_obj_ids = ilNewsItem::filterObjIdsPerNews($obj_ids, $per);
164 
165  // related objects (contexts) of news
166  $news_tpl->setCurrentBlock("related_option");
167  $news_tpl->setVariable("VAL_RELATED", "0");
168  $news_tpl->setVariable("TXT_RELATED", $lng->txt("news_all_items"));
169  $news_tpl->parseCurrentBlock();
170 
171  $conts = array();
172  $sel_has_news = false;
173  foreach ($ref_ids as $ref_id)
174  {
175  $obj_id = ilObject::_lookupObjId($ref_id);
176  $title = ilObject::_lookupTitle($obj_id);
177 
178  //if (in_array($obj_id, $news_obj_ids)) // this does not work, since news can come
179  //{ // from "lower" objects in category
180  $conts[$ref_id] = $title;
181  if ($sel_ref_id == $ref_id)
182  {
183  $sel_has_news = true;
184  }
185  //}
186  }
187 
188  $cnt = array();
189  $nitem = new ilNewsItem();
190  $news_items = $nitem->_getNewsItemsOfUser($ilUser->getId(), false,
191  true, $per, $cnt);
192 
193  // reset selected news ref id, if no news are given for id
194  if (!$sel_has_news)
195  {
196  $sel_ref_id = "";
197  }
198  asort($conts);
199  foreach($conts as $ref_id => $title)
200  {
201  $news_tpl->setCurrentBlock("related_option");
202  $news_tpl->setVariable("VAL_RELATED", $ref_id);
203  $news_tpl->setVariable("TXT_RELATED", $title." (".(int) $cnt[$ref_id].")");
204  if ($sel_ref_id == $ref_id)
205  {
206  $news_tpl->setVariable("SEL", ' selected="selected" ');
207  }
208  $news_tpl->parseCurrentBlock();
209  }
210 
211  $news_tpl->setCurrentBlock("related_selection");
212  $news_tpl->setVariable("FORMACTION", $ilCtrl->getFormAction($this));
213  $news_tpl->setVariable("TXT_RELATED_TO", $lng->txt("news_related_to"));
214  $news_tpl->setVariable("TXT_CHANGE", $lng->txt("change"));
215  $news_tpl->parseCurrentBlock();
216 
217  if ($sel_ref_id > 0)
218  {
219  $obj_id = ilObject::_lookupObjId($sel_ref_id);
220  $obj_type = ilObject::_lookupType($obj_id);
221  $nitem->setContextObjId($obj_id);
222  $nitem->setContextObjType($obj_type);
223  $news_items = $nitem->getNewsForRefId($sel_ref_id, false,
224  false, $per, true);
225  }
226 
227  include_once("./Services/News/classes/class.ilPDNewsTableGUI.php");
228  $pd_news_table = new ilPDNewsTableGUI($this, "view");
229  $pd_news_table->setData($news_items);
230 
231  if (count($news_items) > 0)
232  {
233  $news_tpl->setVariable("NEWS", $pd_news_table->getHTML());
234  }
235  else
236  {
237  $news_tpl->setCurrentBlock("no_news");
238  $news_tpl->setVariable("NO_NEWS", $lng->txt("news_no_news_items"));
239  $news_tpl->parseCurrentBlock();
240  }
241 
242  $tpl->setContent($news_tpl->get());
243  }
244 
249  {
250  global $ilUser;
251 
252  $this->ctrl->setParameter($this, "news_ref_id", $_POST["news_ref_id"]);
253  $ilUser->writePref("news_sel_ref_id", $_POST["news_ref_id"]);
254  if ($_POST["news_per"] > 0)
255  {
256  $_SESSION["news_pd_news_per"] = $_POST["news_per"];
257  }
258  $this->ctrl->redirect($this, "view");
259  }
260 
261 }
262 ?>