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