ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilNewsForContextBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
30 {
34  public const OBJECTS_WITH_NEWS_SUBTAB = ["category", "course", "group", "forum"];
35  protected \ILIAS\News\InternalGUIService $gui;
37  protected bool $cache_hit = false;
38  protected bool $dynamic = false;
39  protected ilNewsCache $acache;
40  protected bool $show_view_selection;
41 
45  protected string $view;
47  protected ilHelpGUI $help;
48  protected ilSetting $settings;
49  protected ilTabsGUI $tabs;
50  public static string $block_type = "news";
51  public static array $st_data;
54 
55  public function __construct()
56  {
57  global $DIC;
58  $this->ctrl = $DIC->ctrl();
59  $this->lng = $DIC->language();
60  $this->user = $DIC->user();
61  $this->help = $DIC["ilHelp"];
62  $this->access = $DIC->access();
63  $this->settings = $DIC->settings();
64  $this->tabs = $DIC->tabs();
65  $this->obj_definition = $DIC["objDefinition"];
66  $this->std_request = $DIC->news()
67  ->internal()
68  ->gui()
69  ->standardRequest();
70 
71  $this->news_access = new NewsAccess($this->std_request->getRefId());
72 
73  $ilCtrl = $DIC->ctrl();
74  $lng = $DIC->language();
75  $ilUser = $DIC->user();
76  $ilHelp = $DIC["ilHelp"];
77 
79 
80  $lng->loadLanguageModule("news");
81  $ilHelp->addHelpSection("news_block");
82 
83  $this->setBlockId((string) $ilCtrl->getContextObjId());
84  $this->setLimit(5);
85  $this->setEnableNumInfo(true);
86 
87  $this->dynamic = false;
88  $this->acache = new ilNewsCache();
89  $cres = unserialize(
90  (string) $this->acache->getEntry($ilUser->getId() . ":" . $this->std_request->getRefId()),
91  ["allowed_classes" => false]
92  );
93  $this->cache_hit = false;
94 
95  if ($this->acache->getLastAccessStatus() === "hit" && is_array($cres)) {
96  self::$st_data = ilNewsItem::prepareNewsDataFromCache($cres);
97  $this->cache_hit = true;
98  }
99  if (!empty(self::$st_data)) {
100  $data = self::$st_data;
101  } else {
102  $data = $this->getNewsData();
103  self::$st_data = $data;
104  }
105 
106  $this->setTitle($lng->txt("news_internal_news"));
107  $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
108  $this->setData($data);
109  $this->allow_moving = false;
110  $this->handleView();
111 
112  $this->setPresentation(self::PRES_SEC_LIST);
113  $this->gui = $DIC->news()->internal()->gui();
114  }
115 
116  public function getNewsData(): array
117  {
118  $ilCtrl = $this->ctrl;
119  $ilUser = $this->user;
120 
121  $this->acache = new ilNewsCache();
122  /* $cres = $this->acache->getEntry($ilUser->getId().":".$_GET["ref_id"]);
123  if ($this->acache->getLastAccessStatus() == "hit" && false)
124  {
125  $news_data = unserialize($cres);
126  }
127  else
128  {*/
129  $news_item = new ilNewsItem();
130  $news_item->setContextObjId($ilCtrl->getContextObjId());
131  $news_item->setContextObjType($ilCtrl->getContextObjType());
132 
133  // workaround, better: reduce constructor and introduce
134  //$prevent_aggregation = $this->getProperty("prevent_aggregation");
135  $prevent_aggregation = true;
136  if ($ilCtrl->getContextObjType() !== "frm") {
137  $forum_grouping = true;
138  } else {
139  $forum_grouping = false;
140  }
141 
142 
143  $news_data = $news_item->getNewsForRefId(
144  $this->std_request->getRefId(),
145  false,
146  false,
147  0,
148  $prevent_aggregation,
149  $forum_grouping
150  );
151 
152  $this->acache->storeEntry(
153  $ilUser->getId() . ":" . $this->std_request->getRefId(),
154  serialize($news_data)
155  );
156 
157  // }
158  //var_dump($news_data);
159  return $news_data;
160  }
161 
162  public function getBlockType(): string
163  {
164  return self::$block_type;
165  }
166 
167  protected function isRepositoryObject(): bool
168  {
169  return false;
170  }
171 
172  public static function getScreenMode(): string
173  {
174  global $DIC;
175 
176  $ilCtrl = $DIC->ctrl();
177 
178  if (strtolower($ilCtrl->getCmdClass()) === "ilnewsitemgui") {
179  return IL_SCREEN_FULL;
180  }
181 
182  switch ($ilCtrl->getCmd()) {
183  case "showNews":
184  case "showFeedUrl":
185  return IL_SCREEN_CENTER;
186 
187  case "editSettings":
188  case "saveSettings":
189  return IL_SCREEN_FULL;
190 
191  default:
192  return IL_SCREEN_SIDE;
193  }
194  }
195 
196  public function executeCommand()
197  {
198  $ilCtrl = $this->ctrl;
199 
200  $next_class = $ilCtrl->getNextClass();
201  $cmd = $ilCtrl->getCmd("getHTML");
202 
203  switch ($next_class) {
204  case "ilnewsitemgui":
205  $news_item_gui = new ilNewsItemGUI();
206  $news_item_gui->setEnableEdit($this->getEnableEdit());
207  $html = $ilCtrl->forwardCommand($news_item_gui);
208  return $html;
209 
210  default:
211  return $this->$cmd();
212  }
213  }
214 
215  public function getHTML(): string
216  {
217  global $DIC;
218 
219  $ilCtrl = $this->ctrl;
220  $lng = $this->lng;
221  $ilUser = $this->user;
222 
223  $news_set = new ilSetting("news");
224  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
225 
226  $hide_block = ilBlockSetting::_lookup(
227  $this->getBlockType(),
228  "hide_news_block",
229  0,
230  (int) $this->block_id
231  );
232 
233  if ($this->getProperty("title") != "") {
234  $this->setTitle($this->getProperty("title"));
235  }
236 
237  $public_feed = ilBlockSetting::_lookup(
238  $this->getBlockType(),
239  "public_feed",
240  0,
241  (int) $this->block_id
242  );
243  if ($public_feed && $enable_internal_rss) {
244  // @todo: rss icon HTML: ilRSSButtonGUI::get(ilRSSButtonGUI::ICON_RSS)
245  $this->addBlockCommand(
246  ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&" .
247  "ref_id=" . $this->std_request->getRefId(),
248  $lng->txt("news_feed_url")
249  );
250  }
251 
252  // add edit commands
253  if ($this->news_access->canAdd()) {
254  $this->addBlockCommand(
255  $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "editNews"),
256  $lng->txt("edit")
257  );
258 
259  $ilCtrl->setParameter($this, "add_mode", "block");
260  $this->addBlockCommand(
261  $ilCtrl->getLinkTargetByClass("ilnewsitemgui", "createNewsItem"),
262  $lng->txt("add")
263  );
264  $ilCtrl->setParameter($this, "add_mode", "");
265  }
266 
267  if ($this->getProperty("settings")) {
268  $ref_id = $this->std_request->getRefId();
269  $obj_def = $DIC["objDefinition"];
271  $obj_type = ilObject::_lookupType($ref_id, true);
272  $obj_class = strtolower($obj_def->getClassName($obj_type));
273  $parent_gui = "ilobj" . $obj_class . "gui";
274 
275  $ilCtrl->setParameterByClass("ilcontainernewssettingsgui", "ref_id", $ref_id);
276 
277  if (in_array($obj_class, self::OBJECTS_WITH_NEWS_SUBTAB)) {
278  $this->addBlockCommand(
279  $ilCtrl->getLinkTargetByClass(["ilrepositorygui", $parent_gui, "ilcontainernewssettingsgui"], "show"),
280  $lng->txt("settings")
281  );
282  } else {
283  // not sure if this code is still used anywhere, see discussion at
284  // https://mantis.ilias.de/view.php?id=31801
285  // If ILIAS 8 beta phase does not throw this exception, we can remove this part.
286  //throw new ilException("News settings are deprecated.");
287  // the info screen will call this
288  $this->addBlockCommand(
289  $ilCtrl->getLinkTarget($this, "editSettings"),
290  $lng->txt("settings")
291  );
292  }
293  }
294 
295  // do not display hidden repository news blocks for users
296  // who do not have write permission
297  if (!$this->getEnableEdit() && $this->getRepositoryMode() &&
299  $this->getBlockType(),
300  "hide_news_block",
301  0,
302  (int) $this->block_id
303  )) {
304  return "";
305  }
306 
307  // do not display empty news blocks for users
308  // who do not have write permission
309  if (!$this->dynamic && !$this->getEnableEdit() && $this->getRepositoryMode() && count($this->getData()) === 0 &&
310  (
311  !$news_set->get("enable_rss_for_internal") ||
313  $this->getBlockType(),
314  "public_feed",
315  0,
316  (int) $this->block_id
317  )
318  )) {
319  return "";
320  }
321 
322  $en = "";
323 
324  return parent::getHTML() . $en;
325  }
326 
330  public function handleView(): void
331  {
332  $ilUser = $this->user;
333 
334  $this->view = (string) ilBlockSetting::_lookup(
335  $this->getBlockType(),
336  "view",
337  $ilUser->getId(),
338  (int) $this->block_id
339  );
340 
341  // check whether notices and messages exist
342  $got_notices = $got_messages = false;
343  foreach ($this->data as $row) {
344  if ((int) ($row["priority"] ?? 0) === 0) {
345  $got_notices = true;
346  }
347  if ((int) ($row["priority"] ?? 0) === 1) {
348  $got_messages = true;
349  }
350  }
351  $this->show_view_selection = false;
352 
353  if ($got_notices && $got_messages) {
354  $this->show_view_selection = true;
355  } elseif ($got_notices) {
356  $this->view = "";
357  }
358  }
359 
360  public function getInfoForData(array $news): array
361  {
362  $ilCtrl = $this->ctrl;
363  $lng = $this->lng;
364  $obj_definition = $this->obj_definition;
365 
366  $info = [];
367 
368  $info["ref_id"] = $news["ref_id"] ?? 0;
369  $info["creation_date"] =
370  ilDatePresentation::formatDate(new ilDateTime($news["creation_date"], IL_CAL_DATETIME));
371 
372  // title image type
373  if (($news["ref_id"] ?? 0) > 0) {
374  if (isset($news["agg_ref_id"]) && $news["agg_ref_id"] > 0) {
375  $obj_id = ilObject::_lookupObjId($news["agg_ref_id"]);
376  $type = ilObject::_lookupType($obj_id);
377  $context_ref = $news["agg_ref_id"];
378  } else {
379  $obj_id = $news["context_obj_id"];
380  $type = $news["context_obj_type"];
381  $context_ref = $news["ref_id"];
382  }
383 
384  $lang_type = in_array($type, ["sahs", "lm", "htlm"])
385  ? "lres"
386  : "obj_" . $type;
387 
388  $type_txt = ($obj_definition->isPlugin($news["context_obj_type"]))
389  ? ilObjectPlugin::lookupTxtById($news["context_obj_type"], $lang_type)
390  : $lng->txt($lang_type);
391 
392 
393  $info["type_txt"] = $type_txt;
394  $info["type_icon"] = ilObject::_getIcon($obj_id, "tiny", $type);
395  $info["obj_title"] = ilStr::shortenWords(ilObject::_lookupTitle($obj_id));
396  $info["user_read"] = $news["user_read"];
397 
398  $ilCtrl->setParameter($this, "news_context", $context_ref);
399  } else {
400  $ilCtrl->setParameter($this, "news_context", "");
401  }
402 
403  // title
404  $info["news_title"] =
407  $news["context_obj_type"] ?? "",
408  $news["title"] ?? "",
409  $news["content_is_lang_var"] ?? false,
410  $news["agg_ref_id"] ?? 0,
411  $news["aggregation"] ?? []
412  )
413  );
414 
415 
416  $ilCtrl->setParameter($this, "news_id", $news["id"]);
417  $info["url"] =
418  $ilCtrl->getLinkTarget($this, "showNews");
419  $ilCtrl->clearParameters($this);
420 
421  return $info;
422  }
423 
424  public function getOverview(): string
425  {
426  $lng = $this->lng;
427 
428  return '<div class="small">' . (count($this->getData())) . " " . $lng->txt("news_news_items") . "</div>";
429  }
430 
431  public function showNews(): string
432  {
433  $lng = $this->lng;
434  $ilCtrl = $this->ctrl;
435  $ilUser = $this->user;
436  $ilAccess = $this->access;
437 
438  // workaround for dynamic mode (if cache is disabled, showNews has no data)
439  if (empty(self::$st_data)) {
440  $this->setData($this->getNewsData());
441  }
442 
443  $news_set = new ilSetting("news");
444  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
445 
446 
447  $tpl = new ilTemplate("tpl.show_news.html", true, true, "Services/News");
448 
449  // get current item in data set
450  $previous = "";
451  reset($this->data);
452  $c = current($this->data);
453  $curr_cnt = 1;
454 
455  if ($this->std_request->getNewsId() > 0) {
456  $news = new ilNewsItem($this->std_request->getNewsId());
457  $news_context = $this->std_request->getNewsContext();
458  while ($c["id"] > 0 && (int) $c["id"] !== $this->std_request->getNewsId()) {
459  $previous = $c;
460  $c = next($this->data);
461  $curr_cnt++;
462  }
463  } else {
464  $news_page = $this->std_request->getNewsPage();
465  $news_context = 0;
466  while ($curr_cnt - 1 < $news_page) {
467  $previous = $c;
468  $c = next($this->data);
469  if ($curr_cnt - 1 === $news_page) {
470  }
471  $curr_cnt++;
472  }
473  $news = new ilNewsItem($c["id"] ?? 0);
474  if (($c["ref_id"] ?? 0) > 0) {
475  $news_context = (int) $c["ref_id"];
476  }
477  }
478 
479 
480  if (!is_array($c) && is_object($news) && $news->getId() > 0
481  && ilNewsItem::_lookupContextObjId($news->getId()) !== $ilCtrl->getContextObjId()) {
482  throw new ilException("News ID does not match object context.");
483  }
484 
485 
486  // collect news items to show
487  $news_list = [];
488  if (isset($c["aggregation"]) && is_array($c["aggregation"])) { // we have an aggregation
489  $news_list[] = [
490  "ref_id" => $c["agg_ref_id"],
491  "agg_ref_id" => $c["agg_ref_id"],
492  "aggregation" => $c["aggregation"],
493  "user_id" => "",
494  "content_type" => "text",
495  "mob_id" => 0,
496  "visibility" => "",
497  "content" => "",
498  "content_long" => "",
499  "update_date" => $news->getUpdateDate(),
500  "creation_date" => "",
501  "content_is_lang_var" => false,
502  "loc_context" => $news_context,
503  "context_obj_type" => $news->getContextObjType(),
504  "title" => ""
505  ];
506 
507  foreach ($c["aggregation"] as $c_item) {
508  ilNewsItem::_setRead($ilUser->getId(), $c_item["id"]);
509  $c_item["loc_context"] = $c_item["ref_id"];
510  $c_item["loc_stop"] = $news_context;
511  $news_list[] = $c_item;
512  }
513  } else { // no aggregation, simple news item
514  $news_list[] = [
515  "id" => $news->getId(),
516  "ref_id" => $news_context,
517  "user_id" => $news->getUserId(),
518  "content_type" => $news->getContentType(),
519  "mob_id" => $news->getMobId(),
520  "visibility" => $news->getVisibility(),
521  "priority" => $news->getPriority(),
522  "content" => $news->getContent(),
523  "content_long" => $news->getContentLong(),
524  "update_date" => $news->getUpdateDate(),
525  "creation_date" => $news->getCreationDate(),
526  "context_sub_obj_type" => $news->getContextSubObjType(),
527  "context_obj_type" => $news->getContextObjType(),
528  "context_sub_obj_id" => $news->getContextSubObjId(),
529  "content_is_lang_var" => $news->getContentIsLangVar(),
530  "content_text_is_lang_var" => $news->getContentTextIsLangVar(),
531  "loc_context" => $news_context,
532  "title" => $news->getTitle()
533  ];
534  ilNewsItem::_setRead($ilUser->getId(), $this->std_request->getNewsId());
535  }
536 
537  $row_css = "";
538  $cache_deleted = false;
539  foreach ($news_list as $item) {
540  $row_css = ($row_css !== "tblrow1")
541  ? "tblrow1"
542  : "tblrow2";
543 
544  if ($item["ref_id"] > 0 && !$ilAccess->checkAccess("read", "", $item["ref_id"])) {
545  $tpl->setCurrentBlock("content");
546  $tpl->setVariable("VAL_CONTENT", $lng->txt("news_sorry_not_accessible_anymore"));
548  $tpl->setCurrentBlock("item");
549  $tpl->setVariable("ITEM_ROW_CSS", $row_css);
551  if (!$cache_deleted) {
552  $this->acache->deleteEntry($ilUser->getId() . ":" . $this->std_request->getRefId());
553  $cache_deleted = true;
554  }
555  continue;
556  }
557 
558  // user
559  if ($item["user_id"] > 0 &&
560  \ilObjUser::userExists([$item["user_id"]])
561  ) {
562  // get login
563  if (ilObjUser::_exists($item["user_id"])) {
564  $user = new ilObjUser($item["user_id"]);
565  $displayname = $user->getLogin();
566  } else {
567  // this should actually not happen, since news entries
568  // should be deleted when the user is going to be removed
569  $displayname = "&lt;" . strtolower($lng->txt("deleted")) . "&gt;";
570  }
571 
572  $tpl->setCurrentBlock("user_info");
573  $tpl->setVariable("VAL_AUTHOR", $displayname);
574  $tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
576  }
577 
578  // media player
579  $ui_renderer = $this->ui->renderer();
580  $ui_factory = $this->ui->factory();
581 
582  if ($item["mob_id"] > 0 && ilObject::_exists((int) $item["mob_id"])) {
583  $media_path = $this->getMediaPath((int) $item["mob_id"]);
584  $mime = ilObjMediaObject::getMimeType($media_path);
585  if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
586  $title = basename($media_path);
587  $html = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
588  } elseif (in_array($mime, ["video/mp4", "video/youtube", "video/vimeo"])) {
589  $video = $ui_factory->player()->video($media_path);
590  $html = $ui_renderer->render($video);
591  } elseif (in_array($mime, ["audio/mpeg"])) {
592  $audio = $ui_factory->player()->audio($media_path);
593  $html = $ui_renderer->render($audio);
594  } elseif (in_array($mime, ["application/pdf"])) {
595  $this->ctrl->setParameter($this, "news_id", $item["id"]);
596  $link = $ui_factory->link()->standard(
597  basename($media_path),
598  $this->ctrl->getLinkTarget($this, "downloadMob")
599  );
600  $html = $ui_renderer->render($link);
601  $this->ctrl->setParameter($this, "news_id", null);
602  } else {
603  // download?
604  $html = $mime;
605  }
606 
607 
608  $tpl->setCurrentBlock("player");
609  $tpl->setVariable(
610  "PLAYER",
611  $html
612  );
614  }
615 
616  // access
617  if ($enable_internal_rss && $item["visibility"] != "") {
618  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
619  $tpl->setCurrentBlock("access");
620  $tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
621  if ($item["visibility"] === NEWS_PUBLIC ||
622  ((int) $item["priority"] === 0 &&
624  "news",
625  "public_notifications",
626  0,
627  $obj_id
628  ))) {
629  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
630  } else {
631  $tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
632  }
634  }
635 
636  // content
637  $renderer = ilNewsRendererFactory::getRenderer($item["context_obj_type"]);
638  if (trim($item["content"]) != "") { // content
639  $it = new ilNewsItem($item["id"]);
640  $renderer->setNewsItem($it, $item["ref_id"]);
641  $tpl->setCurrentBlock("content");
642  $tpl->setVariable("VAL_CONTENT", $renderer->getDetailContent());
644  }
645  if ($item["update_date"] != $item["creation_date"]) { // update date
646  $tpl->setCurrentBlock("ni_update");
647  $tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
648  $tpl->setVariable(
649  "VAL_LAST_UPDATE",
650  ilDatePresentation::formatDate(new ilDateTime($item["update_date"], IL_CAL_DATETIME))
651  );
653  }
654 
655  // creation date
656  if ($item["creation_date"] != "") {
657  $tpl->setCurrentBlock("ni_update");
658  $tpl->setVariable(
659  "VAL_CREATION_DATE",
660  ilDatePresentation::formatDate(new ilDateTime($item["creation_date"], IL_CAL_DATETIME))
661  );
662  $tpl->setVariable("TXT_CREATED", $lng->txt("created"));
664  }
665 
666 
667  // context / title
668  if ($news_context > 0) {
669  //$obj_id = ilObject::_lookupObjId($_GET["news_context"]);
670  $obj_id = ilObject::_lookupObjId($item["ref_id"]);
671  $obj_type = ilObject::_lookupType($obj_id);
672  $obj_title = ilObject::_lookupTitle($obj_id);
673 
674  // file hack, not nice
675  if ($obj_type === "file") {
676  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $item["ref_id"]);
677  $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "sendfile");
678  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->std_request->getRefId());
679 
680  $button = $this->gui->button(
681  $this->lng->txt("download"),
682  $url
683  );
684 
685  $tpl->setCurrentBlock("download");
686  $tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
688  }
689 
690  // forum hack, not nice
691  $add = "";
692  if ($obj_type === "frm" && ($item["context_sub_obj_type"] ?? "") === "pos"
693  && $item["context_sub_obj_id"] > 0) {
694  $pos = $item["context_sub_obj_id"];
696  if ($thread > 0) {
697  $add = "_" . $thread . "_" . $pos;
698  }
699  }
700 
701  // wiki hack, not nice
702  if ($obj_type === "wiki" && $item["context_sub_obj_type"] === "wpg"
703  && $item["context_sub_obj_id"] > 0) {
704  $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
705  if ($wptitle != "") {
706  $add = "_" . ilWikiUtil::makeUrlTitle($wptitle);
707  }
708  }
709 
710  $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
711  $obj_type . "_" . $item["ref_id"] . $add;
712 
713  // lm page hack, not nice
714  if (
715  ($item["context_sub_obj_type"] ?? "") === "pg" &&
716  $item["context_sub_obj_id"] > 0 &&
717  in_array($obj_type, ["lm"], true)) {
718  $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
719  "pg_" . $item["context_sub_obj_id"] . "_" . $item["ref_id"];
720  }
721 
722  // blog posting hack, not nice
723  if ($obj_type === "blog" && ($item["context_sub_obj_type"] ?? "") === "blp"
724  && $item["context_sub_obj_id"] > 0) {
725  $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
726  "blog_" . $item["ref_id"] . "_" . $item["context_sub_obj_id"];
727  }
728 
729  $context_opened = false;
730  $loc_stop = $item["loc_stop"] ?? "";
731  if ($item["loc_context"] != null &&
732  $item["loc_context"] != $loc_stop
733  ) {
734  $tpl->setCurrentBlock("context");
735  $context_opened = true;
736  $cont_loc = new ilLocatorGUI();
737  $cont_loc->addContextItems($item["loc_context"], true, (int) $loc_stop);
738  $tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
739  }
740 
741  //var_dump($item);
742  $no_context_title = $item["no_context_title"] ?? false;
743  if ($no_context_title !== true) {
744  if (!$context_opened) {
745  $tpl->setCurrentBlock("context");
746  }
747  $tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
748  $tpl->setVariable("CONTEXT_TITLE", $obj_title);
749  $tpl->setVariable("IMG_CONTEXT_TITLE", ilObject::_getIcon($obj_id, "big", $obj_type));
750  }
751  if ($context_opened) {
753  }
754 
755  $tpl->setVariable("HREF_TITLE", $url_target);
756  }
757 
758  // title
759  $tpl->setVariable(
760  "VAL_TITLE",
762  $item["context_obj_type"] ?? "",
763  $item["title"] ?? "",
764  $item["content_is_lang_var"] ?? false,
765  $item["agg_ref_id"] ?? 0,
766  $item["aggregation"] ?? []
767  )
768  );
769 
770 
771  $tpl->setCurrentBlock("item");
772  $tpl->setVariable("ITEM_ROW_CSS", $row_css);
774  }
775 
776  $content = $tpl->get();
777  if ($this->getProperty("title") != "") {
778  $title = $this->getProperty("title");
779  } else {
780  $title = $lng->txt("news_internal_news");
781  }
782  $panel = $this->ui->factory()->panel()->standard($title, $this->ui->factory()->legacy($content));
783 
784  $parameter_name = 'news_page';
785 
786  $pagination = $this->ui->factory()->viewControl()->pagination()
787  ->withTargetURL($ilCtrl->getLinkTarget($this, "showNews"), "news_page")
788  ->withTotalEntries(count($this->getData()))
789  ->withPageSize(1)
790  ->withMaxPaginationButtons(10)
791  ->withCurrentPage($curr_cnt - 1);
792  $panel = $panel->withViewControls([$pagination]);
793 
794  return $this->ui->renderer()->render($panel);
795  }
796 
797  protected function getMediaPath(int $mob_id): string
798  {
799  $media_path = "";
800  if ($mob_id > 0) {
801  $mob = new ilObjMediaObject($mob_id);
802  $med = $mob->getMediaItem("Standard");
803  if (strcasecmp("Reference", $med->getLocationType()) === 0) {
804  $media_path = $med->getLocation();
805  } else {
806  $media_path = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
807  }
808  }
809  return $media_path;
810  }
811 
812  public function makeClickable(string $a_str): string
813  {
814  // this fixes bug 8744. We assume that strings that contain < and >
815  // already contain html, we do not handle these
816  if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<"))) {
817  return $a_str;
818  }
819 
820  return ilUtil::makeClickable($a_str);
821  }
822 
823  public function showNotifications(): void
824  {
825  $ilCtrl = $this->ctrl;
826  $ilUser = $this->user;
827 
829  $this->getBlockType(),
830  "view",
831  "",
832  $ilUser->getId(),
833  (int) $this->block_id
834  );
835 
836  // reload data
837  $data = $this->getNewsData();
838  $this->setData($data);
839  $this->handleView();
840 
841  if ($ilCtrl->isAsynch()) {
842  $this->send($this->getHTML());
843  }
844 
845  $ilCtrl->returnToParent($this);
846  }
847 
848  public function hideNotifications(): void
849  {
850  $ilCtrl = $this->ctrl;
851  $ilUser = $this->user;
852 
854  $this->getBlockType(),
855  "view",
856  "hide_notifications",
857  $ilUser->getId(),
858  (int) $this->block_id
859  );
860 
861  // reload data
862  $data = $this->getNewsData();
863  $this->setData($data);
864  $this->handleView();
865 
866  if ($ilCtrl->isAsynch()) {
867  $this->send($this->getHTML());
868  }
869 
870  $ilCtrl->returnToParent($this);
871  }
872 
876  public function editSettings(): string
877  {
878  $this->initSettingsForm();
879  return $this->settings_form->getHTML();
880  }
881 
885  public function initSettingsForm(): void
886  {
887  $lng = $this->lng;
888  $ilCtrl = $this->ctrl;
889  $ilTabs = $this->tabs;
890 
891  $ilTabs->clearTargets();
892 
893  $news_set = new ilSetting("news");
894  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
895 
896  $public = ilBlockSetting::_lookup(
897  $this->getBlockType(),
898  "public_notifications",
899  0,
900  (int) $this->block_id
901  );
902  $public_feed = ilBlockSetting::_lookup(
903  $this->getBlockType(),
904  "public_feed",
905  0,
906  (int) $this->block_id
907  );
908  $hide_block = ilBlockSetting::_lookup(
909  $this->getBlockType(),
910  "hide_news_block",
911  0,
912  (int) $this->block_id
913  );
914  $hide_news_per_date = ilBlockSetting::_lookup(
915  $this->getBlockType(),
916  "hide_news_per_date",
917  0,
918  (int) $this->block_id
919  );
920  $hide_news_date = ilBlockSetting::_lookup(
921  $this->getBlockType(),
922  "hide_news_date",
923  0,
924  (int) $this->block_id
925  );
926 
927  if (is_string($hide_news_date) && $hide_news_date !== '') {
928  $hide_news_date = explode(" ", $hide_news_date);
929  }
930 
931  $this->settings_form = new ilPropertyFormGUI();
932  $this->settings_form->setTitle($lng->txt("news_settings"));
933 
934  // hide news block for learners
935  if ($this->getProperty("hide_news_block_option")) {
936  $ch = new ilCheckboxInputGUI(
937  $lng->txt("news_hide_news_block"),
938  "hide_news_block"
939  );
940  $ch->setInfo($lng->txt("news_hide_news_block_info"));
941  $ch->setChecked((bool) $hide_block);
942  $this->settings_form->addItem($ch);
943 
944  $hnpd = new ilCheckboxInputGUI(
945  $lng->txt("news_hide_news_per_date"),
946  "hide_news_per_date"
947  );
948  $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
949  $hnpd->setChecked((bool) $hide_news_per_date);
950 
951  $dt_prop = new ilDateTimeInputGUI(
952  $lng->txt("news_hide_news_date"),
953  "hide_news_date"
954  );
955  $dt_prop->setRequired(true);
956  if (is_array($hide_news_date) && count($hide_news_date) === 2) {
957  $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . $hide_news_date[1], IL_CAL_DATETIME));
958  }
959  $dt_prop->setShowTime(true);
960  $hnpd->addSubItem($dt_prop);
961 
962  $this->settings_form->addItem($hnpd);
963  }
964 
965  // default visibility
966  if ($enable_internal_rss && $this->getProperty("default_visibility_option")) {
967  $default_visibility = ilBlockSetting::_lookup(
968  $this->getBlockType(),
969  "default_visibility",
970  0,
971  (int) $this->block_id
972  );
973  if ($default_visibility == "") {
974  $default_visibility =
975  ilNewsItem::_getDefaultVisibilityForRefId($this->std_request->getRefId());
976  }
977 
978  // Default Visibility
979  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
980  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
981  $radio_group->addOption($radio_option);
982  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
983  $radio_group->addOption($radio_option);
984  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
985  $radio_group->setRequired(false);
986  $radio_group->setValue($default_visibility);
987  $this->settings_form->addItem($radio_group);
988  }
989 
990  // public notifications
991  if ($enable_internal_rss && $this->getProperty("public_notifications_option")) {
992  $ch = new ilCheckboxInputGUI(
993  $lng->txt("news_notifications_public"),
994  "notifications_public"
995  );
996  $ch->setInfo($lng->txt("news_notifications_public_info"));
997  $ch->setChecked((bool) $public);
998  $this->settings_form->addItem($ch);
999  }
1000 
1001  // extra rss feed
1002  if ($enable_internal_rss) {
1003  $ch = new ilCheckboxInputGUI(
1004  $lng->txt("news_public_feed"),
1005  "notifications_public_feed"
1006  );
1007  $ch->setInfo($lng->txt("news_public_feed_info"));
1008  $ch->setChecked((bool) $public_feed);
1009  $this->settings_form->addItem($ch);
1010  }
1011 
1012  $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
1013  $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
1014  $this->settings_form->setFormAction($ilCtrl->getFormAction($this));
1015  }
1016 
1020  public static function addToSettingsForm(ilFormPropertyGUI $a_input): void
1021  {
1022  global $DIC;
1023 
1024  $std_request = $DIC->news()
1025  ->internal()
1026  ->gui()
1027  ->standardRequest();
1028 
1029  $lng = $DIC->language();
1030  $block_id = $DIC->ctrl()->getContextObjId();
1031 
1032  $news_set = new ilSetting("news");
1033  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1034 
1035  $public_feed = ilBlockSetting::_lookup(
1036  self::$block_type,
1037  "public_feed",
1038  0,
1039  $block_id
1040  );
1041  $default_visibility = ilBlockSetting::_lookup(self::$block_type, "default_visibility", 0, $block_id);
1042  if ($default_visibility == "") {
1043  $default_visibility =
1045  }
1046  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
1047  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
1048  $radio_group->addOption($radio_option);
1049  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
1050  $radio_group->addOption($radio_option);
1051  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1052  $radio_group->setRequired(false);
1053  $radio_group->setValue($default_visibility);
1054  $a_input->addSubItem($radio_group);
1055 
1056  // extra rss feed
1057  if ($enable_internal_rss) {
1058  $radio_rss = new ilCheckboxInputGUI(
1059  $lng->txt("news_public_feed"),
1060  "notifications_public_feed"
1061  );
1062  $radio_rss->setInfo($lng->txt("news_public_feed_info"));
1063  $radio_rss->setChecked((bool) $public_feed);
1064  $a_input->addSubItem($radio_rss);
1065  }
1066  }
1067 
1068  public static function writeSettings(array $a_values): void
1069  {
1070  global $DIC;
1071 
1072  $block_id = $DIC->ctrl()->getContextObjId();
1073  foreach ($a_values as $key => $value) {
1074  ilBlockSetting::_write(self::$block_type, (string) $key, (string) $value, 0, $block_id);
1075  }
1076  }
1077 
1078  public function cancelSettings(): void
1079  {
1080  $ilCtrl = $this->ctrl;
1081 
1082  $ilCtrl->returnToParent($this);
1083  }
1084 
1085  public function saveSettings(): string
1086  {
1087  $ilCtrl = $this->ctrl;
1088  $ilUser = $this->user;
1089 
1090  $this->initSettingsForm();
1091  $form = $this->settings_form;
1092  if ($form->checkInput()) {
1093  $news_set = new ilSetting("news");
1094  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1095 
1096  if ($enable_internal_rss) {
1098  $this->getBlockType(),
1099  "public_notifications",
1100  $form->getInput("notifications_public"),
1101  0,
1102  (int) $this->block_id
1103  );
1105  $this->getBlockType(),
1106  "public_feed",
1107  $form->getInput("notifications_public_feed"),
1108  0,
1109  (int) $this->block_id
1110  );
1112  $this->getBlockType(),
1113  "default_visibility",
1114  $form->getInput("default_visibility"),
1115  0,
1116  (int) $this->block_id
1117  );
1118  }
1119 
1120  if ($this->getProperty("hide_news_block_option")) {
1122  $this->getBlockType(),
1123  "hide_news_block",
1124  $form->getInput("hide_news_block"),
1125  0,
1126  (int) $this->block_id
1127  );
1129  $this->getBlockType(),
1130  "hide_news_per_date",
1131  $form->getInput("hide_news_per_date"),
1132  0,
1133  (int) $this->block_id
1134  );
1135 
1136  // hide date
1137  $hd = $this->settings_form->getItemByPostVar("hide_news_date");
1138  $hide_date = $hd->getDate();
1139  if ($hide_date instanceof ilDateTime && $form->getInput("hide_news_per_date")) {
1141  $this->getBlockType(),
1142  "hide_news_date",
1143  $hide_date->get(IL_CAL_DATETIME),
1144  0,
1145  (int) $this->block_id
1146  );
1147  } else {
1149  $this->getBlockType(),
1150  "hide_news_date",
1151  "",
1152  0,
1153  (int) $this->block_id
1154  );
1155  }
1156  }
1157 
1158  $cache = new ilNewsCache();
1159  $cache->deleteEntry($ilUser->getId() . ":" . $this->std_request->getRefId());
1160 
1161  $ilCtrl->returnToParent($this);
1162  } else {
1163  $this->settings_form->setValuesByPost();
1164  return $this->settings_form->getHTML();
1165  }
1166  return "";
1167  }
1168 
1169  public function showFeedUrl(): string
1170  {
1171  $lng = $this->lng;
1172  $ilUser = $this->user;
1173 
1174  $title = ilObject::_lookupTitle((int) $this->block_id);
1175 
1176  $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
1177  $tpl->setVariable(
1178  "TXT_TITLE",
1179  sprintf($lng->txt("news_feed_url_for"), $title)
1180  );
1181  $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1182  $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1183  $tpl->setVariable(
1184  "VAL_FEED_URL",
1185  ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
1186  "&obj_id=" . $this->block_id .
1187  "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1188  );
1189  $tpl->setVariable(
1190  "VAL_FEED_URL_TXT",
1191  ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
1192  "&obj_id=" . $this->block_id .
1193  "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1194  );
1195 
1196  $panel = $this->ui->factory()->panel()->standard(
1197  $lng->txt("news_internal_news"),
1198  $this->ui->factory()->legacy($tpl->get())
1199  );
1200 
1201  return $this->ui->renderer()->render($panel);
1202  }
1203 
1204  public function getDynamicReload(): string
1205  {
1206  $ilCtrl = $this->ctrl;
1207  $lng = $this->lng;
1208 
1209  $ilCtrl->setParameterByClass(
1210  "ilcolumngui",
1211  "block_id",
1212  "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1213  );
1214 
1215  $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/News");
1216  $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1217  $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1218  $rel_tpl->setVariable(
1219  "TARGET",
1220  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
1221  );
1222 
1223  // no JS
1224  $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1225  $rel_tpl->setVariable(
1226  "TARGET_NO_JS",
1227  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "disableJS")
1228  );
1229 
1230  return $rel_tpl->get();
1231  }
1232 
1233  public function getJSEnabler(): string
1234  {
1235  $ilCtrl = $this->ctrl;
1236 
1237  $ilCtrl->setParameterByClass(
1238  "ilcolumngui",
1239  "block_id",
1240  "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1241  );
1242  //echo "hh";
1243  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/News");
1244  $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1245  $rel_tpl->setVariable(
1246  "TARGET",
1247  $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "enableJS", "", true, false)
1248  );
1249 
1250  return $rel_tpl->get();
1251  }
1252 
1253 
1254  public function disableJS(): void
1255  {
1256  $ilCtrl = $this->ctrl;
1257  $ilUser = $this->user;
1258 
1259  ilSession::set("il_feed_js", "n");
1260  $ilUser->writePref("il_feed_js", "n");
1261  $ilCtrl->returnToParent($this);
1262  }
1263 
1264  public function enableJS(): void
1265  {
1266  $ilUser = $this->user;
1267  ilSession::set("il_feed_js", "y");
1268  $ilUser->writePref("il_feed_js", "y");
1269  $this->send($this->getHTML());
1270  }
1271 
1272  protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
1273  {
1274  if ((int) ($data["id"] ?? 0) === 0) {
1275  return null;
1276  }
1277  $info = $this->getInfoForData($data);
1278 
1279  $props = [
1280  $this->lng->txt("date") => $info["creation_date"] ?? ""
1281  ];
1282 
1283  $factory = $this->ui->factory();
1284  $item = $factory->item()->standard($factory->link()->standard($info["news_title"] ?? "", $info["url"] ?? ""))
1285  ->withProperties($props);
1286  if (($info["ref_id"] ?? 0) > 0) {
1287  $item = $item->withDescription($info["type_txt"] . ": " . $info["obj_title"]);
1288  }
1289  return $item;
1290  }
1291 
1292  public function getNoItemFoundContent(): string
1293  {
1294  return $this->lng->txt("news_no_news_items");
1295  }
1296 
1297  protected function downloadMob(): void
1298  {
1299  $news_id = $this->std_request->getNewsId();
1300  $news = new ilNewsItem($news_id);
1301  $news->deliverMobFile("Standard", true);
1302  }
1303 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilObjUser $user
static _getDefaultVisibilityForRefId(int $a_ref_id)
Get default visibility for reference id.
const IL_CAL_DATETIME
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
ilObjectDefinition $obj_def
get(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
ilLanguage $lng
handleView()
Handles show/hide notification view and removes notifications if hidden.
setLimit(int $a_limit)
setBlockId(string $a_block_id="0")
send(string $output)
Send.
Class ChatMainBarProvider .
setInfo(string $a_info)
setEnableNumInfo(bool $a_enablenuminfo)
Factory $factory
Help GUI class.
static lookupTitle(int $a_page_id, string $lang="-")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for NewsItem entities.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
ILIAS News InternalGUIService $gui
setParameterByClass(string $a_class, string $a_parameter, $a_value)
loadLanguageModule(string $a_module)
Load language module.
BlockGUI class for block NewsForContext.
returnToParent(object $a_gui_obj, string $a_anchor=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a date/time property in a property form.
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRenderer(string $a_context_obj_type)
global $DIC
Definition: feed.php:28
setRowTemplate(string $a_rowtemplatename, string $a_rowtemplatedir="")
Set Row Template Name.
parses the objects.xml it handles the xml-description of all ilias objects
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
getNextClass($a_gui_class=null)
$ref_id
Definition: ltiauth.php:67
const IL_SCREEN_FULL
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:546
static userExists(array $a_usr_ids=[])
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 getMimeType(string $a_file, bool $a_external=false)
get mime type for file
ilTemplate $tpl
static _lookupTitle(int $obj_id)
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.
const CLIENT_ID
Definition: constants.php:41
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
string $key
Consumer key/client ID value.
Definition: System.php:193
getClassName(string $obj_name)
static _lookupObjectId(int $ref_id)
$url
Definition: ltiregstart.php:35
addBlockCommand(string $a_href, string $a_text, string $a_onclick="", RoundTrip $modal=null)
const IL_SCREEN_CENTER
clearTargets()
clear all targets
setRequired(bool $a_required)
static lookupTxtById(string $plugin_id, string $lang_var)
static _getThreadForPosting(int $a_pos_id)
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static makeUrlTitle(string $a_par)
A news item can be created by different sources.
static _lookupFeedHash(int $a_user_id, bool $a_create=false)
Lookup news feed hash for user.
setTitle(string $a_title)
static addToSettingsForm(ilFormPropertyGUI $a_input)
Add inputs to the container news settings form to configure also the contextBlock options...
static prepareNewsDataFromCache(array $a_cres)
Prepare news data from cache.
This class represents a block method of a block.
static _getURL(int $a_mob_id)
get directory for files of media object
static _setRead(int $a_user_id, int $a_news_id)
Set item read.
isPlugin(string $obj_name)
get RBAC status by type returns true if object type is an (activated) plugin type ...
setData(array $a_data)
ilAccessHandler $access
ILIAS UI Renderer $renderer
static _lookupType(int $id, bool $reference=false)
const IL_SCREEN_SIDE
static makeClickable(string $a_text, bool $detectGotoLinks=false)
static _lookupContextObjId(int $a_news_id)
Context Object ID.
getProperty(string $a_property)
static set(string $a_var, $a_val)
Set a value.
setPresentation(int $type)
static shortenWords(string $a_str, int $a_len=30, bool $a_dots=true)
Ensure that the maximum word lenght within a text is not longer than $a_len.
const OBJECTS_WITH_NEWS_SUBTAB
object type names with settings->news settings subtab