ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilNewsTimelineItemGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected \ILIAS\News\InternalGUIService $gui;
28 protected \ILIAS\Notes\Service $notes;
29 protected ilLanguage $lng;
32 protected ilObjUser $user;
33 protected bool $user_edit_all;
34 protected int $news_item_ref_id;
35 protected int $ref_id;
36 protected ilCtrl $ctrl;
42 protected array $item_image = [];
46 protected array $item_modal = [];
47
48 protected function __construct(
49 ilNewsItem $a_news_item,
50 int $a_news_ref_id,
51 ilLikeGUI $a_like_gui
52 ) {
53 global $DIC;
54
55 $this->like_gui = $a_like_gui;
56 $this->lng = $DIC->language();
57 $this->ctrl = $DIC->ctrl();
58 $this->setNewsItem($a_news_item);
59 $this->user = $DIC->user();
60 $this->obj_def = $DIC["objDefinition"];
61 $this->news_item_ref_id = $a_news_ref_id;
62
63 $this->std_request = $DIC->news()
64 ->internal()
65 ->gui()
66 ->standardRequest();
67 $this->ref_id = $this->std_request->getRefId();
68 $this->gui = $DIC->news()
69 ->internal()
70 ->gui();
71 $this->notes = $DIC->notes();
72 }
73
74 public static function getInstance(
75 ilNewsItem $a_news_item,
76 int $a_news_ref_id,
77 ilLikeGUI $a_like_gui
78 ): self {
79 return new self($a_news_item, $a_news_ref_id, $a_like_gui);
80 }
81
82 public function setNewsItem(ilNewsItem $a_val): void
83 {
84 $this->news_item = $a_val;
85 }
86
87 public function getNewsItem(): ilNewsItem
88 {
89 return $this->news_item;
90 }
91
95 public function setUserEditAll(bool $a_val): void
96 {
97 $this->user_edit_all = $a_val;
98 }
99
103 public function getUserEditAll(): bool
104 {
105 return $this->user_edit_all;
106 }
107
108 public function getDateTime(): ilDateTime
109 {
110 $i = $this->getNewsItem();
111 return new ilDateTime($i->getCreationDate(), IL_CAL_DATETIME);
112 }
113
114 public function render(): string
115 {
116 $i = $this->getNewsItem();
117 $tpl = new ilTemplate("tpl.timeline_item.html", true, true, "components/ILIAS/News");
118 $ui_factory = $this->gui->ui()->factory();
119 $ui_renderer = $this->gui->ui()->renderer();
120
121 $news_renderer = ilNewsRendererFactory::getRenderer($i->getContextObjType());
122 $news_renderer->setLanguage($this->lng->getLangKey());
123 $news_renderer->setNewsItem($i, $this->news_item_ref_id);
124
125 $obj_id = $i->getContextObjId();
126
127 // edited?
128 if ($i->getCreationDate() !== $i->getUpdateDate()) {
129 $tpl->setCurrentBlock("edited");
130 $update_date = new ilDateTime($i->getUpdateDate(), IL_CAL_DATETIME);
131 $tpl->setVariable("TXT_EDITED", $this->lng->txt("cont_news_edited"));
132 if ($i->getUpdateUserId() > 0 && ($i->getUpdateUserId() !== $i->getUserId())) {
133 $tpl->setVariable("TXT_USR_EDITED", ilUserUtil::getNamePresentation(
134 $i->getUpdateUserId(),
135 false,
136 true,
137 $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
138 ) . " - ");
139 }
140 $tpl->setVariable("TIME_EDITED", ilDatePresentation::formatDate($update_date));
141 $tpl->parseCurrentBlock();
142 }
143
144 // context object link
145 if ($this->news_item_ref_id > 0 && $this->ref_id !== $this->news_item_ref_id) {
146 $tpl->setCurrentBlock("object");
147 $tpl->setVariable("OBJ_TITLE", ilObject::_lookupTitle($obj_id));
148 $tpl->setVariable("OBJ_IMG", ilObject::_getIcon($obj_id));
149 $tpl->setVariable("OBJ_HREF", $news_renderer->getObjectLink());
150 $tpl->parseCurrentBlock();
151 }
152
153 // media
154 if ($i->getMobId() > 0 && ilObject::_exists($i->getMobId())) {
155 $media = $this->renderMedia($i);
156 $tpl->setCurrentBlock("player");
157 $tpl->setVariable("PLAYER", $media);
158 $tpl->parseCurrentBlock();
159 }
160
161 $p = $this->gui->profile();
162 $tpl->setVariable("USER_AVATAR", $this->gui->ui()->renderer()->render(
163 $p->getAvatar($i->getUserId())
164 ));
165 $tpl->setVariable(
166 "TITLE",
167 ilNewsItem::determineNewsTitle($i->getContextObjType(), $i->getTitle(), $i->getContentIsLangVar())
168 );
169
170 // content
171 $tpl->setVariable("CONTENT", $news_renderer->getTimelineContent());
172
173 $tpl->setVariable("TXT_USR", $p->getNamePresentation(
174 $i->getUserId(),
175 true,
176 $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
177 ));
178
179 $tpl->setVariable("TIME", ilDatePresentation::formatDate($this->getDateTime()));
180
181 // actions
182 $actions = [];
183
184 if ($i->getPriority() === 1 && ($i->getUserId() === $this->user->getId() || $this->getUserEditAll())) {
185 if (!$news_renderer->preventEditing()) {
186 $actions[] = $ui_factory->button()->shy(
187 $this->lng->txt("edit"),
188 ""
189 )->withOnLoadCode(static function ($id) use ($i) {
190 return "document.getElementById('$id').addEventListener('click', () => {il.News.edit(" . $i->getId() . ");});";
191 });
192 $actions[] = $ui_factory->button()->shy(
193 $this->lng->txt("delete"),
194 ""
195 )->withOnLoadCode(static function ($id) use ($i) {
196 return "document.getElementById('$id').addEventListener('click', () => {il.News.delete(" . $i->getId() . ");});";
197 });
198 }
199 }
200 foreach ($news_renderer->getTimelineActions() as $action) {
201 $actions[] = $action;
202 }
203 $dd = $ui_factory->dropdown()->standard($actions);
204 $tpl->setVariable("ACTIONS", $ui_renderer->render($dd));
205
206 return $tpl->get();
207 }
208
209 protected function renderMedia(ilNewsItem $i): string
210 {
211 $media_path = $this->getMediaPath($i);
212 $mime = ilObjMediaObject::getMimeType($media_path);
213
214 $ui_factory = $this->gui->ui()->factory();
215 $ui_renderer = $this->gui->ui()->renderer();
216
217 if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
218 if (isset($this->item_image[$i->getId()]) && isset($this->item_modal[$i->getId()])) {
219 $image = $this->item_image[$i->getId()];
220 } else {
221 $title = basename($media_path);
222 $image = $ui_factory->image()->responsive($media_path, $title);
223 $modal_page = $ui_factory->modal()->lightboxImagePage($image, $title);
224 $modal = $ui_factory->modal()->lightbox($modal_page);
225 $image = $image->withAction($modal->getShowSignal());
226 $this->item_image[$i->getId()] = $image;
227 $this->item_modal[$i->getId()] = $modal;
228 }
229 $html = $ui_renderer->render($image);
230 } elseif (in_array($mime, ["video/mp4", "video/youtube", "video/vimeo"])) {
231 $video = $ui_factory->player()->video($media_path);
232 $html = $ui_renderer->render($video);
233 } elseif (in_array($mime, ["audio/mpeg"])) {
234 $audio = $ui_factory->player()->audio($media_path);
235 $html = $ui_renderer->render($audio);
236 } elseif (in_array($mime, ["application/pdf"])) {
237 $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $i->getId());
238 $link = $ui_factory->link()->standard(
239 basename($media_path),
240 $this->ctrl->getLinkTargetByClass("ilnewstimelinegui", "downloadMob")
241 );
242 $html = $ui_renderer->render($link);
243 $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", null);
244 } else {
245 $html = "";
246 }
247 return $html;
248 }
249
250 protected function renderMediaModal(ilNewsItem $i): string
251 {
252 $ui_factory = $this->gui->ui()->factory();
253 $ui_renderer = $this->gui->ui()->renderer();
254
255 if (isset($this->item_image[$i->getId()]) && isset($this->item_modal[$i->getId()])) {
256 $modal = $this->item_modal[$i->getId()];
257 return $ui_renderer->render($modal);
258 }
259
260 $media_path = $this->getMediaPath($i);
261 $mime = ilObjMediaObject::getMimeType($media_path);
262
263 $modal_html = "";
264
265 if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
266 $title = basename($media_path);
267 $image = $ui_factory->image()->responsive($media_path, $title);
268 $modal_page = $ui_factory->modal()->lightboxImagePage($image, $title);
269 $modal = $ui_factory->modal()->lightbox($modal_page);
270 $image = $image->withAction($modal->getShowSignal());
271 $this->item_image[$i->getId()] = $image;
272 $this->item_modal[$i->getId()] = $modal;
273 $modal_html = $ui_renderer->render($modal);
274 }
275 return $modal_html;
276 }
277
278 public function renderFooter(): string
279 {
280 $i = $this->getNewsItem();
281
282 // like
283 $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $i->getId());
284 $this->like_gui->setObject(
285 $i->getContextObjId(),
286 $i->getContextObjType(),
287 $i->getContextSubObjId(),
288 (string) $i->getContextSubObjType(),
289 $i->getId()
290 );
291 $html = $this->ctrl->getHTML($this->like_gui);
292
293 // comments
294 $notes_obj_type = ($i->getContextSubObjType() == "")
295 ? $i->getContextObjType()
296 : $i->getContextSubObjType();
297 $comments_gui = $this->notes->gui()->getCommentsGUI(
298 $i->getContextObjId(),
299 $i->getContextSubObjId(),
300 $notes_obj_type,
301 $i->getId()
302 );
303 $comments_gui->setDefaultCommand("getWidget");
304 $comments_gui->setShowEmptyListMessage(false);
305 $comments_gui->setShowHeader(false);
306 $html .= $comments_gui->getWidget();
307 //$html .= $this->ctrl->getHTML($comments_gui);
308
309 $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $this->std_request->getNewsId());
310 return $html . $this->renderMediaModal($i);
311 }
312
313 protected function getMediaPath(ilNewsItem $i): string
314 {
315 $media_path = "";
316 if ($i->getMobId() > 0) {
317 $mob = new ilObjMediaObject($i->getMobId());
318 $media_path = $mob->getStandardSrc();
319 }
320 return $media_path;
321 }
322}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_DATETIME
Class ilCtrl provides processing control methods.
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
language handling
User interface for like feature.
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 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.
ILIAS News InternalGUIService $gui
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
User class.
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=null)
Default behaviour is:
return['delivery_method'=> 'php',]
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...
global $DIC
Definition: shib_login.php:26