67 $this->
help = $DIC[
"ilHelp"];
69 $this->
tabs = $DIC->tabs();
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());
77 $this->
lng->loadLanguageModule(
"news");
78 $DIC->help()->addHelpSection(
"news_block");
84 if (!$this->prevent_initial_loading) {
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;
98 if ($this->std_request->getRefId() === 0) {
103 $collection = $this->domain->collection()->getNewsForContainer(
104 $this->std_request->getRefId(),
105 $this->ctrl->getContextObjId(),
106 $this->ctrl->getContextObjType(),
108 $this->user->getId(),
112 if ($this->
ctrl->getContextObjType() !==
'frm') {
129 parent::preloadData(
$data);
130 $this->collection->load(array_column(
$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'));
145 $this->
lng->txt(
'date') =>
$info[
'creation_date'] ??
''
148 $item = $this->
ui->factory()->item()->standard(
149 $this->
ui->factory()->link()->standard(
$info[
'news_title'] ??
'',
$info[
'url'] ??
'')
150 )->withProperties($props);
152 if (
$info[
'ref_id'] > 0) {
153 $item = $item->withDescription(
$info[
'type_txt'] .
': ' .
$info[
'obj_title']);
160 $item = $this->collection->getById($news_id);
161 if ($item ===
null) {
162 throw new \InvalidArgumentException(
"News item with id {$news_id} not found.");
165 $grouping = $this->collection->getGroupingFor($item);
170 $item->getContextObjType(),
172 $item->isContentIsLangVar(),
173 $grouping ? $grouping[
'agg_ref_id'] : 0,
174 $grouping ? $grouping[
'aggregation'] : [],
179 'ref_id' => $item->getContextRefId(),
185 if ($item->getContextRefId() > 0) {
186 $obj_id = $item->getContextObjId();
187 $type = $item->getContextObjType();
189 $lang_type = in_array($type, [
'sahs',
'lm',
'htlm']) ?
'lres' :
'obj_' . $type;
191 $type_txt = ($this->obj_def->isPlugin($item->getContextObjType()))
193 : $this->
lng->txt($lang_type);
195 $info[
'type_txt'] = $type_txt;
198 $info[
'user_read'] = $this->collection->isReadByUser($this->
user->getId(), $news_id);
200 $this->
ctrl->setParameter($this,
'news_context', $item->getContextRefId());
202 $this->
ctrl->setParameter($this,
'news_context',
'');
205 $this->
ctrl->setParameter($this,
'news_id', $item->getId());
206 $info[
'url'] = $this->
ctrl->getLinkTarget($this,
'showNews');
207 $this->
ctrl->clearParameters($this);
227 $ilCtrl =
$DIC->ctrl();
229 if (strcasecmp($ilCtrl->getCmdClass(), ilNewsItemGUI::class) === 0) {
233 switch ($ilCtrl->getCmd()) {
249 if (strcasecmp($this->
ctrl->getNextClass(), ilNewsItemGUI::class) === 0) {
252 return $this->
ctrl->forwardCommand($news_item_gui);
255 $cmd = $this->
ctrl->getCmd(
"getHTML");
256 return $this->$cmd();
268 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
274 (
int) $this->block_id
285 (
int) $this->block_id
287 if ($public_feed && $enable_internal_rss) {
290 ILIAS_HTTP_PATH .
"/feed.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&" .
291 "ref_id=" . $this->std_request->getRefId(),
297 if ($this->news_access->canAdd()) {
299 $ilCtrl->getLinkTargetByClass(ilNewsItemGUI::class,
"editNews"),
303 $ilCtrl->setParameter($this,
"add_mode",
"block");
305 $ilCtrl->getLinkTargetByClass(ilNewsItemGUI::class,
"createNewsItem"),
308 $ilCtrl->setParameter($this,
"add_mode",
"");
312 $ref_id = $this->std_request->getRefId();
317 $parent_gui =
"ilobj" . $obj_class .
"gui";
319 $ilCtrl->setParameterByClass(ilContainerNewsSettingsGUI::class,
"ref_id",
$ref_id);
321 if (in_array($obj_class, self::OBJECTS_WITH_NEWS_SUBTAB)) {
323 $ilCtrl->getLinkTargetByClass([ilRepositoryGUI::class, $parent_gui, ilContainerNewsSettingsGUI::class],
"show"),
333 $ilCtrl->getLinkTarget($this,
"editSettings"),
346 (
int) $this->block_id
355 !$news_set->get(
"enable_rss_for_internal") ||
357 $this->getBlockType(),
360 (
int) $this->block_id
368 return parent::getHTML() . $en;
410 return '<div class="small">' . (count($this->
getData())) .
" " .
$lng->
txt(
"news_news_items") .
"</div>";
413 public function showNews(): string
415 $ui_renderer = $this->
ui->renderer();
416 $ui_factory = $this->
ui->factory();
418 $tpl =
new ilTemplate(
"tpl.show_news.html",
true,
true,
"components/ILIAS/News");
420 $enable_internal_rss = $setting->get(
"enable_rss_for_internal");
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();
426 $current_item = $this->collection->pick($this->std_request->getNewsPage());
427 $news_context = $current_item->getContextRefId();
430 if ($current_item ===
null) {
434 if ($grouping = $this->collection->getGroupingFor($current_item)) {
435 $news_list = $grouping[
'aggregation'];
437 $news_list = [$current_item];
440 for ($i = 0; $i < count($news_list); $i++) {
442 $item = $news_list[$i];
443 $item = $item->withContextRefId($news_context);
447 $is_grouped_item = $i > 0;
448 $legacy_news = $item->toLegacy();
457 $display_name =
"<" . strtolower($this->
lng->txt(
"deleted")) .
">";
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")
483 $html = $ui_renderer->render($link);
484 $this->
ctrl->setParameter($this,
"news_id",
null);
496 if ($enable_internal_rss && $item->getVisibility() !==
'') {
500 ($item->getPriority() === 0 &&
503 "public_notifications",
505 $item->getContextObjId()
516 if (trim($item->getContent()) !==
'') {
517 $renderer->setNewsItem($legacy_news, $item->getContextRefId());
524 if ($item->getUpdateDate() !== $item->getCreationDate()) {
535 if ($item->getCreationDate()->getTimestamp() !== 0) {
546 if ($news_context > 0) {
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());
555 $button = $this->gui->button(
556 $this->
lng->txt(
"download"),
567 if ($item->getContextObjType() ===
"frm" &&
568 $item->getContextSubObjType() ===
"pos" &&
569 $item->getContextSubObjId() > 0
571 $pos = $item->getContextSubObjId();
574 $add =
"_" . $thread .
"_" . $pos;
579 if ($item->getContextObjType() ===
"wiki" &&
580 $item->getContextSubObjType() ===
"wpg" &&
581 $item->getContextSubObjId() > 0
584 if ($wptitle !=
"") {
589 $url_target =
"./goto.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&target=" .
590 $item->getContextObjType() .
"_" . $item->getContextRefId() . $add;
593 if ($item->getContextObjType() ===
"lm" &&
594 $item->getContextSubObjType() ===
"pg" &&
595 $item->getContextSubObjId() > 0
597 $url_target =
"./goto.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&target=" .
598 "pg_" . $item->getContextSubObjId() .
"_" . $item->getContextRefId();
602 if ($item->getContextObjType() ===
"blog" &&
603 $item->getContextSubObjType() ===
"blp" &&
604 $item->getContextSubObjId() > 0
606 $url_target =
"./goto.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&target=" .
607 "blog_" . $item->getContextRefId() .
"_" . $item->getContextSubObjId();
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) {
615 $context_opened =
true;
617 $cont_loc->addContextItems($loc_context,
true, (
int) $loc_stop);
621 if (!($grouping[
'no_context_title'] ??
false)) {
622 if (!$context_opened) {
632 if ($context_opened) {
643 $item->getContextObjType(),
645 $item->isContentIsLangVar(),
646 (!$is_grouped_item && $grouping) ? $grouping[
'agg_ref_id'] : 0,
647 (!$is_grouped_item && $grouping) ? $grouping[
'aggregation'] : [],
652 $tpl->
setVariable(
"ITEM_ROW_CSS", $i % 2 === 0 ?
"tblrow1" :
"tblrow2");
658 $panel = $ui_factory->panel()->standard(
$title, $ui_factory->legacy()->content($content));
660 $pagination = $ui_factory->viewControl()->pagination()
661 ->withTargetURL($this->
ctrl->getLinkTarget($this,
"showNews"),
"news_page")
662 ->withTotalEntries(count($this->
getData()))
664 ->withMaxPaginationButtons(10)
665 ->withCurrentPage($this->collection->getPageFor($current_item->getId()));
666 $panel = $panel->withViewControls([$pagination]);
668 return $ui_renderer->render($panel);
676 $media_path = $mob->getStandardSrc();
685 if (is_int(strpos($a_str,
">")) && is_int(strpos($a_str,
"<"))) {
702 (
int) $this->block_id
709 if ($ilCtrl->isAsynch()) {
713 $ilCtrl->returnToParent($this);
724 "hide_notifications",
726 (
int) $this->block_id
733 if ($ilCtrl->isAsynch()) {
737 $ilCtrl->returnToParent($this);
746 return $this->settings_form->getHTML();
761 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
765 "public_notifications",
767 (
int) $this->block_id
773 (
int) $this->block_id
779 (
int) $this->block_id
783 "hide_news_per_date",
785 (
int) $this->block_id
791 (
int) $this->block_id
794 if (is_string($hide_news_date) && $hide_news_date !==
'') {
795 $hide_news_date = explode(
" ", $hide_news_date);
799 $this->settings_form->setTitle(
$lng->
txt(
"news_settings"));
802 if ($this->
getProperty(
"hide_news_block_option")) {
804 $lng->
txt(
"news_hide_news_block"),
807 $ch->setInfo(
$lng->
txt(
"news_hide_news_block_info"));
808 $ch->setChecked((
bool) $hide_block);
809 $this->settings_form->addItem($ch);
812 $lng->
txt(
"news_hide_news_per_date"),
815 $hnpd->setInfo(
$lng->
txt(
"news_hide_news_per_date_info"));
816 $hnpd->setChecked((
bool) $hide_news_per_date);
819 $lng->
txt(
"news_hide_news_date"),
822 $dt_prop->setRequired(
true);
823 if (is_array($hide_news_date) && count($hide_news_date) === 2) {
826 $dt_prop->setShowTime(
true);
827 $hnpd->addSubItem($dt_prop);
829 $this->settings_form->addItem($hnpd);
833 if ($enable_internal_rss && $this->
getProperty(
"default_visibility_option")) {
836 "default_visibility",
838 (
int) $this->block_id
840 if ($default_visibility ==
"") {
841 $default_visibility =
848 $radio_group->addOption($radio_option);
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);
858 if ($enable_internal_rss && $this->
getProperty(
"public_notifications_option")) {
860 $lng->
txt(
"news_notifications_public"),
861 "notifications_public"
863 $ch->setInfo(
$lng->
txt(
"news_notifications_public_info"));
864 $ch->setChecked((
bool) $public);
865 $this->settings_form->addItem($ch);
869 if ($enable_internal_rss) {
872 "notifications_public_feed"
874 $ch->setInfo(
$lng->
txt(
"news_public_feed_info"));
875 $ch->setChecked((
bool) $public_feed);
876 $this->settings_form->addItem($ch);
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));
900 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
909 if ($default_visibility ==
"") {
910 $default_visibility =
915 $radio_group->addOption($radio_option);
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);
924 if ($enable_internal_rss) {
927 "notifications_public_feed"
929 $radio_rss->setInfo(
$lng->
txt(
"news_public_feed_info"));
930 $radio_rss->setChecked((
bool) $public_feed);
931 $a_input->addSubItem($radio_rss);
940 foreach ($a_values as $key => $value) {
958 if ($form->checkInput()) {
960 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
962 if ($enable_internal_rss) {
965 "public_notifications",
966 $form->getInput(
"notifications_public"),
968 (
int) $this->block_id
973 $form->getInput(
"notifications_public_feed"),
975 (
int) $this->block_id
979 "default_visibility",
980 $form->getInput(
"default_visibility"),
982 (
int) $this->block_id
986 if ($this->
getProperty(
"hide_news_block_option")) {
990 $form->getInput(
"hide_news_block"),
992 (
int) $this->block_id
996 "hide_news_per_date",
997 $form->getInput(
"hide_news_per_date"),
999 (
int) $this->block_id
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")) {
1011 (
int) $this->block_id
1019 (
int) $this->block_id
1024 $this->domain->collection()->invalidateCache($this->
user->getId());
1026 $ilCtrl->returnToParent($this);
1028 $this->settings_form->setValuesByPost();
1029 return $this->settings_form->getHTML();
1041 $tpl =
new ilTemplate(
"tpl.show_feed_url.html",
true,
true,
"components/ILIAS/News");
1050 ILIAS_HTTP_PATH .
"/feed.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&user_id=" . $ilUser->getId() .
1051 "&obj_id=" . $this->block_id .
1056 ILIAS_HTTP_PATH .
"/feed.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&<br />user_id=" . $ilUser->getId() .
1057 "&obj_id=" . $this->block_id .
1061 $panel = $this->
ui->factory()->panel()->standard(
1062 $lng->
txt(
"news_internal_news"),
1063 $this->ui->factory()->legacy()->content(
$tpl->
get())
1066 return $this->
ui->renderer()->render($panel);
1074 $ilCtrl->setParameterByClass(
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"));
1083 $rel_tpl->setVariable(
1085 $ilCtrl->getLinkTargetByClass(ilColumnGUI::class,
"updateBlock",
"",
true)
1089 $rel_tpl->setVariable(
"TXT_NEWS_CLICK_HERE",
$lng->
txt(
"news_no_js_click_here"));
1090 $rel_tpl->setVariable(
1092 $ilCtrl->getLinkTarget($this,
"disableJS")
1095 return $rel_tpl->get();
1108 $rel_tpl =
new ilTemplate(
"tpl.js_enabler.html",
true,
true,
"components/ILIAS/News");
1110 $rel_tpl->setVariable(
1112 $ilCtrl->getLinkTarget($this,
"enableJS",
"",
true,
false)
1115 return $rel_tpl->get();
1125 $ilUser->writePref(
"il_feed_js",
"n");
1126 $ilCtrl->returnToParent($this);
1133 $ilUser->writePref(
"il_feed_js",
"y");
1139 return $this->
lng->txt(
"news_no_news_items");
1144 $news_id = $this->std_request->getNewsId();
1146 $news->deliverMobFile(
"Standard",
true);
setVariable($variable, $value='')
Sets a variable value.
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.
This class represents a block method of a block.
send(string $output)
Send.
setTitle(string $a_title)
setPresentation(int $type)
ilObjectDefinition $obj_def
getProperty(string $a_property)
ILIAS UI Renderer $renderer
addBlockCommand(string $a_href, string $a_text, string $a_onclick="", ?RoundTrip $modal=null)
setBlockId(string $a_block_id="0")
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.
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,)
@classDescription Date and time handling
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.
bool $show_view_selection
static string $block_type
StandardGUIRequest $std_request
getMediaPath(int $mob_id)
editSettings()
Show settings screen.
InternalDomainService $domain
ilPropertyFormGUI $settings_form
static writeSettings(array $a_values)
NewsCollection $collection
getListItemForData(array $data)
Get list item for data array.
initSettingsForm()
Init setting form.
handleView()
Handles show/hide notification view and removes notifications if hidden.
bool $prevent_initial_loading
const OBJECTS_WITH_NEWS_SUBTAB
object type names with settings->news settings subtab
getNewsForId(int $news_id)
makeClickable(string $a_str)
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 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 an option in a radio group.
static set(string $a_var, $a_val)
Set a value.
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)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.