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