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