ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilUserFeedWriter.php
Go to the documentation of this file.
1<?php
2
21
27{
29 protected ilLanguage $lng;
30
31 public function __construct(
32 int $a_user_id,
33 string $a_hash,
34 bool $privFeed = false
35 ) {
36 global $DIC;
37
38 $this->settings = $DIC->settings();
39 $this->lng = $DIC->language();
40 $ilSetting = $DIC->settings();
41
43
44 if ($a_user_id == "" || $a_hash == "") {
45 return;
46 }
47
48 $news_set = new ilSetting("news");
49 if (!$news_set->get("enable_rss_for_internal")) {
50 return;
51 }
52
53 $hash = ilObjUser::_lookupFeedHash($a_user_id);
54
55 if ($a_hash == $hash) {
56 $rss_period = ilNewsItem::_lookupRSSPeriod();
57 $items = $DIC->news()->internal()->domain()->collection()->getNewsForUser(
58 new ilObjUser($a_user_id),
59 new NewsCriteria(period: $rss_period, only_public: !$privFeed),
60 false
61 );
62
63 if ($ilSetting->get('short_inst_name') != "") {
64 $this->setChannelTitle($ilSetting->get('short_inst_name'));
65 } else {
66 $this->setChannelTitle("ILIAS");
67 }
68
69 $this->setChannelAbout(ILIAS_HTTP_PATH);
70 $this->setChannelLink(ILIAS_HTTP_PATH);
71 //$this->setChannelDescription("ILIAS Channel Description");
72
74 foreach ($items as $item) {
75 $obj_title = ilObject::_lookupTitle($item->getContextObjId());
76
77 // not nice, to do: general solution
78 if ($item->getContextObjType() === 'mcst') {
79 if (!ilObjMediaCastAccess::_lookupOnline($item->getContextObjId())) {
80 continue;
81 }
82 }
83
84 $feed_item = new ilFeedItem();
86 $item->getContextObjType(),
87 $item->getTitle(),
88 $item->isContentIsLangVar(),
89 0,
90 []
91 );
92
93 // path
94 $loc = $this->getContextPath($item->getContextRefId());
95
96 // title
97 if ($news_set->get("rss_title_format") == "news_obj") {
98 $feed_item->setTitle($this->prepareStr(str_replace("<br />", " ", $title)) .
99 " (" . $this->prepareStr($loc) . " " . $this->prepareStr($obj_title) .
100 ")");
101 } else {
102 $feed_item->setTitle($this->prepareStr($loc) . " " . $this->prepareStr($obj_title) .
103 ": " . $this->prepareStr(str_replace("<br />", " ", $title)));
104 }
105
106 // description
107 $content = $this->prepareStr(nl2br(
109 $item->getContextObjType(),
110 $item->getContent(),
111 $item->isContentTextIsLangVar(),
112 )
113 ));
114 $feed_item->setDescription($content);
115
116 // lm page hack, not nice
117 if ($item->getContextObjType() == "lm" && $item->getContextSubObjType() == "pg"
118 && $item->getContextObjId() > 0) {
119 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
120 "&amp;target=pg_" . $item->getContextSubObjId() . "_" . $item->getContextRefId());
121 } elseif ($item->getContextObjType() == "wiki" && $item->getContextSubObjType() == "wpg"
122 && $item->getContextSubObjId() > 0) {
123 $wptitle = ilWikiPage::lookupTitle($item->getContextSubObjId());
124 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
125 "&amp;target=" . $item->getContextObjType() . "_" . $item->getContextRefId() . "_" . urlencode($wptitle)); // #14629
126 } elseif ($item->getContextObjType() == "frm" && $item->getContextSubObjType() == "pos"
127 && $item->getContextSubObjId() > 0) {
128 // frm hack, not nice
129 $thread_id = ilObjForumAccess::_getThreadForPosting($item->getContextSubObjId());
130 if ($thread_id > 0) {
131 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
132 "&amp;target=" . $item->getContextObjType() . "_" . $item->getContextRefId() . "_" . $thread_id . "_" . $item->getContextSubObjId());
133 } else {
134 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
135 "&amp;target=" . $item->getContextObjType() . "_" . $item->getContextRefId());
136 }
137 } else {
138 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
139 "&amp;target=" . $item->getContextObjType() . "_" . $item->getContextRefId());
140 }
141 $feed_item->setAbout($feed_item->getLink() . "&amp;il_about_feed=" . $item->getId());
142 $feed_item->setDate($item->getCreationDate()->format("Y-m-d H:i:s"));
143 $this->addItem($feed_item);
144 }
145 }
146 }
147}
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addItem(ilFeedItem $a_item)
getContextPath(int $a_ref_id)
prepareStr(string $a_str)
setChannelAbout(string $a_ab)
setChannelTitle(string $a_title)
setChannelLink(string $a_link)
language handling
static _lookupRSSPeriod()
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 determineNewsContent(string $a_context_obj_type, string $a_content, bool $a_is_lang_var, ?ilLanguage $lng=null)
Determine new content.
static _getThreadForPosting(int $a_pos_id)
User class.
static _lookupFeedHash(int $a_user_id, bool $a_create=false)
static _lookupTitle(int $obj_id)
ILIAS Setting Class.
Feed writer for personal user feeds.
static lookupTitle(int $a_page_id, string $lang="-")
const CLIENT_ID
Definition: constants.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26