ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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;
37  protected ilLikeGUI $like_gui;
39 
40  protected function __construct(
41  ilNewsItem $a_news_item,
42  int $a_news_ref_id,
43  ilLikeGUI $a_like_gui
44  ) {
45  global $DIC;
46 
47  $this->like_gui = $a_like_gui;
48  $this->lng = $DIC->language();
49  $this->ctrl = $DIC->ctrl();
50  $this->setNewsItem($a_news_item);
51  $this->user = $DIC->user();
52  $this->obj_def = $DIC["objDefinition"];
53  $this->news_item_ref_id = $a_news_ref_id;
54 
55  $this->std_request = $DIC->news()
56  ->internal()
57  ->gui()
58  ->standardRequest();
59  $this->ref_id = $this->std_request->getRefId();
60  $this->gui = $DIC->news()
61  ->internal()
62  ->gui();
63  $this->notes = $DIC->notes();
64  }
65 
66  public static function getInstance(
67  ilNewsItem $a_news_item,
68  int $a_news_ref_id,
69  ilLikeGUI $a_like_gui
70  ): self {
71  return new self($a_news_item, $a_news_ref_id, $a_like_gui);
72  }
73 
74  public function setNewsItem(ilNewsItem $a_val): void
75  {
76  $this->news_item = $a_val;
77  }
78 
79  public function getNewsItem(): ilNewsItem
80  {
81  return $this->news_item;
82  }
83 
87  public function setUserEditAll(bool $a_val): void
88  {
89  $this->user_edit_all = $a_val;
90  }
91 
95  public function getUserEditAll(): bool
96  {
97  return $this->user_edit_all;
98  }
99 
100  public function getDateTime(): ilDateTime
101  {
102  $i = $this->getNewsItem();
103  return new ilDateTime($i->getCreationDate(), IL_CAL_DATETIME);
104  }
105 
106  public function render(): string
107  {
108  $i = $this->getNewsItem();
109  $tpl = new ilTemplate("tpl.timeline_item.html", true, true, "Services/News");
110  $ui_factory = $this->gui->ui()->factory();
111  $ui_renderer = $this->gui->ui()->renderer();
112 
113  $news_renderer = ilNewsRendererFactory::getRenderer($i->getContextObjType());
114  $news_renderer->setLanguage($this->lng->getLangKey());
115  $news_renderer->setNewsItem($i, $this->news_item_ref_id);
116 
117  $obj_id = $i->getContextObjId();
118 
119  // edited?
120  if ($i->getCreationDate() !== $i->getUpdateDate()) {
121  $tpl->setCurrentBlock("edited");
122  $update_date = new ilDateTime($i->getUpdateDate(), IL_CAL_DATETIME);
123  $tpl->setVariable("TXT_EDITED", $this->lng->txt("cont_news_edited"));
124  if ($i->getUpdateUserId() > 0 && ($i->getUpdateUserId() !== $i->getUserId())) {
125  $tpl->setVariable("TXT_USR_EDITED", ilUserUtil::getNamePresentation(
126  $i->getUpdateUserId(),
127  false,
128  true,
129  $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
130  ) . " - ");
131  }
132  $tpl->setVariable("TIME_EDITED", ilDatePresentation::formatDate($update_date));
133  $tpl->parseCurrentBlock();
134  }
135 
136  // context object link
137  if ($this->news_item_ref_id > 0 && $this->ref_id !== $this->news_item_ref_id) {
138  $tpl->setCurrentBlock("object");
139  $tpl->setVariable("OBJ_TITLE", ilObject::_lookupTitle($obj_id));
140  $tpl->setVariable("OBJ_IMG", ilObject::_getIcon($obj_id));
141  $tpl->setVariable("OBJ_HREF", $news_renderer->getObjectLink());
142  $tpl->parseCurrentBlock();
143  }
144 
145  // media
146  if ($i->getMobId() > 0 && ilObject::_exists($i->getMobId())) {
147  $media = $this->renderMedia($i);
148  $tpl->setCurrentBlock("player");
149  $tpl->setVariable("PLAYER", $media);
150  $tpl->parseCurrentBlock();
151  }
152 
153  $p = $this->gui->profile();
154  $tpl->setVariable("USER_AVATAR", $this->gui->ui()->renderer()->render(
155  $p->getAvatar($i->getUserId())
156  ));
157  $tpl->setVariable(
158  "TITLE",
159  ilNewsItem::determineNewsTitle($i->getContextObjType(), $i->getTitle(), $i->getContentIsLangVar())
160  );
161 
162  // content
163  $tpl->setVariable("CONTENT", $news_renderer->getTimelineContent());
164 
165  $tpl->setVariable("TXT_USR", $p->getNamePresentation(
166  $i->getUserId(),
167  true,
168  $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
169  ));
170 
171  $tpl->setVariable("TIME", ilDatePresentation::formatDate($this->getDateTime()));
172 
173  // actions
174  $actions = [];
175 
176  if ($i->getPriority() === 1 && ($i->getUserId() === $this->user->getId() || $this->getUserEditAll())) {
177  if (!$news_renderer->preventEditing()) {
178  $actions[] = $ui_factory->button()->shy(
179  $this->lng->txt("edit"),
180  ""
181  )->withOnLoadCode(static function ($id) use ($i) {
182  return "document.getElementById('$id').addEventListener('click', () => {il.News.edit(" . $i->getId() . ");});";
183  });
184  $actions[] = $ui_factory->button()->shy(
185  $this->lng->txt("delete"),
186  ""
187  )->withOnLoadCode(static function ($id) use ($i) {
188  return "document.getElementById('$id').addEventListener('click', () => {il.News.delete(" . $i->getId() . ");});";
189  });
190  }
191  }
192  foreach ($news_renderer->getTimelineActions() as $action) {
193  $actions[] = $action;
194  }
195  $dd = $ui_factory->dropdown()->standard($actions);
196  $tpl->setVariable("ACTIONS", $ui_renderer->render($dd));
197 
198  return $tpl->get();
199  }
200 
201  protected function renderMedia(ilNewsItem $i): string
202  {
203  global $DIC;
204 
205  $media_path = $this->getMediaPath($i);
206  $mime = ilObjMediaObject::getMimeType($media_path);
207 
208  $ui_factory = $DIC->ui()->factory();
209  $ui_renderer = $DIC->ui()->renderer();
210 
211  if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
212  $item_id = "il-news-modal-img-" . $i->getId();
213  $title = basename($media_path);
214  $image = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
215 
216  $img_tpl = new ilTemplate("tpl.news_timeline_image_file.html", true, true, "Services/News");
217  $img_tpl->setVariable("ITEM_ID", $item_id);
218  $img_tpl->setVariable("IMAGE", $image);
219 
220  $html = $img_tpl->get();
221  } elseif (in_array($mime, ["video/mp4", "video/youtube", "video/vimeo"])) {
222  $video = $ui_factory->player()->video($media_path);
223  $html = $ui_renderer->render($video);
224  } elseif (in_array($mime, ["audio/mpeg"])) {
225  $audio = $ui_factory->player()->audio($media_path);
226  $html = $ui_renderer->render($audio);
227  } elseif (in_array($mime, ["application/pdf"])) {
228  $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $i->getId());
229  $link = $ui_factory->link()->standard(
230  basename($media_path),
231  $this->ctrl->getLinkTargetByClass("ilnewstimelinegui", "downloadMob")
232  );
233  $html = $ui_renderer->render($link);
234  $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", null);
235  } else {
236  $html = "";
237  }
238  return $html;
239  }
240 
241  protected function renderMediaModal(ilNewsItem $i): string
242  {
243  global $DIC;
244 
245  $media_path = $this->getMediaPath($i);
246  $mime = ilObjMediaObject::getMimeType($media_path);
247 
248  $ui_factory = $DIC->ui()->factory();
249  $ui_renderer = $DIC->ui()->renderer();
250 
251  $modal_html = "";
252 
253  if (in_array($mime, ["image/jpeg", "image/svg+xml", "image/gif", "image/png"])) {
254  $title = basename($media_path);
255  $item_id = "il-news-modal-img-" . $i->getId();
256  $image = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
257  $modal = ilModalGUI::getInstance();
258  $modal->setId($item_id);
259  $modal->setType(ilModalGUI::TYPE_LARGE);
260  $modal->setBody($image);
261  $modal->setHeading($title);
262  $modal_html = $modal->getHTML();
263  }
264  return $modal_html;
265  }
266 
267  public function renderFooter(): string
268  {
269  $i = $this->getNewsItem();
270 
271  // like
272  $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $i->getId());
273  $this->like_gui->setObject(
274  $i->getContextObjId(),
275  $i->getContextObjType(),
276  $i->getContextSubObjId(),
277  (string) $i->getContextSubObjType(),
278  $i->getId()
279  );
280  $html = $this->ctrl->getHTML($this->like_gui);
281 
282  // comments
283  $notes_obj_type = ($i->getContextSubObjType() == "")
284  ? $i->getContextObjType()
285  : $i->getContextSubObjType();
286  $comments_gui = $this->notes->gui()->getCommentsGUI(
287  $i->getContextObjId(),
288  $i->getContextSubObjId(),
289  $notes_obj_type,
290  $i->getId()
291  );
292  $comments_gui->setDefaultCommand("getWidget");
293  $comments_gui->setShowEmptyListMessage(false);
294  $comments_gui->setShowHeader(false);
295  $html .= $comments_gui->getWidget();
296  //$html .= $this->ctrl->getHTML($comments_gui);
297 
298  $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $this->std_request->getNewsId());
299 
300  return $html . $this->renderMediaModal($i);
301  }
302 
303  protected function getMediaPath(ilNewsItem $i): string
304  {
305  $media_path = "";
306  if ($i->getMobId() > 0) {
307  $mob = new ilObjMediaObject($i->getMobId());
308  $med = $mob->getMediaItem("Standard");
309  if (strcasecmp("Reference", $med->getLocationType()) === 0) {
310  $media_path = $med->getLocation();
311  } else {
312  $media_path = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
313  }
314  }
315  return $media_path;
316  }
317 }
Single news timeline item.
getUserEditAll()
Get user can edit other users postings.
const IL_CAL_DATETIME
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
__construct(ilNewsItem $a_news_item, int $a_news_ref_id, ilLikeGUI $a_like_gui)
static getRenderer(string $a_context_obj_type)
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
setUserEditAll(bool $a_val)
Set user can edit other users postings.
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
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:
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
static _lookupTitle(int $obj_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=[], ?ilLanguage $lng=null)
Determine title for news item entry.
getMediaItem(string $a_purpose)
get item for media purpose
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS News InternalGUIService $gui
static getInstance()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A news item can be created by different sources.
static getInstance(ilNewsItem $a_news_item, int $a_news_ref_id, ilLikeGUI $a_like_gui)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getURL(int $a_mob_id)
get directory for files of media object
User interface for like feature.