ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 (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;
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;
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 {
427
428 return '<div class="small">' . (count($this->getData())) . " " . $lng->txt("news_news_items") . "</div>";
429 }
430
431 public function showNews(): string
432 {
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, "components/ILIAS/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");
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"));
649 "VAL_LAST_UPDATE",
651 );
653 }
654
655 // creation date
656 if ($item["creation_date"] != "") {
657 $tpl->setCurrentBlock("ni_update");
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
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($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 $media_path = $mob->getStandardSrc();
803 }
804 return $media_path;
805 }
806
807 public function makeClickable(string $a_str): string
808 {
809 // this fixes bug 8744. We assume that strings that contain < and >
810 // already contain html, we do not handle these
811 if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<"))) {
812 return $a_str;
813 }
814
815 return ilUtil::makeClickable($a_str);
816 }
817
818 public function showNotifications(): void
819 {
820 $ilCtrl = $this->ctrl;
821 $ilUser = $this->user;
822
824 $this->getBlockType(),
825 "view",
826 "",
827 $ilUser->getId(),
828 (int) $this->block_id
829 );
830
831 // reload data
832 $data = $this->getNewsData();
833 $this->setData($data);
834 $this->handleView();
835
836 if ($ilCtrl->isAsynch()) {
837 $this->send($this->getHTML());
838 }
839
840 $ilCtrl->returnToParent($this);
841 }
842
843 public function hideNotifications(): void
844 {
845 $ilCtrl = $this->ctrl;
846 $ilUser = $this->user;
847
849 $this->getBlockType(),
850 "view",
851 "hide_notifications",
852 $ilUser->getId(),
853 (int) $this->block_id
854 );
855
856 // reload data
857 $data = $this->getNewsData();
858 $this->setData($data);
859 $this->handleView();
860
861 if ($ilCtrl->isAsynch()) {
862 $this->send($this->getHTML());
863 }
864
865 $ilCtrl->returnToParent($this);
866 }
867
871 public function editSettings(): string
872 {
873 $this->initSettingsForm();
874 return $this->settings_form->getHTML();
875 }
876
880 public function initSettingsForm(): void
881 {
883 $ilCtrl = $this->ctrl;
884 $ilTabs = $this->tabs;
885
886 $ilTabs->clearTargets();
887
888 $news_set = new ilSetting("news");
889 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
890
891 $public = ilBlockSetting::_lookup(
892 $this->getBlockType(),
893 "public_notifications",
894 0,
895 (int) $this->block_id
896 );
897 $public_feed = ilBlockSetting::_lookup(
898 $this->getBlockType(),
899 "public_feed",
900 0,
901 (int) $this->block_id
902 );
903 $hide_block = ilBlockSetting::_lookup(
904 $this->getBlockType(),
905 "hide_news_block",
906 0,
907 (int) $this->block_id
908 );
909 $hide_news_per_date = ilBlockSetting::_lookup(
910 $this->getBlockType(),
911 "hide_news_per_date",
912 0,
913 (int) $this->block_id
914 );
915 $hide_news_date = ilBlockSetting::_lookup(
916 $this->getBlockType(),
917 "hide_news_date",
918 0,
919 (int) $this->block_id
920 );
921
922 if (is_string($hide_news_date) && $hide_news_date !== '') {
923 $hide_news_date = explode(" ", $hide_news_date);
924 }
925
926 $this->settings_form = new ilPropertyFormGUI();
927 $this->settings_form->setTitle($lng->txt("news_settings"));
928
929 // hide news block for learners
930 if ($this->getProperty("hide_news_block_option")) {
931 $ch = new ilCheckboxInputGUI(
932 $lng->txt("news_hide_news_block"),
933 "hide_news_block"
934 );
935 $ch->setInfo($lng->txt("news_hide_news_block_info"));
936 $ch->setChecked((bool) $hide_block);
937 $this->settings_form->addItem($ch);
938
939 $hnpd = new ilCheckboxInputGUI(
940 $lng->txt("news_hide_news_per_date"),
941 "hide_news_per_date"
942 );
943 $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
944 $hnpd->setChecked((bool) $hide_news_per_date);
945
946 $dt_prop = new ilDateTimeInputGUI(
947 $lng->txt("news_hide_news_date"),
948 "hide_news_date"
949 );
950 $dt_prop->setRequired(true);
951 if (is_array($hide_news_date) && count($hide_news_date) === 2) {
952 $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . $hide_news_date[1], IL_CAL_DATETIME));
953 }
954 $dt_prop->setShowTime(true);
955 $hnpd->addSubItem($dt_prop);
956
957 $this->settings_form->addItem($hnpd);
958 }
959
960 // default visibility
961 if ($enable_internal_rss && $this->getProperty("default_visibility_option")) {
962 $default_visibility = ilBlockSetting::_lookup(
963 $this->getBlockType(),
964 "default_visibility",
965 0,
966 (int) $this->block_id
967 );
968 if ($default_visibility == "") {
969 $default_visibility =
970 ilNewsItem::_getDefaultVisibilityForRefId($this->std_request->getRefId());
971 }
972
973 // Default Visibility
974 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
975 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
976 $radio_group->addOption($radio_option);
977 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
978 $radio_group->addOption($radio_option);
979 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
980 $radio_group->setRequired(false);
981 $radio_group->setValue($default_visibility);
982 $this->settings_form->addItem($radio_group);
983 }
984
985 // public notifications
986 if ($enable_internal_rss && $this->getProperty("public_notifications_option")) {
987 $ch = new ilCheckboxInputGUI(
988 $lng->txt("news_notifications_public"),
989 "notifications_public"
990 );
991 $ch->setInfo($lng->txt("news_notifications_public_info"));
992 $ch->setChecked((bool) $public);
993 $this->settings_form->addItem($ch);
994 }
995
996 // extra rss feed
997 if ($enable_internal_rss) {
998 $ch = new ilCheckboxInputGUI(
999 $lng->txt("news_public_feed"),
1000 "notifications_public_feed"
1001 );
1002 $ch->setInfo($lng->txt("news_public_feed_info"));
1003 $ch->setChecked((bool) $public_feed);
1004 $this->settings_form->addItem($ch);
1005 }
1006
1007 $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
1008 $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
1009 $this->settings_form->setFormAction($ilCtrl->getFormAction($this));
1010 }
1011
1015 public static function addToSettingsForm(ilFormPropertyGUI $a_input): void
1016 {
1017 global $DIC;
1018
1019 $std_request = $DIC->news()
1020 ->internal()
1021 ->gui()
1022 ->standardRequest();
1023
1024 $lng = $DIC->language();
1025 $block_id = $DIC->ctrl()->getContextObjId();
1026
1027 $news_set = new ilSetting("news");
1028 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1029
1030 $public_feed = ilBlockSetting::_lookup(
1031 self::$block_type,
1032 "public_feed",
1033 0,
1034 $block_id
1035 );
1036 $default_visibility = ilBlockSetting::_lookup(self::$block_type, "default_visibility", 0, $block_id);
1037 if ($default_visibility == "") {
1038 $default_visibility =
1040 }
1041 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
1042 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
1043 $radio_group->addOption($radio_option);
1044 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
1045 $radio_group->addOption($radio_option);
1046 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
1047 $radio_group->setRequired(false);
1048 $radio_group->setValue($default_visibility);
1049 $a_input->addSubItem($radio_group);
1050
1051 // extra rss feed
1052 if ($enable_internal_rss) {
1053 $radio_rss = new ilCheckboxInputGUI(
1054 $lng->txt("news_public_feed"),
1055 "notifications_public_feed"
1056 );
1057 $radio_rss->setInfo($lng->txt("news_public_feed_info"));
1058 $radio_rss->setChecked((bool) $public_feed);
1059 $a_input->addSubItem($radio_rss);
1060 }
1061 }
1062
1063 public static function writeSettings(array $a_values): void
1064 {
1065 global $DIC;
1066
1067 $block_id = $DIC->ctrl()->getContextObjId();
1068 foreach ($a_values as $key => $value) {
1069 ilBlockSetting::_write(self::$block_type, (string) $key, (string) $value, 0, $block_id);
1070 }
1071 }
1072
1073 public function cancelSettings(): void
1074 {
1075 $ilCtrl = $this->ctrl;
1076
1077 $ilCtrl->returnToParent($this);
1078 }
1079
1080 public function saveSettings(): string
1081 {
1082 $ilCtrl = $this->ctrl;
1083 $ilUser = $this->user;
1084
1085 $this->initSettingsForm();
1086 $form = $this->settings_form;
1087 if ($form->checkInput()) {
1088 $news_set = new ilSetting("news");
1089 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1090
1091 if ($enable_internal_rss) {
1093 $this->getBlockType(),
1094 "public_notifications",
1095 $form->getInput("notifications_public"),
1096 0,
1097 (int) $this->block_id
1098 );
1100 $this->getBlockType(),
1101 "public_feed",
1102 $form->getInput("notifications_public_feed"),
1103 0,
1104 (int) $this->block_id
1105 );
1107 $this->getBlockType(),
1108 "default_visibility",
1109 $form->getInput("default_visibility"),
1110 0,
1111 (int) $this->block_id
1112 );
1113 }
1114
1115 if ($this->getProperty("hide_news_block_option")) {
1117 $this->getBlockType(),
1118 "hide_news_block",
1119 $form->getInput("hide_news_block"),
1120 0,
1121 (int) $this->block_id
1122 );
1124 $this->getBlockType(),
1125 "hide_news_per_date",
1126 $form->getInput("hide_news_per_date"),
1127 0,
1128 (int) $this->block_id
1129 );
1130
1131 // hide date
1132 $hd = $this->settings_form->getItemByPostVar("hide_news_date");
1133 $hide_date = $hd->getDate();
1134 if ($hide_date instanceof ilDateTime && $form->getInput("hide_news_per_date")) {
1136 $this->getBlockType(),
1137 "hide_news_date",
1138 $hide_date->get(IL_CAL_DATETIME),
1139 0,
1140 (int) $this->block_id
1141 );
1142 } else {
1144 $this->getBlockType(),
1145 "hide_news_date",
1146 "",
1147 0,
1148 (int) $this->block_id
1149 );
1150 }
1151 }
1152
1153 $cache = new ilNewsCache();
1154 $cache->deleteEntry($ilUser->getId() . ":" . $this->std_request->getRefId());
1155
1156 $ilCtrl->returnToParent($this);
1157 } else {
1158 $this->settings_form->setValuesByPost();
1159 return $this->settings_form->getHTML();
1160 }
1161 return "";
1162 }
1163
1164 public function showFeedUrl(): string
1165 {
1166 $lng = $this->lng;
1167 $ilUser = $this->user;
1168
1169 $title = ilObject::_lookupTitle((int) $this->block_id);
1170
1171 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "components/ILIAS/News");
1173 "TXT_TITLE",
1174 sprintf($lng->txt("news_feed_url_for"), $title)
1175 );
1176 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1177 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1179 "VAL_FEED_URL",
1180 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
1181 "&obj_id=" . $this->block_id .
1182 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1183 );
1185 "VAL_FEED_URL_TXT",
1186 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
1187 "&obj_id=" . $this->block_id .
1188 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1189 );
1190
1191 $panel = $this->ui->factory()->panel()->standard(
1192 $lng->txt("news_internal_news"),
1193 $this->ui->factory()->legacy()->content($tpl->get())
1194 );
1195
1196 return $this->ui->renderer()->render($panel);
1197 }
1198
1199 public function getDynamicReload(): string
1200 {
1201 $ilCtrl = $this->ctrl;
1202 $lng = $this->lng;
1203
1204 $ilCtrl->setParameterByClass(
1205 "ilcolumngui",
1206 "block_id",
1207 "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1208 );
1209
1210 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "components/ILIAS/News");
1211 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1212 $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1213 $rel_tpl->setVariable(
1214 "TARGET",
1215 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
1216 );
1217
1218 // no JS
1219 $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1220 $rel_tpl->setVariable(
1221 "TARGET_NO_JS",
1222 $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "disableJS")
1223 );
1224
1225 return $rel_tpl->get();
1226 }
1227
1228 public function getJSEnabler(): string
1229 {
1230 $ilCtrl = $this->ctrl;
1231
1232 $ilCtrl->setParameterByClass(
1233 "ilcolumngui",
1234 "block_id",
1235 "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1236 );
1237 //echo "hh";
1238 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "components/ILIAS/News");
1239 $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1240 $rel_tpl->setVariable(
1241 "TARGET",
1242 $ilCtrl->getLinkTargetByClass(strtolower(get_class($this)), "enableJS", "", true, false)
1243 );
1244
1245 return $rel_tpl->get();
1246 }
1247
1248
1249 public function disableJS(): void
1250 {
1251 $ilCtrl = $this->ctrl;
1252 $ilUser = $this->user;
1253
1254 ilSession::set("il_feed_js", "n");
1255 $ilUser->writePref("il_feed_js", "n");
1256 $ilCtrl->returnToParent($this);
1257 }
1258
1259 public function enableJS(): void
1260 {
1261 $ilUser = $this->user;
1262 ilSession::set("il_feed_js", "y");
1263 $ilUser->writePref("il_feed_js", "y");
1264 $this->send($this->getHTML());
1265 }
1266
1267 protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
1268 {
1269 if ((int) ($data["id"] ?? 0) === 0) {
1270 return null;
1271 }
1272 $info = $this->getInfoForData($data);
1273
1274 $props = [
1275 $this->lng->txt("date") => $info["creation_date"] ?? ""
1276 ];
1277
1278 $factory = $this->ui->factory();
1279 $item = $factory->item()->standard($factory->link()->standard($info["news_title"] ?? "", $info["url"] ?? ""))
1280 ->withProperties($props);
1281 if (($info["ref_id"] ?? 0) > 0) {
1282 $item = $item->withDescription($info["type_txt"] . ": " . $info["obj_title"]);
1283 }
1284 return $item;
1285 }
1286
1287 public function getNoItemFoundContent(): string
1288 {
1289 return $this->lng->txt("news_no_news_items");
1290 }
1291
1292 protected function downloadMob(): void
1293 {
1294 $news_id = $this->std_request->getNewsId();
1295 $news = new ilNewsItem($news_id);
1296 $news->deliverMobFile("Standard", true);
1297 }
1298}
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.
getNextClass($a_gui_class=null)
@inheritDoc
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