ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilPDNewsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
26 {
27  protected \ILIAS\News\InternalGUIService $gui;
28  protected string $selected_context;
32  protected array $contexts;
33  protected ilObjUser $user;
35 
36  public function __construct(
37  ilPDNewsGUI $a_parent_obj,
38  string $a_parent_cmd,
39  array $a_contexts,
40  string $a_selected_context
41  ) {
42  global $DIC;
43 
44  $this->ctrl = $DIC->ctrl();
45  $this->lng = $DIC->language();
46  $this->user = $DIC->user();
47  $ilCtrl = $DIC->ctrl();
48  $this->std_request = $DIC->news()
49  ->internal()
50  ->gui()
51  ->standardRequest();
52 
53  parent::__construct($a_parent_obj, $a_parent_cmd);
54 
55  $this->contexts = $a_contexts;
56  $this->selected_context = $a_selected_context;
57  $this->addColumn("");
58  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
59  $this->setRowTemplate(
60  "tpl.table_row_pd_news.html",
61  "components/ILIAS/News"
62  );
63  $this->setDefaultOrderField("update_date");
64  $this->setDefaultOrderDirection("desc");
65  $this->setEnableTitle(false);
66  $this->setEnableHeader(false);
67  $this->setIsDataTable(false);
68  $this->initFilter();
69  $this->gui = $DIC->news()->internal()->gui();
70  }
71 
72  public function initFilter(): void
73  {
74  $lng = $this->lng;
75  $ilUser = $this->user;
76 
77  // period
78  $per = (ilSession::get("news_pd_news_per") != "")
79  ? ilSession::get("news_pd_news_per")
80  : ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
81  $news_set = new ilSetting("news");
82  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
83  $allow_longer_periods = $news_set->get("allow_longer_periods");
84  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
85 
86  $options = [
87  2 => sprintf($lng->txt("news_period_x_days"), 2),
88  3 => sprintf($lng->txt("news_period_x_days"), 3),
89  5 => sprintf($lng->txt("news_period_x_days"), 5),
90  7 => $lng->txt("news_period_1_week"),
91  14 => sprintf($lng->txt("news_period_x_weeks"), 2),
92  30 => $lng->txt("news_period_1_month"),
93  60 => sprintf($lng->txt("news_period_x_months"), 2),
94  120 => sprintf($lng->txt("news_period_x_months"), 4),
95  180 => sprintf($lng->txt("news_period_x_months"), 6),
96  366 => $lng->txt("news_period_1_year")
97  ];
98 
99  $unset = [];
100  foreach ($options as $k => $opt) {
101  if (!$allow_shorter_periods && ($k < $default_per)) {
102  $unset[$k] = $k;
103  }
104  if (!$allow_longer_periods && ($k > $default_per)) {
105  $unset[$k] = $k;
106  }
107  }
108  foreach ($unset as $k) {
109  unset($options[$k]);
110  }
111 
112  $si = new ilSelectInputGUI($this->lng->txt("news_time_period"), "news_per");
113  $si->setOptions($options);
114  $si->setValue((string) $per);
115  $this->addFilterItem($si);
116 
117  // related to...
118  $si = new ilSelectInputGUI($this->lng->txt("context"), "news_ref_id");
119  $si->setOptions($this->contexts);
120  $si->setValue($this->selected_context);
121  $this->addFilterItem($si);
122  }
123 
124  protected function fillRow(array $a_set): void
125  {
126  $lng = $this->lng;
127  $ilCtrl = $this->ctrl;
128 
129  $news_set = new ilSetting("news");
130  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
131 
132  // context
133  $obj_id = ilObject::_lookupObjId((int) $a_set["ref_id"]);
134  $obj_type = ilObject::_lookupType($obj_id);
135  $obj_title = ilObject::_lookupTitle($obj_id);
136 
137  // user
138  if ($a_set["user_id"] > 0) {
139  $this->tpl->setCurrentBlock("user_info");
140  if ($obj_type === "frm") {
141  if (ilForumProperties::_isAnonymized((int) $a_set["context_obj_id"])) {
142  if ($a_set["context_sub_obj_type"] === "pos" &&
143  $a_set["context_sub_obj_id"] > 0) {
144  $post = new ilForumPost((int) $a_set["context_sub_obj_id"]);
145  if (is_string($post->getUserAlias()) && $post->getUserAlias() !== '') {
146  $this->tpl->setVariable("VAL_AUTHOR", ilUtil::stripSlashes($post->getUserAlias()));
147  } else {
148  $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
149  }
150  } else {
151  $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
152  }
153  } elseif (ilObject::_exists((int) $a_set["user_id"])) {
154  $user_obj = new ilObjUser((int) $a_set["user_id"]);
155  $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
156  }
157  } elseif (ilObject::_exists((int) $a_set["user_id"])) {
158  $this->tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin((int) $a_set["user_id"]));
159  }
160  $this->tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
161  $this->tpl->parseCurrentBlock();
162  }
163 
164  // media player
165  if ($a_set["content_type"] === NEWS_AUDIO &&
166  $a_set["mob_id"] > 0 && ilObject::_exists((int) $a_set["mob_id"])) {
167  $mob = new ilObjMediaObject((int) $a_set["mob_id"]);
168  $med = $mob->getMediaItem("Standard");
169  }
170 
171  // access
172  if ($enable_internal_rss) {
173  $this->tpl->setCurrentBlock("access");
174  $this->tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
175  if ($a_set["visibility"] === NEWS_PUBLIC ||
176  ((int) $a_set["priority"] === 0 &&
178  "news",
179  "public_notifications",
180  0,
181  $obj_id
182  ))) {
183  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
184  } else {
185  $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
186  }
187  $this->tpl->parseCurrentBlock();
188  }
189 
190  // content
191  if ($a_set["content"] != "") {
192  $this->tpl->setCurrentBlock("content");
193  $this->tpl->setVariable(
194  "VAL_CONTENT",
195  nl2br($this->makeClickable(
197  $a_set["context_obj_type"],
198  $a_set["content"],
199  (bool) $a_set["content_text_is_lang_var"]
200  )
201  ))
202  );
203  $this->tpl->parseCurrentBlock();
204  }
205  if ($a_set["content_long"] != "") {
206  $this->tpl->setCurrentBlock("long");
207  $this->tpl->setVariable("VAL_LONG_CONTENT", ilUtil::makeClickable($a_set["content_long"], true));
208  $this->tpl->parseCurrentBlock();
209  }
210  if ($a_set["update_date"] != $a_set["creation_date"]) { // update date
211  $this->tpl->setCurrentBlock("ni_update");
212  $this->tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
213  $this->tpl->setVariable(
214  "VAL_LAST_UPDATE",
215  ilDatePresentation::formatDate(new ilDateTime($a_set["update_date"], IL_CAL_DATETIME))
216  );
217  $this->tpl->parseCurrentBlock();
218  }
219 
220  // forum hack, not nice
221  $add = "";
222  if ($obj_type === "frm" && $a_set["context_sub_obj_type"] === "pos"
223  && $a_set["context_sub_obj_id"] > 0) {
224  $pos = $a_set["context_sub_obj_id"];
225  $thread = ilObjForumAccess::_getThreadForPosting((int) $pos);
226  if ($thread > 0) {
227  $add = "_" . $thread . "_" . $pos;
228  }
229  }
230 
231  // file hack, not nice
232  if ($obj_type === "file") {
233  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_set["ref_id"]);
234  $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "sendfile");
235  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->std_request->getRefId());
236 
237  $button = $this->gui->button(
238  $this->lng->txt("download"),
239  $url
240  );
241 
242  $this->tpl->setCurrentBlock("download");
243  $this->tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
244  $this->tpl->parseCurrentBlock();
245  }
246 
247  // wiki hack, not nice
248  if ($obj_type === "wiki" && $a_set["context_sub_obj_type"] === "wpg"
249  && $a_set["context_sub_obj_id"] > 0) {
250  $wptitle = ilWikiPage::lookupTitle((int) $a_set["context_sub_obj_id"]);
251  if ($wptitle != "") {
252  $add = "_" . ilWikiUtil::makeUrlTitle($wptitle);
253  }
254  }
255 
256 
257  $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
258  $obj_type . "_" . $a_set["ref_id"] . $add;
259 
260  // lm page hack, not nice
261  if ($a_set["context_sub_obj_type"] === "pg" &&
262  $a_set["context_sub_obj_id"] > 0 &&
263  in_array($obj_type, ["dbk", "lm"], true)) {
264  $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
265  "pg_" . $a_set["context_sub_obj_id"] . "_" . $a_set["ref_id"];
266  }
267 
268 
269  $this->tpl->setCurrentBlock("context");
270  $cont_loc = new ilLocatorGUI();
271  $cont_loc->addContextItems($a_set["ref_id"], true);
272  $this->tpl->setVariable(
273  "CONTEXT_LOCATOR",
274  $cont_loc->getHTML()
275  );
276  $this->tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
277  $this->tpl->setVariable("CONTEXT_TITLE", $obj_title);
278  $this->tpl->setVariable(
279  "ALT_CONTEXT_TITLE",
280  $lng->txt("icon") . " " . $lng->txt("obj_" . $obj_type)
281  );
282  $this->tpl->setVariable(
283  "IMG_CONTEXT_TITLE",
284  ilObject::_getIcon((int) $a_set["context_obj_id"])
285  );
286  $this->tpl->parseCurrentBlock();
287 
288  $this->tpl->setVariable("HREF_TITLE", $url_target);
289 
290  // title
291  $this->tpl->setVariable(
292  "VAL_TITLE",
293  ilNewsItem::determineNewsTitle($a_set["context_obj_type"], $a_set["title"], $a_set["content_is_lang_var"])
294  );
295 
296  // creation date
297  $this->tpl->setVariable(
298  "VAL_CREATION_DATE",
299  ilDatePresentation::formatDate(new ilDateTime($a_set["creation_date"], IL_CAL_DATETIME))
300  );
301  $this->tpl->setVariable("TXT_CREATED", $lng->txt("created"));
302 
303  $this->tpl->parseCurrentBlock();
304  }
305 
306  public function makeClickable(string $a_str): string
307  {
308  // this fixes bug 8744. We assume that strings that contain < and >
309  // already contain html, we do not handle these
310  if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<"))) {
311  return $a_str;
312  }
313 
314  return ilUtil::makeClickable($a_str);
315  }
316 }
static get(string $a_var)
static determineNewsContent(string $a_context_obj_type, string $a_content, bool $a_is_lang_var, ?ilLanguage $lng=null)
Determine new content.
static _lookupUserPDPeriod(int $a_user_id)
const IL_CAL_DATETIME
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
ILIAS News InternalGUIService $gui
This class represents a selection list property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static lookupTitle(int $a_page_id, string $lang="-")
$url
Definition: shib_logout.php:66
setOptions(array $a_options)
ilLanguage $lng
makeClickable(string $a_str)
Personal desktop news table.
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isAnonymized(int $a_obj_id)
setIsDataTable(bool $a_val)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
__construct(ilPDNewsGUI $a_parent_obj, string $a_parent_cmd, array $a_contexts, string $a_selected_context)
const NEWS_PUBLIC
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
static _lookupTitle(int $obj_id)
setDefaultOrderField(string $a_defaultorderfield)
StandardGUIRequest $std_request
static determineNewsTitle(string $a_context_obj_type, string $a_title, bool $a_content_is_lang_var, int $a_agg_ref_id=0, array $a_aggregation=[], ?ilLanguage $lng=null)
Determine title for news item entry.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: shib_login.php:22
setDefaultOrderDirection(string $a_defaultorderdirection)
static _getThreadForPosting(int $a_pos_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static makeUrlTitle(string $a_par)
__construct(Container $dic, ilPlugin $plugin)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
const NEWS_AUDIO
News on PD.
static _lookupType(int $id, bool $reference=false)
$post
Definition: ltitoken.php:46
static makeClickable(string $a_text, bool $detectGotoLinks=false)
setEnableHeader(bool $a_enableheader)
static _lookupDefaultPDPeriod()
static _lookupLogin(int $a_user_id)