ILIAS  release_8 Revision v8.24
class.ilPDNewsTableGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected string $selected_context;
31 protected array $contexts;
32 protected ilObjUser $user;
34
35 public function __construct(
36 ilPDNewsGUI $a_parent_obj,
37 string $a_parent_cmd,
38 array $a_contexts,
39 string $a_selected_context
40 ) {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->lng = $DIC->language();
45 $this->user = $DIC->user();
46 $ilCtrl = $DIC->ctrl();
47 $this->std_request = new StandardGUIRequest(
48 $DIC->http(),
49 $DIC->refinery()
50 );
51
52 parent::__construct($a_parent_obj, $a_parent_cmd);
53
54 $this->contexts = $a_contexts;
55 $this->selected_context = $a_selected_context;
56 $this->addColumn("");
57 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
58 $this->setRowTemplate(
59 "tpl.table_row_pd_news.html",
60 "Services/News"
61 );
62 $this->setDefaultOrderField("update_date");
63 $this->setDefaultOrderDirection("desc");
64 $this->setEnableTitle(false);
65 $this->setEnableHeader(false);
66 $this->setIsDataTable(false);
67 $this->initFilter();
68 }
69
70 public function initFilter(): void
71 {
74
75 // period
76 $per = (ilSession::get("news_pd_news_per") != "")
77 ? ilSession::get("news_pd_news_per")
79 $news_set = new ilSetting("news");
80 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
81 $allow_longer_periods = $news_set->get("allow_longer_periods");
83
84 $options = [
85 2 => sprintf($lng->txt("news_period_x_days"), 2),
86 3 => sprintf($lng->txt("news_period_x_days"), 3),
87 5 => sprintf($lng->txt("news_period_x_days"), 5),
88 7 => $lng->txt("news_period_1_week"),
89 14 => sprintf($lng->txt("news_period_x_weeks"), 2),
90 30 => $lng->txt("news_period_1_month"),
91 60 => sprintf($lng->txt("news_period_x_months"), 2),
92 120 => sprintf($lng->txt("news_period_x_months"), 4),
93 180 => sprintf($lng->txt("news_period_x_months"), 6),
94 366 => $lng->txt("news_period_1_year")
95 ];
96
97 $unset = [];
98 foreach ($options as $k => $opt) {
99 if (!$allow_shorter_periods && ($k < $default_per)) {
100 $unset[$k] = $k;
101 }
102 if (!$allow_longer_periods && ($k > $default_per)) {
103 $unset[$k] = $k;
104 }
105 }
106 foreach ($unset as $k) {
107 unset($options[$k]);
108 }
109
110 $si = new ilSelectInputGUI($this->lng->txt("news_time_period"), "news_per");
111 $si->setOptions($options);
112 $si->setValue((string) $per);
113 $this->addFilterItem($si);
114
115 // related to...
116 $si = new ilSelectInputGUI($this->lng->txt("context"), "news_ref_id");
117 $si->setOptions($this->contexts);
118 $si->setValue($this->selected_context);
119 $this->addFilterItem($si);
120 }
121
122 protected function fillRow(array $a_set): void
123 {
125 $ilCtrl = $this->ctrl;
126
127 $news_set = new ilSetting("news");
128 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
129
130 // context
131 $obj_id = ilObject::_lookupObjId((int) $a_set["ref_id"]);
132 $obj_type = ilObject::_lookupType($obj_id);
133 $obj_title = ilObject::_lookupTitle($obj_id);
134
135 // user
136 if ($a_set["user_id"] > 0) {
137 $this->tpl->setCurrentBlock("user_info");
138 if ($obj_type === "frm") {
139 if (ilForumProperties::_isAnonymized((int) $a_set["context_obj_id"])) {
140 if ($a_set["context_sub_obj_type"] === "pos" &&
141 $a_set["context_sub_obj_id"] > 0) {
142 $post = new ilForumPost((int) $a_set["context_sub_obj_id"]);
143 if (is_string($post->getUserAlias()) && $post->getUserAlias() !== '') {
144 $this->tpl->setVariable("VAL_AUTHOR", ilUtil::stripSlashes($post->getUserAlias()));
145 } else {
146 $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
147 }
148 } else {
149 $this->tpl->setVariable("VAL_AUTHOR", $lng->txt("forums_anonymous"));
150 }
151 } elseif (ilObject::_exists((int) $a_set["user_id"])) {
152 $user_obj = new ilObjUser((int) $a_set["user_id"]);
153 $this->tpl->setVariable("VAL_AUTHOR", $user_obj->getLogin());
154 }
155 } elseif (ilObject::_exists((int) $a_set["user_id"])) {
156 $this->tpl->setVariable("VAL_AUTHOR", ilObjUser::_lookupLogin((int) $a_set["user_id"]));
157 }
158 $this->tpl->setVariable("TXT_AUTHOR", $lng->txt("author"));
159 $this->tpl->parseCurrentBlock();
160 }
161
162 // media player
163 if ($a_set["content_type"] === NEWS_AUDIO &&
164 $a_set["mob_id"] > 0 && ilObject::_exists((int) $a_set["mob_id"])) {
165 $mob = new ilObjMediaObject((int) $a_set["mob_id"]);
166 $med = $mob->getMediaItem("Standard");
167 $mpl = new ilMediaPlayerGUI();
168 $mpl->setFile(ilObjMediaObject::_getDirectory((int) $a_set["mob_id"]) . "/" .
169 $med->getLocation());
170 $this->tpl->setCurrentBlock("player");
171 $this->tpl->setVariable(
172 "PLAYER",
173 $mpl->getMp3PlayerHtml()
174 );
175 $this->tpl->parseCurrentBlock();
176 }
177
178 // access
179 if ($enable_internal_rss) {
180 $this->tpl->setCurrentBlock("access");
181 $this->tpl->setVariable("TXT_ACCESS", $lng->txt("news_news_item_visibility"));
182 if ($a_set["visibility"] === NEWS_PUBLIC ||
183 ((int) $a_set["priority"] === 0 &&
185 "news",
186 "public_notifications",
187 0,
188 $obj_id
189 ))) {
190 $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_public"));
191 } else {
192 $this->tpl->setVariable("VAL_ACCESS", $lng->txt("news_visibility_users"));
193 }
194 $this->tpl->parseCurrentBlock();
195 }
196
197 // content
198 if ($a_set["content"] != "") {
199 $this->tpl->setCurrentBlock("content");
200 $this->tpl->setVariable(
201 "VAL_CONTENT",
202 nl2br($this->makeClickable(
204 $a_set["context_obj_type"],
205 $a_set["content"],
206 (bool) $a_set["content_text_is_lang_var"]
207 )
208 ))
209 );
210 $this->tpl->parseCurrentBlock();
211 }
212 if ($a_set["content_long"] != "") {
213 $this->tpl->setCurrentBlock("long");
214 $this->tpl->setVariable("VAL_LONG_CONTENT", ilUtil::makeClickable($a_set["content_long"], true));
215 $this->tpl->parseCurrentBlock();
216 }
217 if ($a_set["update_date"] != $a_set["creation_date"]) { // update date
218 $this->tpl->setCurrentBlock("ni_update");
219 $this->tpl->setVariable("TXT_LAST_UPDATE", $lng->txt("last_update"));
220 $this->tpl->setVariable(
221 "VAL_LAST_UPDATE",
223 );
224 $this->tpl->parseCurrentBlock();
225 }
226
227 // forum hack, not nice
228 $add = "";
229 if ($obj_type === "frm" && $a_set["context_sub_obj_type"] === "pos"
230 && $a_set["context_sub_obj_id"] > 0) {
231 $pos = $a_set["context_sub_obj_id"];
232 $thread = ilObjForumAccess::_getThreadForPosting((int) $pos);
233 if ($thread > 0) {
234 $add = "_" . $thread . "_" . $pos;
235 }
236 }
237
238 // file hack, not nice
239 if ($obj_type === "file") {
240 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_set["ref_id"]);
241 $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "sendfile");
242 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->std_request->getRefId());
243
244 $button = ilLinkButton::getInstance();
245 $button->setUrl($url);
246 $button->setCaption("download");
247
248 $this->tpl->setCurrentBlock("download");
249 $this->tpl->setVariable("BUTTON_DOWNLOAD", $button->render());
250 $this->tpl->parseCurrentBlock();
251 }
252
253 // wiki hack, not nice
254 if ($obj_type === "wiki" && $a_set["context_sub_obj_type"] === "wpg"
255 && $a_set["context_sub_obj_id"] > 0) {
256 $wptitle = ilWikiPage::lookupTitle((int) $a_set["context_sub_obj_id"]);
257 if ($wptitle != "") {
258 $add = "_" . ilWikiUtil::makeUrlTitle($wptitle);
259 }
260 }
261
262
263 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
264 $obj_type . "_" . $a_set["ref_id"] . $add;
265
266 // lm page hack, not nice
267 if ($a_set["context_sub_obj_type"] === "pg" &&
268 $a_set["context_sub_obj_id"] > 0 &&
269 in_array($obj_type, ["dbk", "lm"], true)) {
270 $url_target = "./goto.php?client_id=" . rawurlencode(CLIENT_ID) . "&target=" .
271 "pg_" . $a_set["context_sub_obj_id"] . "_" . $a_set["ref_id"];
272 }
273
274
275 $this->tpl->setCurrentBlock("context");
276 $cont_loc = new ilLocatorGUI();
277 $cont_loc->addContextItems($a_set["ref_id"], true);
278 $this->tpl->setVariable(
279 "CONTEXT_LOCATOR",
280 $cont_loc->getHTML()
281 );
282 $this->tpl->setVariable("HREF_CONTEXT_TITLE", $url_target);
283 $this->tpl->setVariable("CONTEXT_TITLE", $obj_title);
284 $this->tpl->setVariable(
285 "ALT_CONTEXT_TITLE",
286 $lng->txt("icon") . " " . $lng->txt("obj_" . $obj_type)
287 );
288 $this->tpl->setVariable(
289 "IMG_CONTEXT_TITLE",
290 ilObject::_getIcon((int) $a_set["context_obj_id"])
291 );
292 $this->tpl->parseCurrentBlock();
293
294 $this->tpl->setVariable("HREF_TITLE", $url_target);
295
296 // title
297 $this->tpl->setVariable(
298 "VAL_TITLE",
299 ilNewsItem::determineNewsTitle($a_set["context_obj_type"], $a_set["title"], $a_set["content_is_lang_var"])
300 );
301
302 // creation date
303 $this->tpl->setVariable(
304 "VAL_CREATION_DATE",
305 ilDatePresentation::formatDate(new ilDateTime($a_set["creation_date"], IL_CAL_DATETIME))
306 );
307 $this->tpl->setVariable("TXT_CREATED", $lng->txt("created"));
308
309 $this->tpl->parseCurrentBlock();
310 }
311
312 public function makeClickable(string $a_str): string
313 {
314 // this fixes bug 8744. We assume that strings that contain < and >
315 // already contain html, we do not handle these
316 if (is_int(strpos($a_str, ">")) && is_int(strpos($a_str, "<"))) {
317 return $a_str;
318 }
319
320 return ilUtil::makeClickable($a_str);
321 }
322}
const IL_CAL_DATETIME
const NEWS_AUDIO
const NEWS_PUBLIC
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
static _isAnonymized(int $a_obj_id)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupUserPDPeriod(int $a_user_id)
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=[])
Determine title for news item entry.
static _lookupDefaultPDPeriod()
static determineNewsContent(string $a_context_obj_type, string $a_content, bool $a_is_lang_var)
Determine new content.
static _getThreadForPosting(int $a_pos_id)
static _getDirectory(int $a_mob_id)
Get absolute directory.
User class.
static _lookupLogin(int $a_user_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 _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Personal desktop news table.
__construct(ilPDNewsGUI $a_parent_obj, string $a_parent_cmd, array $a_contexts, string $a_selected_context)
makeClickable(string $a_str)
StandardGUIRequest $std_request
fillRow(array $a_set)
Standard Version of Fill Row.
This class represents a selection list property in a property form.
static get(string $a_var)
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...
setIsDataTable(bool $a_val)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
ilLanguage $lng
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static makeClickable(string $a_text, bool $detectGotoLinks=false)
static lookupTitle(int $a_page_id)
static makeUrlTitle(string $a_par)
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
$post
Definition: ltitoken.php:49
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url