ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilNewsForContextBlockGUI.php
Go to the documentation of this file.
1<?php
2
26
35{
39 public const OBJECTS_WITH_NEWS_SUBTAB = ["category", "course", "group", "forum"];
40 public static string $block_type = "news";
42 protected bool $dynamic = false;
43 protected bool $show_view_selection;
44
48 protected string $view;
50 protected ilHelpGUI $help;
52 protected ilTabsGUI $tabs;
53
57
58 protected bool $prevent_initial_loading = false;
60
61 public function __construct()
62 {
63 global $DIC;
64
66
67 $this->help = $DIC["ilHelp"];
68 $this->settings = $DIC->settings();
69 $this->tabs = $DIC->tabs();
70
71 $locator = $DIC->news()->internal();
72 $this->std_request = $locator->gui()->standardRequest();
73 $this->domain = $locator->domain();
74 $this->gui = $locator->gui();
75 $this->news_access = new NewsAccess($this->std_request->getRefId());
76
77 $this->lng->loadLanguageModule("news");
78 $DIC->help()->addHelpSection("news_block");
79
80 $this->setBlockId((string) $this->ctrl->getContextObjId());
81 $this->setLimit(5);
82 $this->setEnableNumInfo(true);
83
84 if (!$this->prevent_initial_loading) {
85 $this->loadNewsData();
86 }
87
88 $this->setTitle($this->lng->txt("news_internal_news"));
89 $this->setRowTemplate("tpl.block_row_news_for_context.html", "components/ILIAS/News");
90 $this->allow_moving = false;
91 $this->handleView();
92
93 $this->setPresentation(self::PRES_SEC_LIST);
94 }
95
96 private function loadNewsData(): void
97 {
98 if ($this->std_request->getRefId() === 0) {
99 $this->initData(new NewsCollection());
100 return;
101 }
102
103 $collection = $this->domain->collection()->getNewsForContainer(
104 $this->std_request->getRefId(),
105 $this->ctrl->getContextObjId(),
106 $this->ctrl->getContextObjType(),
107 new NewsCriteria(read_user_id: $this->user->getId()),
108 $this->user->getId(),
109 true
110 );
111
112 if ($this->ctrl->getContextObjType() !== 'frm') {
113 $collection = $collection->groupForums(true);
114 }
115 $this->initData($collection->groupFiles());
116 }
117
118 protected function initData(NewsCollection $collection): void
119 {
120 $this->collection = $collection;
121 $this->data = $collection->pluck('id', true);
122 }
123
127 protected function preloadData(array $data): void
128 {
129 parent::preloadData($data);
130 $this->collection->load(array_column($data, 0));
131 }
132
133 protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
134 {
135 try {
136 $info = $this->getNewsForId($data[0]);
137 } catch (\Exception $e) {
138 $this->logger->error($e->getMessage());
139 return $this->ui->factory()->item()->standard($this->lng->txt('news_not_available'))
140 ->withDescription($this->lng->txt('news_sorry_not_accessible_anymore'));
141 }
142
143
144 $props = [
145 $this->lng->txt('date') => $info['creation_date'] ?? ''
146 ];
147
148 $item = $this->ui->factory()->item()->standard(
149 $this->ui->factory()->link()->standard($info['news_title'] ?? '', $info['url'] ?? '')
150 )->withProperties($props);
151
152 if ($info['ref_id'] > 0) {
153 $item = $item->withDescription($info['type_txt'] . ': ' . $info['obj_title']);
154 }
155 return $item;
156 }
157
158 private function getNewsForId(int $news_id): array
159 {
160 $item = $this->collection->getById($news_id);
161 if ($item === null) {
162 throw new \InvalidArgumentException("News item with id {$news_id} not found.");
163 }
164
165 $grouping = $this->collection->getGroupingFor($item);
166
167 $creation_date = new ilDateTime($item->getCreationDate()->format('c'), IL_CAL_DATETIME);
170 $item->getContextObjType(),
171 $item->getTitle(),
172 $item->isContentIsLangVar(),
173 $grouping ? $grouping['agg_ref_id'] : 0,
174 $grouping ? $grouping['aggregation'] : [],
175 )
176 );
177
178 $info = [
179 'ref_id' => $item->getContextRefId(),
180 'creation_date' => ilDatePresentation::formatDate($creation_date),
181 'news_title' => $title,
182 ];
183
184 // title image type
185 if ($item->getContextRefId() > 0) {
186 $obj_id = $item->getContextObjId();
187 $type = $item->getContextObjType();
188
189 $lang_type = in_array($type, ['sahs', 'lm', 'htlm']) ? 'lres' : 'obj_' . $type;
190
191 $type_txt = ($this->obj_def->isPlugin($item->getContextObjType()))
192 ? ilObjectPlugin::lookupTxtById($item->getContextObjType(), $lang_type)
193 : $this->lng->txt($lang_type);
194
195 $info['type_txt'] = $type_txt;
196 $info['type_icon'] = ilObject::_getIcon($obj_id, 'tiny', $type);
197 $info['obj_title'] = ilStr::shortenWords(ilObject::_lookupTitle($obj_id));
198 $info['user_read'] = $this->collection->isReadByUser($this->user->getId(), $news_id);
199
200 $this->ctrl->setParameter($this, 'news_context', $item->getContextRefId());
201 } else {
202 $this->ctrl->setParameter($this, 'news_context', '');
203 }
204
205 $this->ctrl->setParameter($this, 'news_id', $item->getId());
206 $info['url'] = $this->ctrl->getLinkTarget($this, 'showNews');
207 $this->ctrl->clearParameters($this);
208
209 return $info;
210 }
211
212
213 public function getBlockType(): string
214 {
215 return self::$block_type;
216 }
217
218 protected function isRepositoryObject(): bool
219 {
220 return false;
221 }
222
223 public static function getScreenMode(): string
224 {
225 global $DIC;
226
227 $ilCtrl = $DIC->ctrl();
228
229 if (strcasecmp($ilCtrl->getCmdClass(), ilNewsItemGUI::class) === 0) {
230 return IL_SCREEN_FULL;
231 }
232
233 switch ($ilCtrl->getCmd()) {
234 case "showNews":
235 case "showFeedUrl":
236 return IL_SCREEN_CENTER;
237
238 case "editSettings":
239 case "saveSettings":
240 return IL_SCREEN_FULL;
241
242 default:
243 return IL_SCREEN_SIDE;
244 }
245 }
246
247 public function executeCommand()
248 {
249 if (strcasecmp($this->ctrl->getNextClass(), ilNewsItemGUI::class) === 0) {
250 $news_item_gui = new ilNewsItemGUI();
251 $news_item_gui->setEnableEdit($this->getEnableEdit());
252 return $this->ctrl->forwardCommand($news_item_gui);
253 }
254
255 $cmd = $this->ctrl->getCmd("getHTML");
256 return $this->$cmd();
257 }
258
259 public function getHTML(): string
260 {
261 global $DIC;
262
263 $ilCtrl = $this->ctrl;
265 $ilUser = $this->user;
266
267 $news_set = new ilSetting("news");
268 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
269
270 $hide_block = ilBlockSetting::_lookup(
271 $this->getBlockType(),
272 "hide_news_block",
273 0,
274 (int) $this->block_id
275 );
276
277 if ($this->getProperty("title") != "") {
278 $this->setTitle($this->getProperty("title"));
279 }
280
281 $public_feed = ilBlockSetting::_lookup(
282 $this->getBlockType(),
283 "public_feed",
284 0,
285 (int) $this->block_id
286 );
287 if ($public_feed && $enable_internal_rss) {
288 // @todo: rss icon HTML: ilRSSButtonGUI::get(ilRSSButtonGUI::ICON_RSS)
289 $this->addBlockCommand(
290 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&" .
291 "ref_id=" . $this->std_request->getRefId(),
292 $lng->txt("news_feed_url")
293 );
294 }
295
296 // add edit commands
297 if ($this->news_access->canAdd()) {
298 $this->addBlockCommand(
299 $ilCtrl->getLinkTargetByClass(ilNewsItemGUI::class, "editNews"),
300 $lng->txt("edit")
301 );
302
303 $ilCtrl->setParameter($this, "add_mode", "block");
304 $this->addBlockCommand(
305 $ilCtrl->getLinkTargetByClass(ilNewsItemGUI::class, "createNewsItem"),
306 $lng->txt("add")
307 );
308 $ilCtrl->setParameter($this, "add_mode", "");
309 }
310
311 if ($this->getProperty("settings")) {
312 $ref_id = $this->std_request->getRefId();
313 $obj_def = $DIC["objDefinition"];
315 $obj_type = ilObject::_lookupType($ref_id, true);
316 $obj_class = strtolower($obj_def->getClassName($obj_type));
317 $parent_gui = "ilobj" . $obj_class . "gui";
318
319 $ilCtrl->setParameterByClass(ilContainerNewsSettingsGUI::class, "ref_id", $ref_id);
320
321 if (in_array($obj_class, self::OBJECTS_WITH_NEWS_SUBTAB)) {
322 $this->addBlockCommand(
323 $ilCtrl->getLinkTargetByClass([ilRepositoryGUI::class, $parent_gui, ilContainerNewsSettingsGUI::class], "show"),
324 $lng->txt("settings")
325 );
326 } else {
327 // not sure if this code is still used anywhere, see discussion at
328 // https://mantis.ilias.de/view.php?id=31801
329 // If ILIAS 8 beta phase does not throw this exception, we can remove this part.
330 //throw new ilException("News settings are deprecated.");
331 // the info screen will call this
332 $this->addBlockCommand(
333 $ilCtrl->getLinkTarget($this, "editSettings"),
334 $lng->txt("settings")
335 );
336 }
337 }
338
339 // do not display hidden repository news blocks for users
340 // who do not have write permission
341 if (!$this->getEnableEdit() && $this->getRepositoryMode() &&
343 $this->getBlockType(),
344 "hide_news_block",
345 0,
346 (int) $this->block_id
347 )) {
348 return "";
349 }
350
351 // do not display empty news blocks for users
352 // who do not have write permission
353 if (!$this->dynamic && !$this->getEnableEdit() && $this->getRepositoryMode() && count($this->getData()) === 0 &&
354 (
355 !$news_set->get("enable_rss_for_internal") ||
357 $this->getBlockType(),
358 "public_feed",
359 0,
360 (int) $this->block_id
361 )
362 )) {
363 return "";
364 }
365
366 $en = "";
367
368 return parent::getHTML() . $en;
369 }
370
374 public function handleView(): void
375 {
376 // it seems like this method does not change any state, so it may be removed in the future
377
378 /*$ilUser = $this->user;
379
380 $this->view = (string) ilBlockSetting::_lookup(
381 $this->getBlockType(),
382 "view",
383 $ilUser->getId(),
384 (int) $this->block_id
385 );
386
387 // check whether notices and messages exist
388 $got_notices = $got_messages = false;
389 foreach ($this->data as $row) {
390 if ((int) ($row["priority"] ?? 0) === 0) {
391 $got_notices = true;
392 }
393 if ((int) ($row["priority"] ?? 0) === 1) {
394 $got_messages = true;
395 }
396 }
397 $this->show_view_selection = false;
398
399 if ($got_notices && $got_messages) {
400 $this->show_view_selection = true;
401 } elseif ($got_notices) {
402 $this->view = "";
403 }*/
404 }
405
406 public function getOverview(): string
407 {
409
410 return '<div class="small">' . (count($this->getData())) . " " . $lng->txt("news_news_items") . "</div>";
411 }
412
413 public function showNews(): string
414 {
415 $ui_renderer = $this->ui->renderer();
416 $ui_factory = $this->ui->factory();
417
418 $tpl = new ilTemplate("tpl.show_news.html", true, true, "components/ILIAS/News");
419 $setting = new ilSetting("news");
420 $enable_internal_rss = $setting->get("enable_rss_for_internal");
421
422 if ($this->std_request->getNewsId() > 0) {
423 $current_item = $this->collection->getById($this->std_request->getNewsId());
424 $news_context = (int) $this->std_request->getNewsContext();
425 } else {
426 $current_item = $this->collection->pick($this->std_request->getNewsPage());
427 $news_context = $current_item->getContextRefId();
428 }
429
430 if ($current_item === null) {
431 return '';
432 }
433
434 if ($grouping = $this->collection->getGroupingFor($current_item)) {
435 $news_list = $grouping['aggregation'];
436 } else {
437 $news_list = [$current_item];
438 }
439
440 for ($i = 0; $i < count($news_list); $i++) {
442 $item = $news_list[$i];
443 $item = $item->withContextRefId($news_context);
444
445 ilNewsItem::_setRead($this->user->getId(), $this->std_request->getNewsId());
446
447 $is_grouped_item = $i > 0;
448 $legacy_news = $item->toLegacy();
449
450 // author
451 if (\ilObjUser::userExists([$item->getUserId()])) {
452 $user = new ilObjUser($item->getUserId());
453 $display_name = $user->getLogin();
454 } else {
455 // this should actually not happen, since news entries
456 // should be deleted when the user is going to be removed
457 $display_name = "&lt;" . strtolower($this->lng->txt("deleted")) . "&gt;";
458 }
459 $tpl->setCurrentBlock("user_info");
460 $tpl->setVariable("VAL_AUTHOR", $display_name);
461 $tpl->setVariable("TXT_AUTHOR", $this->lng->txt("author"));
463
464 // media player
465 if ($item->getMobId() > 0 && ilObject::_exists($item->getMobId())) {
466 $media_path = $this->getMediaPath($item->getMobId());
467 $mime = ilObjMediaObject::getMimeType($media_path);
468 if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
469 $title = basename($media_path);
470 $html = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
471 } elseif (in_array($mime, ["video/mp4", "video/youtube", "video/vimeo"])) {
472 $video = $ui_factory->player()->video($media_path);
473 $html = $ui_renderer->render($video);
474 } elseif (in_array($mime, ["audio/mpeg"])) {
475 $audio = $ui_factory->player()->audio($media_path);
476 $html = $ui_renderer->render($audio);
477 } elseif (in_array($mime, ["application/pdf"])) {
478 $this->ctrl->setParameter($this, "news_id", $item->getId());
479 $link = $ui_factory->link()->standard(
480 basename($media_path),
481 $this->ctrl->getLinkTarget($this, "downloadMob")
482 );
483 $html = $ui_renderer->render($link);
484 $this->ctrl->setParameter($this, "news_id", null);
485 } else {
486 // download?
487 $html = $mime;
488 }
489
490 $tpl->setCurrentBlock("player");
491 $tpl->setVariable("PLAYER", $html);
493 }
494
495 // access
496 if ($enable_internal_rss && $item->getVisibility() !== '') {
497 $tpl->setCurrentBlock("access");
498 $tpl->setVariable("TXT_ACCESS", $this->lng->txt("news_news_item_visibility"));
499 if ($item->getVisibility() === NEWS_PUBLIC ||
500 ($item->getPriority() === 0 &&
502 "news",
503 "public_notifications",
504 0,
505 $item->getContextObjId()
506 ))) {
507 $tpl->setVariable("VAL_ACCESS", $this->lng->txt("news_visibility_public"));
508 } else {
509 $tpl->setVariable("VAL_ACCESS", $this->lng->txt("news_visibility_users"));
510 }
512 }
513
514 // content
515 $renderer = ilNewsRendererFactory::getRenderer($item->getContextObjType());
516 if (trim($item->getContent()) !== '') {
517 $renderer->setNewsItem($legacy_news, $item->getContextRefId());
518 $tpl->setCurrentBlock("content");
519 $tpl->setVariable("VAL_CONTENT", $renderer->getDetailContent());
521 }
522
523 // update date
524 if ($item->getUpdateDate() !== $item->getCreationDate()) {
525 $tpl->setCurrentBlock("ni_update");
526 $tpl->setVariable("TXT_LAST_UPDATE", $this->lng->txt("last_update"));
528 "VAL_LAST_UPDATE",
529 ilDatePresentation::formatDate(new ilDateTime($legacy_news->getUpdateDate(), IL_CAL_DATETIME))
530 );
532 }
533
534 // creation date
535 if ($item->getCreationDate()->getTimestamp() !== 0) {
536 $tpl->setCurrentBlock("ni_update");
538 "VAL_CREATION_DATE",
539 ilDatePresentation::formatDate(new ilDateTime($legacy_news->getCreationDate(), IL_CAL_DATETIME))
540 );
541 $tpl->setVariable("TXT_CREATED", $this->lng->txt("created"));
543 }
544
545 // context / title
546 if ($news_context > 0) {
547 $obj_title = ilObject::_lookupTitle($item->getContextObjId());
548
549 // file hack, not nice
550 if ($item->getContextObjType() === "file") {
551 $this->ctrl->setParameterByClass(ilRepositoryGUI::class, "ref_id", $item->getContextRefId());
552 $url = $this->ctrl->getLinkTargetByClass(ilRepositoryGUI::class, "sendfile");
553 $this->ctrl->setParameterByClass(ilRepositoryGUI::class, "ref_id", $this->std_request->getRefId());
554
555 $button = $this->gui->button(
556 $this->lng->txt("download"),
557 $url
558 );
559
560 $tpl->setCurrentBlock("download");
561 $tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
563 }
564
565 // forum hack, not nice
566 $add = "";
567 if ($item->getContextObjType() === "frm" &&
568 $item->getContextSubObjType() === "pos" &&
569 $item->getContextSubObjId() > 0
570 ) {
571 $pos = $item->getContextSubObjId();
573 if ($thread > 0) {
574 $add = "_" . $thread . "_" . $pos;
575 }
576 }
577
578 // wiki hack, not nice
579 if ($item->getContextObjType() === "wiki" &&
580 $item->getContextSubObjType() === "wpg" &&
581 $item->getContextSubObjId() > 0
582 ) {
583 $wptitle = ilWikiPage::lookupTitle($item->getContextSubObjId());
584 if ($wptitle != "") {
585 $add = "_" . ilWikiUtil::makeUrlTitle($wptitle);
586 }
587 }
588
589 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
590 $item->getContextObjType() . "_" . $item->getContextRefId() . $add;
591
592 // lm page hack, not nice
593 if ($item->getContextObjType() === "lm" &&
594 $item->getContextSubObjType() === "pg" &&
595 $item->getContextSubObjId() > 0
596 ) {
597 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
598 "pg_" . $item->getContextSubObjId() . "_" . $item->getContextRefId();
599 }
600
601 // blog posting hack, not nice
602 if ($item->getContextObjType() === "blog" &&
603 $item->getContextSubObjType() === "blp" &&
604 $item->getContextSubObjId() > 0
605 ) {
606 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
607 "blog_" . $item->getContextRefId() . "_" . $item->getContextSubObjId();
608 }
609
610 $context_opened = false;
611 $loc_context = $is_grouped_item ? $current_item->getContextRefId() : $news_context;
612 $loc_stop = $is_grouped_item ? $news_context : null;
613 if ($loc_context !== 0 && $loc_context !== $loc_stop) {
614 $tpl->setCurrentBlock("context");
615 $context_opened = true;
616 $cont_loc = new ilLocatorGUI();
617 $cont_loc->addContextItems($loc_context, true, (int) $loc_stop);
618 $tpl->setVariable("CONTEXT_LOCATOR", $cont_loc->getHTML());
619 }
620
621 if (!($grouping['no_context_title'] ?? false)) {
622 if (!$context_opened) {
623 $tpl->setCurrentBlock("context");
624 }
625 $tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
626 $tpl->setVariable("CONTEXT_TITLE", $obj_title);
628 "IMG_CONTEXT_TITLE",
629 ilObject::_getIcon($item->getContextObjId(), "big", $item->getContextObjType())
630 );
631 }
632 if ($context_opened) {
634 }
635
636 $tpl->setVariable("HREF_TITLE", $url_target);
637 }
638
639 // title
641 "VAL_TITLE",
643 $item->getContextObjType(),
644 $item->getTitle(),
645 $item->isContentIsLangVar(),
646 (!$is_grouped_item && $grouping) ? $grouping['agg_ref_id'] : 0,
647 (!$is_grouped_item && $grouping) ? $grouping['aggregation'] : [],
648 )
649 );
650
651 $tpl->setCurrentBlock("item");
652 $tpl->setVariable("ITEM_ROW_CSS", $i % 2 === 0 ? "tblrow1" : "tblrow2");
654 }
655
656 $content = $tpl->get();
657 $title = $this->getProperty('title') ?? $this->lng->txt("news_internal_news");
658 $panel = $ui_factory->panel()->standard($title, $ui_factory->legacy()->content($content));
659
660 $pagination = $ui_factory->viewControl()->pagination()
661 ->withTargetURL($this->ctrl->getLinkTarget($this, "showNews"), "news_page")
662 ->withTotalEntries(count($this->getData()))
663 ->withPageSize(1)
664 ->withMaxPaginationButtons(10)
665 ->withCurrentPage($this->collection->getPageFor($current_item->getId()));
666 $panel = $panel->withViewControls([$pagination]);
667
668 return $ui_renderer->render($panel);
669 }
670
671 protected function getMediaPath(int $mob_id): string
672 {
673 $media_path = "";
674 if ($mob_id > 0) {
675 $mob = new ilObjMediaObject($mob_id);
676 $media_path = $mob->getStandardSrc();
677 }
678 return $media_path;
679 }
680
681 public function makeClickable(string $a_str): string
682 {
683 // this fixes bug 8744. We assume that strings that contain < and >
684 // already contain html, we do not handle these
685 if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<"))) {
686 return $a_str;
687 }
688
689 return ilUtil::makeClickable($a_str);
690 }
691
692 public function showNotifications(): void
693 {
694 $ilCtrl = $this->ctrl;
695 $ilUser = $this->user;
696
698 $this->getBlockType(),
699 "view",
700 "",
701 $ilUser->getId(),
702 (int) $this->block_id
703 );
704
705 // reload data
706 $this->loadNewsData();
707 $this->handleView();
708
709 if ($ilCtrl->isAsynch()) {
710 $this->send($this->getHTML());
711 }
712
713 $ilCtrl->returnToParent($this);
714 }
715
716 public function hideNotifications(): void
717 {
718 $ilCtrl = $this->ctrl;
719 $ilUser = $this->user;
720
722 $this->getBlockType(),
723 "view",
724 "hide_notifications",
725 $ilUser->getId(),
726 (int) $this->block_id
727 );
728
729 // reload data
730 $this->loadNewsData();
731 $this->handleView();
732
733 if ($ilCtrl->isAsynch()) {
734 $this->send($this->getHTML());
735 }
736
737 $ilCtrl->returnToParent($this);
738 }
739
743 public function editSettings(): string
744 {
745 $this->initSettingsForm();
746 return $this->settings_form->getHTML();
747 }
748
752 public function initSettingsForm(): void
753 {
755 $ilCtrl = $this->ctrl;
756 $ilTabs = $this->tabs;
757
758 $ilTabs->clearTargets();
759
760 $news_set = new ilSetting("news");
761 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
762
763 $public = ilBlockSetting::_lookup(
764 $this->getBlockType(),
765 "public_notifications",
766 0,
767 (int) $this->block_id
768 );
769 $public_feed = ilBlockSetting::_lookup(
770 $this->getBlockType(),
771 "public_feed",
772 0,
773 (int) $this->block_id
774 );
775 $hide_block = ilBlockSetting::_lookup(
776 $this->getBlockType(),
777 "hide_news_block",
778 0,
779 (int) $this->block_id
780 );
781 $hide_news_per_date = ilBlockSetting::_lookup(
782 $this->getBlockType(),
783 "hide_news_per_date",
784 0,
785 (int) $this->block_id
786 );
787 $hide_news_date = ilBlockSetting::_lookup(
788 $this->getBlockType(),
789 "hide_news_date",
790 0,
791 (int) $this->block_id
792 );
793
794 if (is_string($hide_news_date) && $hide_news_date !== '') {
795 $hide_news_date = explode(" ", $hide_news_date);
796 }
797
798 $this->settings_form = new ilPropertyFormGUI();
799 $this->settings_form->setTitle($lng->txt("news_settings"));
800
801 // hide news block for learners
802 if ($this->getProperty("hide_news_block_option")) {
803 $ch = new ilCheckboxInputGUI(
804 $lng->txt("news_hide_news_block"),
805 "hide_news_block"
806 );
807 $ch->setInfo($lng->txt("news_hide_news_block_info"));
808 $ch->setChecked((bool) $hide_block);
809 $this->settings_form->addItem($ch);
810
811 $hnpd = new ilCheckboxInputGUI(
812 $lng->txt("news_hide_news_per_date"),
813 "hide_news_per_date"
814 );
815 $hnpd->setInfo($lng->txt("news_hide_news_per_date_info"));
816 $hnpd->setChecked((bool) $hide_news_per_date);
817
818 $dt_prop = new ilDateTimeInputGUI(
819 $lng->txt("news_hide_news_date"),
820 "hide_news_date"
821 );
822 $dt_prop->setRequired(true);
823 if (is_array($hide_news_date) && count($hide_news_date) === 2) {
824 $dt_prop->setDate(new ilDateTime($hide_news_date[0] . ' ' . $hide_news_date[1], IL_CAL_DATETIME));
825 }
826 $dt_prop->setShowTime(true);
827 $hnpd->addSubItem($dt_prop);
828
829 $this->settings_form->addItem($hnpd);
830 }
831
832 // default visibility
833 if ($enable_internal_rss && $this->getProperty("default_visibility_option")) {
834 $default_visibility = ilBlockSetting::_lookup(
835 $this->getBlockType(),
836 "default_visibility",
837 0,
838 (int) $this->block_id
839 );
840 if ($default_visibility == "") {
841 $default_visibility =
842 ilNewsItem::_getDefaultVisibilityForRefId($this->std_request->getRefId());
843 }
844
845 // Default Visibility
846 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
847 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
848 $radio_group->addOption($radio_option);
849 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
850 $radio_group->addOption($radio_option);
851 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
852 $radio_group->setRequired(false);
853 $radio_group->setValue($default_visibility);
854 $this->settings_form->addItem($radio_group);
855 }
856
857 // public notifications
858 if ($enable_internal_rss && $this->getProperty("public_notifications_option")) {
859 $ch = new ilCheckboxInputGUI(
860 $lng->txt("news_notifications_public"),
861 "notifications_public"
862 );
863 $ch->setInfo($lng->txt("news_notifications_public_info"));
864 $ch->setChecked((bool) $public);
865 $this->settings_form->addItem($ch);
866 }
867
868 // extra rss feed
869 if ($enable_internal_rss) {
870 $ch = new ilCheckboxInputGUI(
871 $lng->txt("news_public_feed"),
872 "notifications_public_feed"
873 );
874 $ch->setInfo($lng->txt("news_public_feed_info"));
875 $ch->setChecked((bool) $public_feed);
876 $this->settings_form->addItem($ch);
877 }
878
879 $this->settings_form->addCommandButton("saveSettings", $lng->txt("save"));
880 $this->settings_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
881 $this->settings_form->setFormAction($ilCtrl->getFormAction($this));
882 }
883
887 public static function addToSettingsForm(ilFormPropertyGUI $a_input): void
888 {
889 global $DIC;
890
891 $std_request = $DIC->news()
892 ->internal()
893 ->gui()
894 ->standardRequest();
895
896 $lng = $DIC->language();
897 $block_id = $DIC->ctrl()->getContextObjId();
898
899 $news_set = new ilSetting("news");
900 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
901
902 $public_feed = ilBlockSetting::_lookup(
903 self::$block_type,
904 "public_feed",
905 0,
907 );
908 $default_visibility = ilBlockSetting::_lookup(self::$block_type, "default_visibility", 0, $block_id);
909 if ($default_visibility == "") {
910 $default_visibility =
912 }
913 $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "default_visibility");
914 $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
915 $radio_group->addOption($radio_option);
916 $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
917 $radio_group->addOption($radio_option);
918 $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
919 $radio_group->setRequired(false);
920 $radio_group->setValue($default_visibility);
921 $a_input->addSubItem($radio_group);
922
923 // extra rss feed
924 if ($enable_internal_rss) {
925 $radio_rss = new ilCheckboxInputGUI(
926 $lng->txt("news_public_feed"),
927 "notifications_public_feed"
928 );
929 $radio_rss->setInfo($lng->txt("news_public_feed_info"));
930 $radio_rss->setChecked((bool) $public_feed);
931 $a_input->addSubItem($radio_rss);
932 }
933 }
934
935 public static function writeSettings(array $a_values): void
936 {
937 global $DIC;
938
939 $block_id = $DIC->ctrl()->getContextObjId();
940 foreach ($a_values as $key => $value) {
941 ilBlockSetting::_write(self::$block_type, (string) $key, (string) $value, 0, $block_id);
942 }
943 }
944
945 public function cancelSettings(): void
946 {
947 $ilCtrl = $this->ctrl;
948
949 $ilCtrl->returnToParent($this);
950 }
951
952 public function saveSettings(): string
953 {
954 $ilCtrl = $this->ctrl;
955
956 $this->initSettingsForm();
957 $form = $this->settings_form;
958 if ($form->checkInput()) {
959 $news_set = new ilSetting("news");
960 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
961
962 if ($enable_internal_rss) {
964 $this->getBlockType(),
965 "public_notifications",
966 $form->getInput("notifications_public"),
967 0,
968 (int) $this->block_id
969 );
971 $this->getBlockType(),
972 "public_feed",
973 $form->getInput("notifications_public_feed"),
974 0,
975 (int) $this->block_id
976 );
978 $this->getBlockType(),
979 "default_visibility",
980 $form->getInput("default_visibility"),
981 0,
982 (int) $this->block_id
983 );
984 }
985
986 if ($this->getProperty("hide_news_block_option")) {
988 $this->getBlockType(),
989 "hide_news_block",
990 $form->getInput("hide_news_block"),
991 0,
992 (int) $this->block_id
993 );
995 $this->getBlockType(),
996 "hide_news_per_date",
997 $form->getInput("hide_news_per_date"),
998 0,
999 (int) $this->block_id
1000 );
1001
1002 // hide date
1003 $hd = $this->settings_form->getItemByPostVar("hide_news_date");
1004 $hide_date = $hd->getDate();
1005 if ($hide_date instanceof ilDateTime && $form->getInput("hide_news_per_date")) {
1007 $this->getBlockType(),
1008 "hide_news_date",
1009 $hide_date->get(IL_CAL_DATETIME),
1010 0,
1011 (int) $this->block_id
1012 );
1013 } else {
1015 $this->getBlockType(),
1016 "hide_news_date",
1017 "",
1018 0,
1019 (int) $this->block_id
1020 );
1021 }
1022 }
1023
1024 $this->domain->collection()->invalidateCache($this->user->getId());
1025
1026 $ilCtrl->returnToParent($this);
1027 } else {
1028 $this->settings_form->setValuesByPost();
1029 return $this->settings_form->getHTML();
1030 }
1031 return "";
1032 }
1033
1034 public function showFeedUrl(): string
1035 {
1036 $lng = $this->lng;
1037 $ilUser = $this->user;
1038
1039 $title = ilObject::_lookupTitle((int) $this->block_id);
1040
1041 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "components/ILIAS/News");
1043 "TXT_TITLE",
1044 sprintf($lng->txt("news_feed_url_for"), $title)
1045 );
1046 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
1047 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
1049 "VAL_FEED_URL",
1050 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
1051 "&obj_id=" . $this->block_id .
1052 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1053 );
1055 "VAL_FEED_URL_TXT",
1056 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
1057 "&obj_id=" . $this->block_id .
1058 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
1059 );
1060
1061 $panel = $this->ui->factory()->panel()->standard(
1062 $lng->txt("news_internal_news"),
1063 $this->ui->factory()->legacy()->content($tpl->get())
1064 );
1065
1066 return $this->ui->renderer()->render($panel);
1067 }
1068
1069 public function getDynamicReload(): string
1070 {
1071 $ilCtrl = $this->ctrl;
1072 $lng = $this->lng;
1073
1074 $ilCtrl->setParameterByClass(
1075 ilColumnGUI::class,
1076 "block_id",
1077 "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1078 );
1079
1080 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "components/ILIAS/News");
1081 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("news_loading_news"));
1082 $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1083 $rel_tpl->setVariable(
1084 "TARGET",
1085 $ilCtrl->getLinkTargetByClass(ilColumnGUI::class, "updateBlock", "", true)
1086 );
1087
1088 // no JS
1089 $rel_tpl->setVariable("TXT_NEWS_CLICK_HERE", $lng->txt("news_no_js_click_here"));
1090 $rel_tpl->setVariable(
1091 "TARGET_NO_JS",
1092 $ilCtrl->getLinkTarget($this, "disableJS")
1093 );
1094
1095 return $rel_tpl->get();
1096 }
1097
1098 public function getJSEnabler(): string
1099 {
1100 $ilCtrl = $this->ctrl;
1101
1102 $ilCtrl->setParameterByClass(
1103 ilColumnGUI::class,
1104 "block_id",
1105 "block_" . $this->getBlockType() . "_" . $this->getBlockId()
1106 );
1107 //echo "hh";
1108 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "components/ILIAS/News");
1109 $rel_tpl->setVariable("BLOCK_ID", "block_" . $this->getBlockType() . "_" . $this->getBlockId());
1110 $rel_tpl->setVariable(
1111 "TARGET",
1112 $ilCtrl->getLinkTarget($this, "enableJS", "", true, false)
1113 );
1114
1115 return $rel_tpl->get();
1116 }
1117
1118
1119 public function disableJS(): void
1120 {
1121 $ilCtrl = $this->ctrl;
1122 $ilUser = $this->user;
1123
1124 ilSession::set("il_feed_js", "n");
1125 $ilUser->writePref("il_feed_js", "n");
1126 $ilCtrl->returnToParent($this);
1127 }
1128
1129 public function enableJS(): void
1130 {
1131 $ilUser = $this->user;
1132 ilSession::set("il_feed_js", "y");
1133 $ilUser->writePref("il_feed_js", "y");
1134 $this->send($this->getHTML());
1135 }
1136
1137 public function getNoItemFoundContent(): string
1138 {
1139 return $this->lng->txt("news_no_news_items");
1140 }
1141
1142 protected function downloadMob(): void
1143 {
1144 $news_id = $this->std_request->getNewsId();
1145 $news = new ilNewsItem($news_id);
1146 $news->deliverMobFile("Standard", true);
1147 }
1148}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Optimized News Collection with memory-efficient data structures to support large news feeds.
pluck(string $key, bool $wrap=false)
groupForums(bool $group_posting_sequence)
News Criteria DTO for querying news items supports caching, JSON serialization, and validation.
News Item DTO for transfer of news items.
Definition: NewsItem.php:29
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.
ilLanguage $lng
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
This class represents a property in a property form.
Help GUI class.
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...
BlockGUI class for block NewsForContext.
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.
initData(NewsCollection $collection)
isRepositoryObject()
Returns whether block has a corresponding repository object.
preloadData(array $data)
Method will be called before rendering the block.
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 _setRead(int $a_user_id, int $a_news_id)
Set item read.
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)
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 _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
$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:70