ILIAS  release_8 Revision v8.24
class.ilNewsTimelineItemGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected ilLanguage $lng;
30 protected ilObjUser $user;
31 protected bool $user_edit_all;
32 protected int $news_item_ref_id;
33 protected int $ref_id;
34 protected ilCtrl $ctrl;
37
38 protected function __construct(
39 ilNewsItem $a_news_item,
40 int $a_news_ref_id,
41 ilLikeGUI $a_like_gui
42 ) {
43 global $DIC;
44
45 $this->like_gui = $a_like_gui;
46 $this->lng = $DIC->language();
47 $this->ctrl = $DIC->ctrl();
48 $this->setNewsItem($a_news_item);
49 $this->user = $DIC->user();
50 $this->obj_def = $DIC["objDefinition"];
51 $this->news_item_ref_id = $a_news_ref_id;
52
53 $this->std_request = new StandardGUIRequest(
54 $DIC->http(),
55 $DIC->refinery()
56 );
57 $this->ref_id = $this->std_request->getRefId();
58 }
59
60 public static function getInstance(
61 ilNewsItem $a_news_item,
62 int $a_news_ref_id,
63 ilLikeGUI $a_like_gui
64 ): self {
65 return new self($a_news_item, $a_news_ref_id, $a_like_gui);
66 }
67
68 public function setNewsItem(ilNewsItem $a_val): void
69 {
70 $this->news_item = $a_val;
71 }
72
73 public function getNewsItem(): ilNewsItem
74 {
75 return $this->news_item;
76 }
77
81 public function setUserEditAll(bool $a_val): void
82 {
83 $this->user_edit_all = $a_val;
84 }
85
89 public function getUserEditAll(): bool
90 {
91 return $this->user_edit_all;
92 }
93
94 public function getDateTime(): ilDateTime
95 {
96 $i = $this->getNewsItem();
97 return new ilDateTime($i->getCreationDate(), IL_CAL_DATETIME);
98 }
99
100 public function render(): string
101 {
102 $i = $this->getNewsItem();
103 $tpl = new ilTemplate("tpl.timeline_item.html", true, true, "Services/News");
104
105 $news_renderer = ilNewsRendererFactory::getRenderer($i->getContextObjType());
106 $news_renderer->setLanguage($this->lng->getLangKey());
107 $news_renderer->setNewsItem($i, $this->news_item_ref_id);
108
109 $obj_id = $i->getContextObjId();
110
111 // edited?
112 if ($i->getCreationDate() !== $i->getUpdateDate()) {
113 $tpl->setCurrentBlock("edited");
114 $update_date = new ilDateTime($i->getUpdateDate(), IL_CAL_DATETIME);
115 $tpl->setVariable("TXT_EDITED", $this->lng->txt("cont_news_edited"));
116 if ($i->getUpdateUserId() > 0 && ($i->getUpdateUserId() !== $i->getUserId())) {
117 $tpl->setVariable("TXT_USR_EDITED", ilUserUtil::getNamePresentation(
118 $i->getUpdateUserId(),
119 false,
120 true,
121 $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
122 ) . " - ");
123 }
124 $tpl->setVariable("TIME_EDITED", ilDatePresentation::formatDate($update_date));
125 $tpl->parseCurrentBlock();
126 }
127
128 // context object link
129 if ($this->news_item_ref_id > 0 && $this->ref_id !== $this->news_item_ref_id) {
130 $tpl->setCurrentBlock("object");
131 $tpl->setVariable("OBJ_TITLE", ilObject::_lookupTitle($obj_id));
132 $tpl->setVariable("OBJ_IMG", ilObject::_getIcon($obj_id));
133 $tpl->setVariable("OBJ_HREF", $news_renderer->getObjectLink());
134 $tpl->parseCurrentBlock();
135 }
136
137 // media
138 if ($i->getMobId() > 0 && ilObject::_exists($i->getMobId())) {
139 $media = $this->renderMedia($i);
140 $tpl->setCurrentBlock("player");
141 $tpl->setVariable("PLAYER", $media);
142 $tpl->parseCurrentBlock();
143 }
144
145 $tpl->setVariable("USER_IMAGE", ilObjUser::_getPersonalPicturePath($i->getUserId(), "small"));
146 $tpl->setVariable(
147 "TITLE",
148 ilNewsItem::determineNewsTitle($i->getContextObjType(), $i->getTitle(), $i->getContentIsLangVar())
149 );
150
151 // content
152 $tpl->setVariable("CONTENT", $news_renderer->getTimelineContent());
153
154 $tpl->setVariable("TXT_USR", ilUserUtil::getNamePresentation(
155 $i->getUserId(),
156 false,
157 true,
158 $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
159 ));
160
161 $tpl->setVariable("TIME", ilDatePresentation::formatDate($this->getDateTime()));
162
163 // actions
164 $list = new ilAdvancedSelectionListGUI();
165 $list->setListTitle("");
166 $list->setId("news_tl_act_" . $i->getId());
168 $list->setUseImages(false);
169
170 if ($i->getPriority() === 1 && ($i->getUserId() === $this->user->getId() || $this->getUserEditAll())) {
171 if (!$news_renderer->preventEditing()) {
172 $list->addItem(
173 $this->lng->txt("edit"),
174 "",
175 "",
176 "",
177 "",
178 "",
179 "",
180 false,
181 "il.News.edit(" . $i->getId() . ");"
182 );
183 $list->addItem(
184 $this->lng->txt("delete"),
185 "",
186 "",
187 "",
188 "",
189 "",
190 "",
191 false,
192 "il.News.delete(" . $i->getId() . ");"
193 );
194 }
195 }
196
197 $news_renderer->addTimelineActions($list);
198
199 $tpl->setVariable("ACTIONS", $list->getHTML());
200
201 return $tpl->get();
202 }
203
204 protected function renderMedia(ilNewsItem $i): string
205 {
206 global $DIC;
207
208 $media_path = $this->getMediaPath($i);
209 $mime = ilObjMediaObject::getMimeType($media_path);
210
211 $ui_factory = $DIC->ui()->factory();
212 $ui_renderer = $DIC->ui()->renderer();
213
214 if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
215 $item_id = "il-news-modal-img-" . $i->getId();
216 $title = basename($media_path);
217 $image = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
218
219 $img_tpl = new ilTemplate("tpl.news_timeline_image_file.html", true, true, "Services/News");
220 $img_tpl->setVariable("ITEM_ID", $item_id);
221 $img_tpl->setVariable("IMAGE", $image);
222
223 $html = $img_tpl->get();
224 } elseif (in_array($mime, ["video/mp4"])) {
225 $video = $ui_factory->player()->video($media_path);
226 $html = $ui_renderer->render($video);
227 } elseif (in_array($mime, ["audio/mpeg"])) {
228 $audio = $ui_factory->player()->audio($media_path);
229 $html = $ui_renderer->render($audio);
230 } else {
231 // download?
232 $html = "";
233 }
234 return $html;
235 }
236
237 protected function renderMediaModal(ilNewsItem $i): string
238 {
239 global $DIC;
240
241 $media_path = $this->getMediaPath($i);
242 $mime = ilObjMediaObject::getMimeType($media_path);
243
244 $ui_factory = $DIC->ui()->factory();
245 $ui_renderer = $DIC->ui()->renderer();
246
247 $modal_html = "";
248
249 if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
250 $title = basename($media_path);
251 $item_id = "il-news-modal-img-" . $i->getId();
252 $image = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
253 $modal = ilModalGUI::getInstance();
254 $modal->setId($item_id);
255 $modal->setType(ilModalGUI::TYPE_LARGE);
256 $modal->setBody($image);
257 $modal->setHeading($title);
258 $modal_html = $modal->getHTML();
259 }
260 return $modal_html;
261 }
262
263 public function renderFooter(): string
264 {
265 $i = $this->getNewsItem();
266
267 // like
268 $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $i->getId());
269 $this->like_gui->setObject(
270 $i->getContextObjId(),
271 $i->getContextObjType(),
272 $i->getContextSubObjId(),
273 (string) $i->getContextSubObjType(),
274 $i->getId()
275 );
276 $html = $this->ctrl->getHTML($this->like_gui);
277
278 // comments
279 $notes_obj_type = ($i->getContextSubObjType() == "")
280 ? $i->getContextObjType()
281 : $i->getContextSubObjType();
282 $note_gui = new ilNoteGUI(
283 $i->getContextObjId(),
284 $i->getContextSubObjId(),
285 $notes_obj_type,
286 false,
287 $i->getId()
288 );
289 $note_gui->setDefaultCommand("getWidget");
290 $note_gui->setShowEmptyListMessage(false);
291 $note_gui->setShowHeader(false);
292 $html .= $this->ctrl->getHTML($note_gui);
293
294 $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $this->std_request->getNewsId());
295
296 return $html . $this->renderMediaModal($i);
297 }
298
299 protected function getMediaPath(ilNewsItem $i): string
300 {
301 $media_path = "";
302 if ($i->getMobId() > 0) {
303 $mob = new ilObjMediaObject($i->getMobId());
304 $med = $mob->getMediaItem("Standard");
305 if (strcasecmp("Reference", $med->getLocationType()) === 0) {
306 $media_path = $med->getLocation();
307 } else {
308 $media_path = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
309 }
310 }
311 return $media_path;
312 }
313}
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
language handling
User interface for like feature.
static getInstance()
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=[])
Determine title for news item entry.
static getRenderer(string $a_context_obj_type)
Single news timeline item.
setUserEditAll(bool $a_val)
Set user can edit other users postings.
static getInstance(ilNewsItem $a_news_item, int $a_news_ref_id, ilLikeGUI $a_like_gui)
__construct(ilNewsItem $a_news_item, int $a_news_ref_id, ilLikeGUI $a_like_gui)
getUserEditAll()
Get user can edit other users postings.
Notes GUI class.
static _getURL(int $a_mob_id)
get directory for files of media object
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
User class.
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
parses the objects.xml it handles the xml-description of all ilias objects
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)
special template class to simplify handling of ITX/PEAR
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41