ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserFeedWriter.php
Go to the documentation of this file.
1<?php
2
24{
26 protected ilLanguage $lng;
27
28 public function __construct(
29 int $a_user_id,
30 string $a_hash,
31 bool $privFeed = false
32 ) {
33 global $DIC;
34
35 $this->settings = $DIC->settings();
36 $this->lng = $DIC->language();
37 $ilSetting = $DIC->settings();
38
40
41 if ($a_user_id == "" || $a_hash == "") {
42 return;
43 }
44
45 $news_set = new ilSetting("news");
46 if (!$news_set->get("enable_rss_for_internal")) {
47 return;
48 }
49
50 $hash = ilObjUser::_lookupFeedHash($a_user_id);
51
52 $rss_period = ilNewsItem::_lookupRSSPeriod();
53
54 if ($a_hash == $hash) {
55 if ($privFeed) {
56 //ilNewsItem::setPrivateFeedId($a_user_id);
57 $items = ilNewsItem::_getNewsItemsOfUser($a_user_id, false, true, $rss_period);
58 } else {
59 $items = ilNewsItem::_getNewsItemsOfUser($a_user_id, true, true, $rss_period);
60 }
61
62 if ($ilSetting->get('short_inst_name') != "") {
63 $this->setChannelTitle($ilSetting->get('short_inst_name'));
64 } else {
65 $this->setChannelTitle("ILIAS");
66 }
67
68 $this->setChannelAbout(ILIAS_HTTP_PATH);
69 $this->setChannelLink(ILIAS_HTTP_PATH);
70 //$this->setChannelDescription("ILIAS Channel Description");
71 foreach ($items as $item) {
72 $obj_id = ilObject::_lookupObjId($item["ref_id"]);
73 $obj_type = ilObject::_lookupType($obj_id);
74 $obj_title = ilObject::_lookupTitle($obj_id);
75
76 // not nice, to do: general solution
77 if ($obj_type == "mcst") {
79 continue;
80 }
81 }
82
83 $feed_item = new ilFeedItem();
85 $item["context_obj_type"],
86 $item["title"],
87 (bool) $item["content_is_lang_var"],
88 (int) ($item["agg_ref_id"] ?? 0),
89 $item["aggregation"] ?? []
90 );
91
92 // path
93 $loc = $this->getContextPath($item["ref_id"]);
94
95 // title
96 if ($news_set->get("rss_title_format") == "news_obj") {
97 $feed_item->setTitle($this->prepareStr(str_replace("<br />", " ", $title)) .
98 " (" . $this->prepareStr($loc) . " " . $this->prepareStr($obj_title) .
99 ")");
100 } else {
101 $feed_item->setTitle($this->prepareStr($loc) . " " . $this->prepareStr($obj_title) .
102 ": " . $this->prepareStr(str_replace("<br />", " ", $title)));
103 }
104
105 // description
106 $content = $this->prepareStr(nl2br(
108 $item["context_obj_type"],
109 $item["content"],
110 $item["content_text_is_lang_var"]
111 )
112 ));
113 $feed_item->setDescription($content);
114
115 // lm page hack, not nice
116 if ($item["context_obj_type"] == "lm" && $item["context_sub_obj_type"] == "pg"
117 && $item["context_sub_obj_id"] > 0) {
118 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
119 "&amp;target=pg_" . $item["context_sub_obj_id"] . "_" . $item["ref_id"]);
120 } elseif ($item["context_obj_type"] == "wiki" && $item["context_sub_obj_type"] == "wpg"
121 && $item["context_sub_obj_id"] > 0) {
122 $wptitle = ilWikiPage::lookupTitle($item["context_sub_obj_id"]);
123 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
124 "&amp;target=" . $item["context_obj_type"] . "_" . $item["ref_id"] . "_" . urlencode($wptitle)); // #14629
125 } elseif ($item["context_obj_type"] == "frm" && $item["context_sub_obj_type"] == "pos"
126 && $item["context_sub_obj_id"] > 0) {
127 // frm hack, not nice
128 $thread_id = ilObjForumAccess::_getThreadForPosting($item["context_sub_obj_id"]);
129 if ($thread_id > 0) {
130 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
131 "&amp;target=" . $item["context_obj_type"] . "_" . $item["ref_id"] . "_" . $thread_id . "_" . $item["context_sub_obj_id"]);
132 } else {
133 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
134 "&amp;target=" . $item["context_obj_type"] . "_" . $item["ref_id"]);
135 }
136 } else {
137 $feed_item->setLink(ILIAS_HTTP_PATH . "/goto.php?client_id=" . CLIENT_ID .
138 "&amp;target=" . $item["context_obj_type"] . "_" . $item["ref_id"]);
139 }
140 $feed_item->setAbout($feed_item->getLink() . "&amp;il_about_feed=" . $item["id"]);
141 $feed_item->setDate($item["creation_date"]);
142 $this->addItem($feed_item);
143 }
144 }
145 }
146}
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 _getNewsItemsOfUser(int $a_user_id, bool $a_only_public=false, bool $a_prevent_aggregation=false, int $a_per=0, array &$a_cnt=[], bool $no_auto_generated=false, array $excluded=[], int $a_limit=0)
Get all news items for a user.
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)
static _lookupFeedHash(int $a_user_id, bool $a_create=false)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_user_id, string $a_hash, bool $privFeed=false)
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