ILIAS  eassessment Revision 61809
 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 (ilObject::_exists($a_set["user_id"]))
135  {
136  $user_obj = new ilObjUser($a_set["user_id"]);
137  $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
138  }
139  $this->tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
140  $this->tpl->parseCurrentBlock();
141  }
142 
143  // media player
144  if ($a_set["content_type"] == NEWS_AUDIO &&
145  $a_set["mob_id"] > 0 && ilObject::_exists($a_set["mob_id"]))
146  {
147  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
148  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
149  $mob = new ilObjMediaObject($a_set["mob_id"]);
150  $med = $mob->getMediaItem("Standard");
151  $mpl = new ilMediaPlayerGUI();
152  $mpl->setFile(ilObjMediaObject::_getDirectory($a_set["mob_id"])."/".
153  $med->getLocation());
154  $this->tpl->setCurrentBlock("player");
155  $this->tpl->setVariable("PLAYER",
156  $mpl->getMp3PlayerHtml());
157  $this->tpl->parseCurrentBlock();
158  }
159 
160  // access
161  if ($enable_internal_rss)
162  {
163  $this->tpl->setCurrentBlock("access");
164  include_once("./Services/Block/classes/class.ilBlockSetting.php");
165  $this->tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
166  if ($a_set["visibility"] == NEWS_PUBLIC ||
167  ($a_set["priority"] == 0 &&
168  ilBlockSetting::_lookup("news", "public_notifications",
169  0, $obj_id)))
170  {
171  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
172  }
173  else
174  {
175  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
176  }
177  $this->tpl->parseCurrentBlock();
178  }
179 
180  // content
181  if ($a_set["content"] != "")
182  {
183  $this->tpl->setCurrentBlock("content");
184  $this->tpl->setVariable("VAL_CONTENT", ilUtil::makeClickable($a_set["content"], true));
185  $this->tpl->parseCurrentBlock();
186  }
187  if ($a_set["content_long"] != "")
188  {
189  $this->tpl->setCurrentBlock("long");
190  $this->tpl->setVariable("VAL_LONG_CONTENT", ilUtil::makeClickable($a_set["content_long"], true));
191  $this->tpl->parseCurrentBlock();
192  }
193  if ($a_set["update_date"] != $a_set["creation_date"]) // update date
194  {
195  $this->tpl->setCurrentBlock("ni_update");
196  $this->tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
197  $this->tpl->setVariable("VAL_LAST_UPDATE",
198  ilDatePresentation::formatDate(new ilDateTime($a_set["update_date"],IL_CAL_DATETIME)));
199  $this->tpl->parseCurrentBlock();
200  }
201 
202  $add = "";
203  $url_target = "./goto.php?client_id=".rawurlencode(CLIENT_ID)."&target=".
204  $obj_type."_".$a_set["ref_id"].$add;
205  $this->tpl->setCurrentBlock("context");
206  $cont_loc = new ilLocatorGUI();
207  $cont_loc->addContextItems($a_set["ref_id"], true);
208  $this->tpl->setVariable("CONTEXT_LOCATOR",
209  $cont_loc->getHTML());
210  $this->tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
211  $this->tpl->setVariable("CONTEXT_TITLE", $obj_title);
212  $this->tpl->setVariable("ALT_CONTEXT_TITLE",
213  $lng->txt("icon")." ".$lng->txt("obj_".$obj_type));
214  $this->tpl->setVariable("IMG_CONTEXT_TITLE",
215  ilUtil::getImagePath("icon_".$obj_type."_b.gif"));
216  $this->tpl->parseCurrentBlock();
217 
218  $this->tpl->setVariable("HREF_TITLE", $url_target);
219 
220  // title
221  if ($a_set["content_is_lang_var"])
222  {
223  $this->tpl->setVariable("VAL_TITLE", $lng->txt($a_set["title"]));
224  }
225  else
226  {
227  $this->tpl->setVariable("VAL_TITLE", ilUtil::stripSlashes($a_set["title"])); // title
228  }
229 
230  // creation date
231  $this->tpl->setVariable("VAL_CREATION_DATE",
232  ilDatePresentation::formatDate(new ilDateTime($a_set["creation_date"],IL_CAL_DATETIME)));
233  $this->tpl->setVariable("TXT_CREATED", $lng->txt("created"));
234 
235  $this->tpl->parseCurrentBlock();
236  }
237 }
238 ?>