ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDNewsTableGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("Services/Table/classes/class.ilTable2GUI.php");
25 
35 {
36 
37  function ilPDNewsTableGUI($a_parent_obj, $a_parent_cmd = "", $a_contexts,
38  $a_selected_context)
39  {
40  global $ilCtrl, $lng;
41 
42  parent::__construct($a_parent_obj, $a_parent_cmd);
43 
44  $this->contexts = $a_contexts;
45  $this->selected_context = $a_selected_context;
46  $this->addColumn("");
47  //$this->addColumn($lng->txt("date"), "creation_date", "1");
48  //$this->addColumn($lng->txt("news_news_item_content"), "");
49  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
50  $this->setRowTemplate("tpl.table_row_pd_news.html",
51  "Services/News");
52  $this->setDefaultOrderField("update_date");
53  $this->setDefaultOrderDirection("desc");
54  $this->setEnableTitle(false);
55  $this->setEnableHeader(false);
56  $this->setIsDataTable(false);
57  $this->initFilter();
58  }
59 
63  function initFilter()
64  {
65  global $lng, $ilUser;
66 
67  // period
68  $per = ($_SESSION["news_pd_news_per"] != "")
69  ? $_SESSION["news_pd_news_per"]
70  : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
71  $news_set = new ilSetting("news");
72  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
73  $allow_longer_periods = $news_set->get("allow_longer_periods");
74  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
75 
76  $options = array(
77  2 => sprintf($lng->txt("news_period_x_days"), 2),
78  3 => sprintf($lng->txt("news_period_x_days"), 3),
79  5 => sprintf($lng->txt("news_period_x_days"), 5),
80  7 => $lng->txt("news_period_1_week"),
81  14 => sprintf($lng->txt("news_period_x_weeks"), 2),
82  30 => $lng->txt("news_period_1_month"),
83  60 => sprintf($lng->txt("news_period_x_months"), 2),
84  120 => sprintf($lng->txt("news_period_x_months"), 4),
85  180 => sprintf($lng->txt("news_period_x_months"), 6),
86  366 => $lng->txt("news_period_1_year"));
87 
88  $unset = array();
89  foreach($options as $k => $opt)
90  {
91  if (!$allow_shorter_periods && ($k < $default_per)) $unset[$k] = $k;
92  if (!$allow_longer_periods && ($k > $default_per)) $unset[$k] = $k;
93  }
94  foreach($unset as $k)
95  {
96  unset($options[$k]);
97  }
98 
99  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
100  $si = new ilSelectInputGUI($this->lng->txt("news_time_period"), "news_per");
101  $si->setOptions($options);
102  $si->setValue($per);
103  $this->addFilterItem($si);
104 
105  // related to...
106  $si = new ilSelectInputGUI($this->lng->txt("context"), "news_ref_id");
107  $si->setOptions($this->contexts);
108  $si->setValue($this->selected_context);
109  $this->addFilterItem($si);
110  }
111 
112 
117  protected function fillRow($a_set)
118  {
119  global $lng, $ilCtrl;
120 
121  $news_set = new ilSetting("news");
122  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
123 
124  // context
125  $obj_id = ilObject::_lookupObjId($a_set["ref_id"]);
126  $obj_type = ilObject::_lookupType($obj_id);
127  $obj_title = ilObject::_lookupTitle($obj_id);
128 
129  // user
130  if ($a_set["user_id"] > 0)
131  {
132  $this->tpl->setCurrentBlock("user_info");
133  if ($obj_type == "frm")
134  {
135  include_once("./Modules/Forum/classes/class.ilForumProperties.php");
136  if (ilForumProperties::_isAnonymized($a_set["context_obj_id"]))
137  {
138  if ($a_set["context_sub_obj_type"] == "pos" &&
139  $a_set["context_sub_obj_id"] > 0)
140  {
141  include_once("./Modules/Forum/classes/class.ilForumPost.php");
142  $post = new ilForumPost($a_set["context_sub_obj_id"]);
143  if ($post->getUserAlias() != "") $this->tpl->setVariable("VAL_AUTHOR", ilUtil::stripSlashes($post->getUserAlias()));
144  else $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
145  }
146  else
147  {
148  $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
149  }
150  }
151  else
152  {
153  if (ilObject::_exists($a_set["user_id"]))
154  {
155  $user_obj = new ilObjUser($a_set["user_id"]);
156  $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
157  }
158  }
159  }
160  else
161  {
162  if (ilObject::_exists($a_set["user_id"]))
163  {
164  $user_obj = new ilObjUser($a_set["user_id"]);
165  $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
166  }
167  }
168  $this->tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
169  $this->tpl->parseCurrentBlock();
170  }
171 
172  // media player
173  if ($a_set["content_type"] == NEWS_AUDIO &&
174  $a_set["mob_id"] > 0 && ilObject::_exists($a_set["mob_id"]))
175  {
176  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
177  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
178  $mob = new ilObjMediaObject($a_set["mob_id"]);
179  $med = $mob->getMediaItem("Standard");
180  $mpl = new ilMediaPlayerGUI();
181  $mpl->setFile(ilObjMediaObject::_getDirectory($a_set["mob_id"])."/".
182  $med->getLocation());
183  $this->tpl->setCurrentBlock("player");
184  $this->tpl->setVariable("PLAYER",
185  $mpl->getMp3PlayerHtml());
186  $this->tpl->parseCurrentBlock();
187  }
188 
189  // access
190  if ($enable_internal_rss)
191  {
192  $this->tpl->setCurrentBlock("access");
193  include_once("./Services/Block/classes/class.ilBlockSetting.php");
194  $this->tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
195  if ($a_set["visibility"] == NEWS_PUBLIC ||
196  ($a_set["priority"] == 0 &&
197  ilBlockSetting::_lookup("news", "public_notifications",
198  0, $obj_id)))
199  {
200  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
201  }
202  else
203  {
204  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
205  }
206  $this->tpl->parseCurrentBlock();
207  }
208 
209  // content
210  if ($a_set["content"] != "")
211  {
212  $this->tpl->setCurrentBlock("content");
213  $this->tpl->setVariable("VAL_CONTENT", ilUtil::makeClickable($a_set["content"], true));
214  $this->tpl->parseCurrentBlock();
215  }
216  if ($a_set["content_long"] != "")
217  {
218  $this->tpl->setCurrentBlock("long");
219  $this->tpl->setVariable("VAL_LONG_CONTENT", ilUtil::makeClickable($a_set["content_long"], true));
220  $this->tpl->parseCurrentBlock();
221  }
222  if ($a_set["update_date"] != $a_set["creation_date"]) // update date
223  {
224  $this->tpl->setCurrentBlock("ni_update");
225  $this->tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
226  $this->tpl->setVariable("VAL_LAST_UPDATE",
227  ilDatePresentation::formatDate(new ilDateTime($a_set["update_date"],IL_CAL_DATETIME)));
228  $this->tpl->parseCurrentBlock();
229  }
230 
231  // forum hack, not nice
232  $add = "";
233  if ($obj_type == "frm" && $a_set["context_sub_obj_type"] == "pos"
234  && $a_set["context_sub_obj_id"] > 0)
235  {
236  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
237  $pos = $a_set["context_sub_obj_id"];
238  $thread = ilObjForumAccess::_getThreadForPosting($pos);
239  if ($thread > 0)
240  {
241  $add = "_".$thread."_".$pos;
242  }
243  }
244  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
245  $obj_type."_".$a_set["ref_id"].$add;
246  $this->tpl->setCurrentBlock("context");
247  $cont_loc = new ilLocatorGUI();
248  $cont_loc->addContextItems($a_set["ref_id"], true);
249  $this->tpl->setVariable("CONTEXT_LOCATOR",
250  $cont_loc->getHTML());
251  $this->tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
252  $this->tpl->setVariable("CONTEXT_TITLE", $obj_title);
253  $this->tpl->setVariable("ALT_CONTEXT_TITLE",
254  $lng->txt("icon")." ".$lng->txt("obj_".$obj_type));
255  $this->tpl->setVariable("IMG_CONTEXT_TITLE",
256  ilUtil::getImagePath("icon_".$obj_type.".svg"));
257  $this->tpl->parseCurrentBlock();
258 
259  $this->tpl->setVariable("HREF_TITLE", $url_target);
260 
261  // title
262  if ($a_set["content_is_lang_var"])
263  {
264  $this->tpl->setVariable("VAL_TITLE", $lng->txt($a_set["title"]));
265  }
266  else
267  {
268  $this->tpl->setVariable("VAL_TITLE", ilUtil::stripSlashes($a_set["title"])); // title
269  }
270 
271  // creation date
272  $this->tpl->setVariable("VAL_CREATION_DATE",
273  ilDatePresentation::formatDate(new ilDateTime($a_set["creation_date"],IL_CAL_DATETIME)));
274  $this->tpl->setVariable("TXT_CREATED", $lng->txt("created"));
275 
276  $this->tpl->parseCurrentBlock();
277  }
278 }
279 ?>