ILIAS  Release_4_2_x_branch Revision 61807
 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->setCloseCommand($ilCtrl->getParentReturnByClass("ilpdnewsgui"));
57  $this->setIsDataTable(false);
58  $this->initFilter();
59  }
60 
64  function initFilter()
65  {
66  global $lng, $ilUser;
67 
68  // period
69  $per = ($_SESSION["news_pd_news_per"] != "")
70  ? $_SESSION["news_pd_news_per"]
71  : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
72  $news_set = new ilSetting("news");
73  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
74  $allow_longer_periods = $news_set->get("allow_longer_periods");
75  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
76 
77  $options = array(
78  2 => sprintf($lng->txt("news_period_x_days"), 2),
79  3 => sprintf($lng->txt("news_period_x_days"), 3),
80  5 => sprintf($lng->txt("news_period_x_days"), 5),
81  7 => $lng->txt("news_period_1_week"),
82  14 => sprintf($lng->txt("news_period_x_weeks"), 2),
83  30 => $lng->txt("news_period_1_month"),
84  60 => sprintf($lng->txt("news_period_x_months"), 2),
85  120 => sprintf($lng->txt("news_period_x_months"), 4),
86  180 => sprintf($lng->txt("news_period_x_months"), 6),
87  366 => $lng->txt("news_period_1_year"));
88 
89  $unset = array();
90  foreach($options as $k => $opt)
91  {
92  if (!$allow_shorter_periods && ($k < $default_per)) $unset[$k] = $k;
93  if (!$allow_longer_periods && ($k > $default_per)) $unset[$k] = $k;
94  }
95  foreach($unset as $k)
96  {
97  unset($options[$k]);
98  }
99 
100  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
101  $si = new ilSelectInputGUI($this->lng->txt("news_time_period"), "news_per");
102  $si->setOptions($options);
103  $si->setValue($per);
104  $this->addFilterItem($si);
105 
106  // related to...
107  $si = new ilSelectInputGUI($this->lng->txt("context"), "news_ref_id");
108  $si->setOptions($this->contexts);
109  $si->setValue($this->selected_context);
110  $this->addFilterItem($si);
111  }
112 
113 
118  protected function fillRow($a_set)
119  {
120  global $lng, $ilCtrl;
121 
122  $news_set = new ilSetting("news");
123  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
124 
125  // context
126  $obj_id = ilObject::_lookupObjId($a_set["ref_id"]);
127  $obj_type = ilObject::_lookupType($obj_id);
128  $obj_title = ilObject::_lookupTitle($obj_id);
129 
130  // user
131  if ($a_set["user_id"] > 0)
132  {
133  $this->tpl->setCurrentBlock("user_info");
134  if ($obj_type == "frm")
135  {
136  include_once("./Modules/Forum/classes/class.ilForumProperties.php");
137  if (ilForumProperties::_isAnonymized($a_set["context_obj_id"]))
138  {
139  if ($a_set["context_sub_obj_type"] == "pos" &&
140  $a_set["context_sub_obj_id"] > 0)
141  {
142  include_once("./Modules/Forum/classes/class.ilForumPost.php");
143  $post = new ilForumPost($a_set["context_sub_obj_id"]);
144  if ($post->getUserAlias() != "") $this->tpl->setVariable("VAL_AUTHOR", ilUtil::stripSlashes($post->getUserAlias()));
145  else $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
146  }
147  else
148  {
149  $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
150  }
151  }
152  else
153  {
154  if (ilObject::_exists($a_set["user_id"]))
155  {
156  $user_obj = new ilObjUser($a_set["user_id"]);
157  $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
158  }
159  }
160  }
161  else
162  {
163  if (ilObject::_exists($a_set["user_id"]))
164  {
165  $user_obj = new ilObjUser($a_set["user_id"]);
166  $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
167  }
168  }
169  $this->tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
170  $this->tpl->parseCurrentBlock();
171  }
172 
173  // media player
174  if ($a_set["content_type"] == NEWS_AUDIO &&
175  $a_set["mob_id"] > 0 && ilObject::_exists($a_set["mob_id"]))
176  {
177  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
178  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
179  $mob = new ilObjMediaObject($a_set["mob_id"]);
180  $med = $mob->getMediaItem("Standard");
181  $mpl = new ilMediaPlayerGUI();
182  $mpl->setFile(ilObjMediaObject::_getDirectory($a_set["mob_id"])."/".
183  $med->getLocation());
184  $this->tpl->setCurrentBlock("player");
185  $this->tpl->setVariable("PLAYER",
186  $mpl->getMp3PlayerHtml());
187  $this->tpl->parseCurrentBlock();
188  }
189 
190  // access
191  if ($enable_internal_rss)
192  {
193  $this->tpl->setCurrentBlock("access");
194  include_once("./Services/Block/classes/class.ilBlockSetting.php");
195  $this->tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
196  if ($a_set["visibility"] == NEWS_PUBLIC ||
197  ($a_set["priority"] == 0 &&
198  ilBlockSetting::_lookup("news", "public_notifications",
199  0, $obj_id)))
200  {
201  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
202  }
203  else
204  {
205  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
206  }
207  $this->tpl->parseCurrentBlock();
208  }
209 
210  // content
211  if ($a_set["content"] != "")
212  {
213  $this->tpl->setCurrentBlock("content");
214  $this->tpl->setVariable("VAL_CONTENT", ilUtil::makeClickable($a_set["content"], true));
215  $this->tpl->parseCurrentBlock();
216  }
217  if ($a_set["content_long"] != "")
218  {
219  $this->tpl->setCurrentBlock("long");
220  $this->tpl->setVariable("VAL_LONG_CONTENT", ilUtil::makeClickable($a_set["content_long"], true));
221  $this->tpl->parseCurrentBlock();
222  }
223  if ($a_set["update_date"] != $a_set["creation_date"]) // update date
224  {
225  $this->tpl->setCurrentBlock("ni_update");
226  $this->tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
227  $this->tpl->setVariable("VAL_LAST_UPDATE",
228  ilDatePresentation::formatDate(new ilDateTime($a_set["update_date"],IL_CAL_DATETIME)));
229  $this->tpl->parseCurrentBlock();
230  }
231 
232  // forum hack, not nice
233  $add = "";
234  if ($obj_type == "frm" && $a_set["context_sub_obj_type"] == "pos"
235  && $a_set["context_sub_obj_id"] > 0)
236  {
237  include_once("./Modules/Forum/classes/class.ilObjForumAccess.php");
238  $pos = $a_set["context_sub_obj_id"];
240  if ($thread > 0)
241  {
242  $add = "_".$thread."_".$pos;
243  }
244  }
245  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
246  $obj_type."_".$a_set["ref_id"].$add;
247  $this->tpl->setCurrentBlock("context");
248  $cont_loc = new ilLocatorGUI();
249  $cont_loc->addContextItems($a_set["ref_id"], true);
250  $this->tpl->setVariable("CONTEXT_LOCATOR",
251  $cont_loc->getHTML());
252  $this->tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
253  $this->tpl->setVariable("CONTEXT_TITLE", $obj_title);
254  $this->tpl->setVariable("ALT_CONTEXT_TITLE",
255  $lng->txt("icon")." ".$lng->txt("obj_".$obj_type));
256  $this->tpl->setVariable("IMG_CONTEXT_TITLE",
257  ilUtil::getImagePath("icon_".$obj_type."_b.gif"));
258  $this->tpl->parseCurrentBlock();
259 
260  $this->tpl->setVariable("HREF_TITLE", $url_target);
261 
262  // title
263  if ($a_set["content_is_lang_var"])
264  {
265  $this->tpl->setVariable("VAL_TITLE", $lng->txt($a_set["title"]));
266  }
267  else
268  {
269  $this->tpl->setVariable("VAL_TITLE", ilUtil::stripSlashes($a_set["title"])); // title
270  }
271 
272  // creation date
273  $this->tpl->setVariable("VAL_CREATION_DATE",
274  ilDatePresentation::formatDate(new ilDateTime($a_set["creation_date"],IL_CAL_DATETIME)));
275  $this->tpl->setVariable("TXT_CREATED", $lng->txt("created"));
276 
277  $this->tpl->parseCurrentBlock();
278  }
279 }
280 ?>