68 $this->
help = $DIC[
"ilHelp"];
70 $this->
tabs = $DIC->tabs();
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());
78 $this->
lng->loadLanguageModule(
"news");
79 $DIC->help()->addHelpSection(
"news_block");
85 if (!$this->prevent_initial_loading) {
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;
99 if ($this->std_request->getRefId() === 0) {
105 new NewsContext($this->std_request->getRefId(), $this->ctrl->getContextObjId(), $this->ctrl->getContextObjType()),
107 $this->user->getId(),
111 if ($this->
ctrl->getContextObjType() !==
'frm') {
128 parent::preloadData(
$data);
129 $this->collection->load(array_column(
$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'));
144 $this->
lng->txt(
'date') =>
$info[
'creation_date'] ??
''
147 $item = $this->
ui->factory()->item()->standard(
148 $this->
ui->factory()->link()->standard(
$info[
'news_title'] ??
'',
$info[
'url'] ??
'')
149 )->withProperties($props);
151 if (
$info[
'ref_id'] > 0) {
152 $item = $item->withDescription(
$info[
'type_txt'] .
': ' .
$info[
'obj_title']);
159 $item = $this->collection->getById($news_id);
160 if ($item ===
null) {
161 throw new \InvalidArgumentException(
"News item with id {$news_id} not found.");
164 $grouping = $this->collection->getGroupingFor($item);
169 $item->getContextObjType(),
171 $item->isContentIsLangVar(),
172 $grouping ? $grouping[
'agg_ref_id'] : 0,
173 $grouping ? $grouping[
'aggregation'] : [],
178 'ref_id' => $item->getContextRefId(),
184 if ($item->getContextRefId() > 0) {
185 $obj_id = $item->getContextObjId();
186 $type = $item->getContextObjType();
188 $lang_type = in_array($type, [
'sahs',
'lm',
'htlm']) ?
'lres' :
'obj_' . $type;
190 $type_txt = ($this->obj_def->isPlugin($item->getContextObjType()))
192 : $this->
lng->txt($lang_type);
194 $info[
'type_txt'] = $type_txt;
197 $info[
'user_read'] = $this->collection->isReadByUser($this->
user->getId(), $news_id);
199 $this->
ctrl->setParameter($this,
'news_context', $item->getContextRefId());
201 $this->
ctrl->setParameter($this,
'news_context',
'');
204 $this->
ctrl->setParameter($this,
'news_id', $item->getId());
205 $info[
'url'] = $this->
ctrl->getLinkTarget($this,
'showNews');
206 $this->
ctrl->clearParameters($this);
226 $ilCtrl =
$DIC->ctrl();
228 if (strcasecmp($ilCtrl->getCmdClass(), ilNewsItemGUI::class) === 0) {
232 switch ($ilCtrl->getCmd()) {
248 if (strcasecmp($this->
ctrl->getNextClass(), ilNewsItemGUI::class) === 0) {
251 return $this->
ctrl->forwardCommand($news_item_gui);
254 $cmd = $this->
ctrl->getCmd(
"getHTML");
255 return $this->$cmd();
267 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
273 (
int) $this->block_id
284 (
int) $this->block_id
286 if ($public_feed && $enable_internal_rss) {
289 ILIAS_HTTP_PATH .
"/feed.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&" .
290 "ref_id=" . $this->std_request->getRefId(),
296 if ($this->news_access->canAdd()) {
298 $ilCtrl->getLinkTargetByClass(ilNewsItemGUI::class,
"editNews"),
302 $ilCtrl->setParameter($this,
"add_mode",
"block");
304 $ilCtrl->getLinkTargetByClass(ilNewsItemGUI::class,
"createNewsItem"),
307 $ilCtrl->setParameter($this,
"add_mode",
"");
311 $ref_id = $this->std_request->getRefId();
316 $parent_gui =
"ilobj" . $obj_class .
"gui";
318 $ilCtrl->setParameterByClass(ilContainerNewsSettingsGUI::class,
"ref_id",
$ref_id);
320 if (in_array($obj_class, self::OBJECTS_WITH_NEWS_SUBTAB)) {
322 $ilCtrl->getLinkTargetByClass([ilRepositoryGUI::class, $parent_gui, ilContainerNewsSettingsGUI::class],
"show"),
332 $ilCtrl->getLinkTarget($this,
"editSettings"),
345 (
int) $this->block_id
354 !$news_set->get(
"enable_rss_for_internal") ||
356 $this->getBlockType(),
359 (
int) $this->block_id
367 return parent::getHTML() . $en;
409 return '<div class="small">' . (count($this->
getData())) .
" " .
$lng->
txt(
"news_news_items") .
"</div>";
412 public function showNews(): string
414 $ui_renderer = $this->
ui->renderer();
415 $ui_factory = $this->
ui->factory();
417 $tpl =
new ilTemplate(
"tpl.show_news.html",
true,
true,
"components/ILIAS/News");
419 $enable_internal_rss = $setting->get(
"enable_rss_for_internal");
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();
425 $current_item = $this->collection->pick($this->std_request->getNewsPage());
426 $news_context = $current_item->getContextRefId();
429 if ($current_item ===
null) {
433 if ($grouping = $this->collection->getGroupingFor($current_item)) {
434 $news_list = $grouping[
'aggregation'];
436 $news_list = [$current_item];
439 for ($i = 0; $i < count($news_list); $i++) {
441 $item = $news_list[$i];
442 $item = $item->withContextRefId($news_context);
446 $is_grouped_item = $i > 0;
447 $legacy_news = $item->toLegacy();
456 $display_name =
"<" . strtolower($this->
lng->txt(
"deleted")) .
">";
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")
482 $html = $ui_renderer->render($link);
483 $this->
ctrl->setParameter($this,
"news_id",
null);
495 if ($enable_internal_rss && $item->getVisibility() !==
'') {
499 ($item->getPriority() === 0 &&
502 "public_notifications",
504 $item->getContextObjId()
515 if (trim($item->getContent()) !==
'') {
516 $renderer->setNewsItem($legacy_news, $item->getContextRefId());
523 if ($item->getUpdateDate() !== $item->getCreationDate()) {
534 if ($item->getCreationDate()->getTimestamp() !== 0) {
545 if ($news_context > 0) {
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());
554 $button = $this->gui->button(
555 $this->
lng->txt(
"download"),
566 if ($item->getContextObjType() ===
"frm" &&
567 $item->getContextSubObjType() ===
"pos" &&
568 $item->getContextSubObjId() > 0
570 $pos = $item->getContextSubObjId();
573 $add =
"_" . $thread .
"_" . $pos;
578 if ($item->getContextObjType() ===
"wiki" &&
579 $item->getContextSubObjType() ===
"wpg" &&
580 $item->getContextSubObjId() > 0
583 if ($wptitle !=
"") {
588 $url_target =
"./goto.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&target=" .
589 $item->getContextObjType() .
"_" . $item->getContextRefId() . $add;
592 if ($item->getContextObjType() ===
"lm" &&
593 $item->getContextSubObjType() ===
"pg" &&
594 $item->getContextSubObjId() > 0
596 $url_target =
"./goto.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&target=" .
597 "pg_" . $item->getContextSubObjId() .
"_" . $item->getContextRefId();
601 if ($item->getContextObjType() ===
"blog" &&
602 $item->getContextSubObjType() ===
"blp" &&
603 $item->getContextSubObjId() > 0
605 $url_target =
"./goto.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&target=" .
606 "blog_" . $item->getContextRefId() .
"_" . $item->getContextSubObjId();
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) {
614 $context_opened =
true;
616 $cont_loc->addContextItems($loc_context,
true, (
int) $loc_stop);
620 if (!($grouping[
'no_context_title'] ??
false)) {
621 if (!$context_opened) {
631 if ($context_opened) {
642 $item->getContextObjType(),
644 $item->isContentIsLangVar(),
645 (!$is_grouped_item && $grouping) ? $grouping[
'agg_ref_id'] : 0,
646 (!$is_grouped_item && $grouping) ? $grouping[
'aggregation'] : [],
651 $tpl->
setVariable(
"ITEM_ROW_CSS", $i % 2 === 0 ?
"tblrow1" :
"tblrow2");
657 $panel = $ui_factory->panel()->standard(
$title, $ui_factory->legacy()->content($content));
659 $pagination = $ui_factory->viewControl()->pagination()
660 ->withTargetURL($this->
ctrl->getLinkTarget($this,
"showNews"),
"news_page")
661 ->withTotalEntries(count($this->
getData()))
663 ->withMaxPaginationButtons(10)
664 ->withCurrentPage($this->collection->getPageFor($current_item->getId()));
665 $panel = $panel->withViewControls([$pagination]);
667 return $ui_renderer->render($panel);
675 $media_path = $mob->getStandardSrc();
684 if (is_int(strpos($a_str,
">")) && is_int(strpos($a_str,
"<"))) {
701 (
int) $this->block_id
708 if ($ilCtrl->isAsynch()) {
712 $ilCtrl->returnToParent($this);
723 "hide_notifications",
725 (
int) $this->block_id
732 if ($ilCtrl->isAsynch()) {
736 $ilCtrl->returnToParent($this);
745 return $this->settings_form->getHTML();
760 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
764 "public_notifications",
766 (
int) $this->block_id
772 (
int) $this->block_id
778 (
int) $this->block_id
782 "hide_news_per_date",
784 (
int) $this->block_id
790 (
int) $this->block_id
793 if (is_string($hide_news_date) && $hide_news_date !==
'') {
794 $hide_news_date = explode(
" ", $hide_news_date);
798 $this->settings_form->setTitle(
$lng->
txt(
"news_settings"));
801 if ($this->
getProperty(
"hide_news_block_option")) {
803 $lng->
txt(
"news_hide_news_block"),
806 $ch->setInfo(
$lng->
txt(
"news_hide_news_block_info"));
807 $ch->setChecked((
bool) $hide_block);
808 $this->settings_form->addItem($ch);
811 $lng->
txt(
"news_hide_news_per_date"),
814 $hnpd->setInfo(
$lng->
txt(
"news_hide_news_per_date_info"));
815 $hnpd->setChecked((
bool) $hide_news_per_date);
818 $lng->
txt(
"news_hide_news_date"),
821 $dt_prop->setRequired(
true);
822 if (is_array($hide_news_date) && count($hide_news_date) === 2) {
825 $dt_prop->setShowTime(
true);
826 $hnpd->addSubItem($dt_prop);
828 $this->settings_form->addItem($hnpd);
832 if ($enable_internal_rss && $this->
getProperty(
"default_visibility_option")) {
835 "default_visibility",
837 (
int) $this->block_id
839 if ($default_visibility ==
"") {
840 $default_visibility =
847 $radio_group->addOption($radio_option);
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);
857 if ($enable_internal_rss && $this->
getProperty(
"public_notifications_option")) {
859 $lng->
txt(
"news_notifications_public"),
860 "notifications_public"
862 $ch->setInfo(
$lng->
txt(
"news_notifications_public_info"));
863 $ch->setChecked((
bool) $public);
864 $this->settings_form->addItem($ch);
868 if ($enable_internal_rss) {
871 "notifications_public_feed"
873 $ch->setInfo(
$lng->
txt(
"news_public_feed_info"));
874 $ch->setChecked((
bool) $public_feed);
875 $this->settings_form->addItem($ch);
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));
899 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
908 if ($default_visibility ==
"") {
909 $default_visibility =
914 $radio_group->addOption($radio_option);
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);
923 if ($enable_internal_rss) {
926 "notifications_public_feed"
928 $radio_rss->setInfo(
$lng->
txt(
"news_public_feed_info"));
929 $radio_rss->setChecked((
bool) $public_feed);
930 $a_input->addSubItem($radio_rss);
939 foreach ($a_values as $key => $value) {
957 if ($form->checkInput()) {
959 $enable_internal_rss = $news_set->get(
"enable_rss_for_internal");
961 if ($enable_internal_rss) {
964 "public_notifications",
965 $form->getInput(
"notifications_public"),
967 (
int) $this->block_id
972 $form->getInput(
"notifications_public_feed"),
974 (
int) $this->block_id
978 "default_visibility",
979 $form->getInput(
"default_visibility"),
981 (
int) $this->block_id
985 if ($this->
getProperty(
"hide_news_block_option")) {
989 $form->getInput(
"hide_news_block"),
991 (
int) $this->block_id
995 "hide_news_per_date",
996 $form->getInput(
"hide_news_per_date"),
998 (
int) $this->block_id
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")) {
1010 (
int) $this->block_id
1018 (
int) $this->block_id
1023 $this->domain->collection()->invalidateCache($this->
user->getId());
1025 $ilCtrl->returnToParent($this);
1027 $this->settings_form->setValuesByPost();
1028 return $this->settings_form->getHTML();
1040 $tpl =
new ilTemplate(
"tpl.show_feed_url.html",
true,
true,
"components/ILIAS/News");
1049 ILIAS_HTTP_PATH .
"/feed.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&user_id=" . $ilUser->getId() .
1050 "&obj_id=" . $this->block_id .
1055 ILIAS_HTTP_PATH .
"/feed.php?client_id=" . rawurlencode(
CLIENT_ID) .
"&<br />user_id=" . $ilUser->getId() .
1056 "&obj_id=" . $this->block_id .
1060 $panel = $this->
ui->factory()->panel()->standard(
1061 $lng->
txt(
"news_internal_news"),
1062 $this->ui->factory()->legacy()->content(
$tpl->
get())
1065 return $this->
ui->renderer()->render($panel);
1073 $ilCtrl->setParameterByClass(
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"));
1082 $rel_tpl->setVariable(
1084 $ilCtrl->getLinkTargetByClass(ilColumnGUI::class,
"updateBlock",
"",
true)
1088 $rel_tpl->setVariable(
"TXT_NEWS_CLICK_HERE",
$lng->
txt(
"news_no_js_click_here"));
1089 $rel_tpl->setVariable(
1091 $ilCtrl->getLinkTarget($this,
"disableJS")
1094 return $rel_tpl->get();
1107 $rel_tpl =
new ilTemplate(
"tpl.js_enabler.html",
true,
true,
"components/ILIAS/News");
1109 $rel_tpl->setVariable(
1111 $ilCtrl->getLinkTarget($this,
"enableJS",
"",
true,
false)
1114 return $rel_tpl->get();
1124 $ilUser->writePref(
"il_feed_js",
"n");
1125 $ilCtrl->returnToParent($this);
1132 $ilUser->writePref(
"il_feed_js",
"y");
1138 return $this->
lng->txt(
"news_no_news_items");
1143 $news_id = $this->std_request->getNewsId();
1145 $news->deliverMobFile(
"Standard",
true);
setVariable($variable, $value='')
Sets a variable value.
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.
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.