ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilNewsTimelineItemGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
17  protected $lng;
18 
22  protected $news_item;
23 
27  protected $obj_def;
28 
32  protected $user;
33 
37  protected $user_edit_all;
38 
44  protected $news_item_ref_id;
45 
50  protected $ref_id;
51 
55  protected $ctrl;
56 
60  protected $like_gui;
61 
69  protected function __construct(ilNewsItem $a_news_item, $a_news_ref_id, \ilLikeGUI $a_like_gui)
70  {
71  global $DIC;
72 
73  $this->like_gui = $a_like_gui;
74 
75  $this->lng = $DIC->language();
76  $this->ctrl = $DIC->ctrl();
77  $this->setNewsItem($a_news_item);
78  $this->user = $DIC->user();
79  $this->obj_def = $DIC["objDefinition"];
80  $this->news_item_ref_id = $a_news_ref_id;
81 
82  $this->ref_id = (int) $_GET["ref_id"];
83  }
84 
91  public static function getInstance(ilNewsItem $a_news_item, $a_news_ref_id, \ilLikeGUI $a_like_gui)
92  {
93  return new self($a_news_item, $a_news_ref_id, $a_like_gui);
94  }
95 
96 
102  public function setNewsItem(ilNewsItem $a_val)
103  {
104  $this->news_item = $a_val;
105  }
106 
112  public function getNewsItem()
113  {
114  return $this->news_item;
115  }
116 
122  public function setUserEditAll($a_val)
123  {
124  $this->user_edit_all = $a_val;
125  }
126 
132  public function getUserEditAll()
133  {
134  return $this->user_edit_all;
135  }
136 
140  public function getDateTime()
141  {
142  $i = $this->getNewsItem();
143  return new ilDateTime($i->getCreationDate(), IL_CAL_DATETIME);
144  }
145 
146 
150  public function render()
151  {
152  $i = $this->getNewsItem();
153  $tpl = new ilTemplate("tpl.timeline_item.html", true, true, "Services/News");
154 
155  include_once("./Services/News/classes/class.ilNewsRendererFactory.php");
156  $news_renderer = ilNewsRendererFactory::getRenderer($i->getContextObjType());
157  $news_renderer->setLanguage($this->lng->getLangKey());
158  $news_renderer->setNewsItem($i, $this->news_item_ref_id);
159 
160  $obj_id = $i->getContextObjId();
161 
162  // edited?
163  if ($i->getCreationDate() != $i->getUpdateDate()) {
164  $tpl->setCurrentBlock("edited");
165  $update_date = new ilDateTime($i->getUpdateDate(), IL_CAL_DATETIME);
166  $tpl->setVariable("TXT_EDITED", $this->lng->txt("cont_news_edited"));
167  if ($i->getUpdateUserId() > 0 && ($i->getUpdateUserId() != $i->getUserId())) {
168  include_once("./Services/User/classes/class.ilUserUtil.php");
169  $tpl->setVariable("TXT_USR_EDITED", ilUserUtil::getNamePresentation(
170  $i->getUpdateUserId(),
171  false,
172  true,
173  $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
174  ) . " - ");
175  }
176  include_once("./Services/Calendar/classes/class.ilDatePresentation.php");
177  $tpl->setVariable("TIME_EDITED", ilDatePresentation::formatDate($update_date));
178  $tpl->parseCurrentBlock();
179  }
180 
181 
182  // context object link
183  include_once("./Services/Link/classes/class.ilLink.php");
184  if ($this->news_item_ref_id > 0 && $this->ref_id != $this->news_item_ref_id) {
185  $tpl->setCurrentBlock("object");
186  $tpl->setVariable("OBJ_TITLE", ilObject::_lookupTitle($obj_id));
187  $tpl->setVariable("OBJ_IMG", ilObject::_getIcon($obj_id));
188  $tpl->setVariable("OBJ_HREF", $news_renderer->getObjectLink());
189  $tpl->parseCurrentBlock();
190  }
191 
192  // media
193  if ($i->getMobId() > 0 && ilObject::_exists($i->getMobId())) {
194  $media = $this->renderMedia($i);
195  $tpl->setCurrentBlock("player");
196  $tpl->setVariable("PLAYER", $media);
197  $tpl->parseCurrentBlock();
198  }
199 
200  $tpl->setVariable("USER_IMAGE", ilObjUser::_getPersonalPicturePath($i->getUserId(), "xsmall"));
201  $tpl->setVariable(
202  "TITLE",
203  ilNewsItem::determineNewsTitle($i->getContextObjType(), $i->getTitle(), $i->getContentIsLangVar())
204  );
205 
206  // content
207  $tpl->setVariable("CONTENT", $news_renderer->getTimelineContent());
208 
209  include_once("./Services/User/classes/class.ilUserUtil.php");
210  $tpl->setVariable("TXT_USR", ilUserUtil::getNamePresentation(
211  $i->getUserId(),
212  false,
213  true,
214  $this->ctrl->getLinkTargetByClass("ilnewstimelinegui")
215  ));
216 
217  include_once("./Services/Calendar/classes/class.ilDatePresentation.php");
218  $tpl->setVariable("TIME", ilDatePresentation::formatDate($this->getDateTime()));
219 
220  // actions
221  include_once("Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
223  $list->setListTitle("");
224  $list->setId("news_tl_act_" . $i->getId());
225  //$list->setSelectionHeaderClass("small");
226  //$list->setItemLinkClass("xsmall");
227  //$list->setLinksMode("il_ContainerItemCommand2");
229  $list->setUseImages(false);
230 
231  if ($i->getPriority() == 1 && ($i->getUserId() == $this->user->getId() || $this->getUserEditAll())) {
232  $list->addItem(
233  $this->lng->txt("edit"),
234  "",
235  "",
236  "",
237  "",
238  "",
239  "",
240  false,
241  "il.News.edit(" . $i->getId() . ");"
242  );
243  $list->addItem(
244  $this->lng->txt("delete"),
245  "",
246  "",
247  "",
248  "",
249  "",
250  "",
251  false,
252  "il.News.delete(" . $i->getId() . ");"
253  );
254  }
255 
256  $news_renderer->addTimelineActions($list);
257 
258  $tpl->setVariable("ACTIONS", $list->getHTML());
259 
260  return $tpl->get();
261  }
262 
269  protected function renderMedia(ilNewsItem $i)
270  {
271  global $DIC;
272 
273  $media_path = $this->getMediaPath($i);
274  $mime = ilObjMediaObject::getMimeType($media_path);
275 
276  $ui_factory = $DIC->ui()->factory();
277  $ui_renderer = $DIC->ui()->renderer();
278 
279  if (in_array($mime, array("image/jpeg", "image/svg+xml", "image/gif", "image/png"))) {
280  $item_id = "il-news-modal-img-" . $i->getId();
281  $title = basename($media_path);
282  $image = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
283 
284  $img_tpl = new ilTemplate("tpl.news_timeline_image_file.html", true, true, "Services/News");
285  $img_tpl->setVariable("ITEM_ID", $item_id);
286  $img_tpl->setVariable("IMAGE", $image);
287 
288  $html = $img_tpl->get();
289  } elseif (in_array($mime, array("audio/mpeg", "audio/ogg", "video/mp4", "video/x-flv", "video/webm"))) {
290  $mp = new ilMediaPlayerGUI();
291  $mp->setFile($media_path);
292  $mp->setDisplayHeight(200);
293  $html = $mp->getMediaPlayerHtml();
294  } else {
295  // download?
296  $html = "";
297  }
298  return $html;
299  }
300 
307  protected function renderMediaModal(ilNewsItem $i)
308  {
309  global $DIC;
310 
311  $media_path = $this->getMediaPath($i);
312  $mime = ilObjMediaObject::getMimeType($media_path);
313 
314  $ui_factory = $DIC->ui()->factory();
315  $ui_renderer = $DIC->ui()->renderer();
316 
317  $modal_html = "";
318 
319  if (in_array($mime, array("image/jpeg", "image/svg+xml", "image/gif", "image/png"))) {
320  $title = basename($media_path);
321  $item_id = "il-news-modal-img-" . $i->getId();
322  $image = $ui_renderer->render($ui_factory->image()->responsive($media_path, $title));
323  $modal = ilModalGUI::getInstance();
324  $modal->setId($item_id);
325  $modal->setType(ilModalGUI::TYPE_LARGE);
326  $modal->setBody($image);
327  $modal->setHeading($title);
328  $modal_html = $modal->getHTML();
329  }
330  return $modal_html;
331  }
332 
333 
338  public function renderFooter()
339  {
340  $i = $this->getNewsItem();
341 
342  // like
343  $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $i->getId());
344  $this->like_gui->setObject(
345  $i->getContextObjId(),
346  $i->getContextObjType(),
347  $i->getContextSubObjId(),
348  $i->getContextSubObjType(),
349  $i->getId()
350  );
351  $html = $this->ctrl->getHTML($this->like_gui);
352 
353  // comments
354  $notes_obj_type = ($i->getContextSubObjType() == "")
355  ? $i->getContextObjType()
356  : $i->getContextSubObjType();
357  $note_gui = new ilNoteGUI(
358  $i->getContextObjId(),
359  $i->getContextSubObjId(),
360  $notes_obj_type,
361  false,
362  $i->getId()
363  );
364  $note_gui->setDefaultCommand("getWidget");
365 
366  //ilNoteGUI::getListCommentsJSCall($this->ajax_hash, $redraw_js)
367  $html .= $this->ctrl->getHTML($note_gui);
368 
369  $this->ctrl->setParameterByClass("ilnewstimelinegui", "news_id", $_GET["news_id"]);
370 
371  return $html . $this->renderMediaModal($i);
372  }
373 
378  protected function getMediaPath(ilNewsItem $i)
379  {
380  $media_path = "";
381  if ($i->getMobId() > 0) {
382  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
383  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
384  $mob = new ilObjMediaObject($i->getMobId());
385  $med = $mob->getMediaItem("Standard");
386  if (strcasecmp("Reference", $med->getLocationType()) == 0) {
387  $media_path = $med->getLocation();
388  } else {
389  $media_path = ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation();
390  }
391  }
392  return $media_path;
393  }
394 }
Single news timeline item.
renderMediaModal(ilNewsItem $i)
Render media.
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
getUserEditAll()
Get user can edit other users postings.
getDateTime()
Get datetime.ilDateTime timestamp
static getMimeType($a_file, $a_external=null)
get mime type for file
& getMediaItem($a_purpose)
get item for media purpose
const IL_CAL_DATETIME
getMobId()
Get MobId.
global $DIC
Definition: saml.php:7
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
$_GET["client_id"]
$tpl
Definition: ilias.php:10
render()
Render item.string html
static _lookupTitle($a_id)
lookup object title
renderMedia(ilNewsItem $i)
Render media.
static _getURL($a_mob_id)
get directory for files of media object (static)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
__construct(ilNewsItem $a_news_item, $a_news_ref_id, \ilLikeGUI $a_like_gui)
Constructor.
user()
Definition: user.php:4
static getInstance(ilNewsItem $a_news_item, $a_news_ref_id, \ilLikeGUI $a_like_gui)
Get instance.
Notes GUI class.
getId()
Get Id.
special template class to simplify handling of ITX/PEAR
Date and time handling
Class ilObjMediaObject.
Interface for timeline items.
setUserEditAll($a_val)
Set user can edit other users postings.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
User interface class for advanced drop-down selection lists.
static getInstance()
Get instance.
User interface for media player.
static getRenderer($a_context_obj_type)
Get renderer.
$i
Definition: disco.tpl.php:19
static determineNewsTitle( $a_context_obj_type, $a_title, $a_content_is_lang_var, $a_agg_ref_id=0, $a_aggregation="")
Determine title for news item entry.
User interface for like feature.
$html
Definition: example_001.php:87
setNewsItem(ilNewsItem $a_val)
Set news item.
setDefaultCommand($a_val)
Set default command.