ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilNewsTimelineGUI Class Reference

Timeline for news. More...

+ Collaboration diagram for ilNewsTimelineGUI:

Public Member Functions

 setUserEditAll ($a_val)
 Set user can edit other users postings. More...
 
 getUserEditAll ()
 Get user can edit other users postings. More...
 
 executeCommand ()
 Execute command. More...
 
 show ()
 Show. More...
 
 loadMore ()
 Load more. More...
 
 save ()
 Save (ajax) More...
 
 update ()
 Update (ajax) More...
 
 remove ()
 Remove (ajax) More...
 

Static Public Member Functions

static getInstance ($a_ref_id, $a_include_auto_entries)
 Get instance. More...
 

Protected Member Functions

 __construct ($a_ref_id, $a_include_auto_entries)
 Constructor. More...
 
 updateNewsItem ()
 
 getEditModal ()
 Get edit modal. More...
 
 getDeleteModal ()
 Get delete modal. More...
 

Protected Attributes

 $ctrl
 
 $tpl
 
 $ref_id
 
 $lng
 
 $toolbar
 
 $user
 
 $access
 
 $user_edit_all = false
 

Static Protected Attributes

static $items_per_load = 10
 

Detailed Description

Timeline for news.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

ilNewsTimelineGUI: ilLikeGUI, ilNoteGUI

Definition at line 15 of file class.ilNewsTimelineGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilNewsTimelineGUI::__construct (   $a_ref_id,
  $a_include_auto_entries 
)
protected

Constructor.

Parameters
int$a_ref_idreference id

Definition at line 67 of file class.ilNewsTimelineGUI.php.

References $_GET, $DIC, and user().

68  {
69  global $DIC;
70 
71  $this->ctrl = $DIC->ctrl();
72  $this->tpl = $DIC["tpl"];
73  $this->ref_id = $a_ref_id;
74  $this->lng = $DIC->language();
75  $this->toolbar = $DIC->toolbar();
76  $this->user = $DIC->user();
77  $this->include_auto_entries = $a_include_auto_entries;
78  $this->access = $DIC->access();
79 
80  $this->news_id = (int) $_GET["news_id"];
81 
82 
83  $this->lng->loadLanguageModule("news");
84  }
global $DIC
Definition: saml.php:7
$_GET["client_id"]
user()
Definition: user.php:4
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilNewsTimelineGUI::executeCommand ( )

Execute command.

Exceptions
ilCtrlException

Definition at line 122 of file class.ilNewsTimelineGUI.php.

References $ctrl, $i, and $ret.

123  {
124  $ctrl = $this->ctrl;
125 
126  $next_class = $this->ctrl->getNextClass($this);
127  $cmd = $this->ctrl->getCmd("show");
128 
129  switch ($next_class) {
130  case "illikegui":
131  $i = new ilNewsItem($this->news_id);
132  include_once("./Services/Like/classes/class.ilLikeFactoryGUI.php");
133  $likef = new ilLikeFactoryGUI();
134  $like_gui = $likef->widget(array($i->getContextObjId()));
135  $ctrl->saveParameter($this, "news_id");
136  $like_gui->setObject(
137  $i->getContextObjId(),
138  $i->getContextObjType(),
139  $i->getContextSubObjId(),
140  $i->getContextSubObjType(),
141  $this->news_id
142  );
143  $ret = $ctrl->forwardCommand($like_gui);
144  break;
145 
146  case "ilnotegui":
147  $i = new ilNewsItem($this->news_id);
148  $ctrl->saveParameter($this, "news_id");
149  $notes_obj_type = ($i->getContextSubObjType() == "")
150  ? $i->getContextObjType()
151  : $i->getContextSubObjType();
152  $note_gui = new ilNoteGUI(
153  $i->getContextObjId(),
154  $i->getContextSubObjId(),
155  $notes_obj_type,
156  false,
157  $i->getId()
158  );
159  $ret = $ctrl->forwardCommand($note_gui);
160  break;
161 
162  default:
163  if (in_array($cmd, array("show", "save", "update", "loadMore", "remove", "updateNewsItem"))) {
164  $this->$cmd();
165  }
166  }
167  }
Notes GUI class.
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19

◆ getDeleteModal()

ilNewsTimelineGUI::getDeleteModal ( )
protected

Get delete modal.

Returns
string modal html

Definition at line 490 of file class.ilNewsTimelineGUI.php.

References ilSubmitButton\getInstance(), ilModalGUI\getInstance(), and ilModalGUI\TYPE_LARGE.

Referenced by show().

491  {
492  include_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
493  $modal = ilModalGUI::getInstance();
494  $modal->setHeading($this->lng->txt("delete"));
495  $modal->setId("ilNewsDeleteModal");
496  $modal->setType(ilModalGUI::TYPE_LARGE);
497 
498  require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php';
499  $confirm = ilSubmitButton::getInstance();
500  $confirm->setCaption("delete");
501  $confirm->setId("news_btn_delete");
502  $modal->addButton($confirm);
503 
504  $cancel = ilSubmitButton::getInstance();
505  $cancel->setCaption("cancel");
506  $cancel->setId("news_btn_cancel_delete");
507  $modal->addButton($cancel);
508 
509  $modal->setBody("<p id='news_delete_news_title'></p>" .
510  $this->tpl->getMessageHTML($this->lng->txt("news_really_delete_news"), "question"));
511 
512  return $modal->getHTML();
513  }
static getInstance()
Get instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getEditModal()

ilNewsTimelineGUI::getEditModal ( )
protected

Get edit modal.

Returns
string modal html

Definition at line 459 of file class.ilNewsTimelineGUI.php.

References $form, ilNewsItemGUI\getEditForm(), ilModalGUI\getInstance(), IL_FORM_EDIT, and ilModalGUI\TYPE_LARGE.

Referenced by show().

460  {
461  include_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
462  $modal = ilModalGUI::getInstance();
463  $modal->setHeading($this->lng->txt("edit"));
464  $modal->setId("ilNewsEditModal");
465  $modal->setType(ilModalGUI::TYPE_LARGE);
466 
467  include_once("./Services/News/classes/class.ilNewsItemGUI.php");
469  $form->setShowTopButtons(false);
470  $form->setFormAction($this->ctrl->getFormAction($this));
471 
472 
473  //
474  $hi = new ilHiddenInputGUI("id");
475  $form->addItem($hi);
476  $act = new ilHiddenInputGUI("news_action");
477  $form->addItem($act);
478  $form->setId("news_edit_form");
479 
480  $modal->setBody($form->getHTML());
481 
482  return $modal->getHTML();
483  }
This class represents a hidden form property in a property form.
if(isset($_POST['submit'])) $form
static getInstance()
Get instance.
static getEditForm($a_mode, $a_ref_id)
FORM NewsItem: Init form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstance()

static ilNewsTimelineGUI::getInstance (   $a_ref_id,
  $a_include_auto_entries 
)
static

Get instance.

Parameters
int$a_ref_idreference id
Returns
ilNewsTimelineGUI

Definition at line 112 of file class.ilNewsTimelineGUI.php.

Referenced by ilObjGroupGUI\executeCommand(), and ilObjCourseGUI\executeCommand().

113  {
114  return new self($a_ref_id, $a_include_auto_entries);
115  }
+ Here is the caller graph for this function:

◆ getUserEditAll()

ilNewsTimelineGUI::getUserEditAll ( )

Get user can edit other users postings.

Returns
bool user can edit all postings

Definition at line 101 of file class.ilNewsTimelineGUI.php.

References $user_edit_all.

Referenced by loadMore(), remove(), and show().

102  {
103  return $this->user_edit_all;
104  }
+ Here is the caller graph for this function:

◆ loadMore()

ilNewsTimelineGUI::loadMore ( )

Load more.

Parameters

Definition at line 267 of file class.ilNewsTimelineGUI.php.

References $_POST, $d, ilJsonUtil\encode(), exit, ilTimelineGUI\getInstance(), ilNewsTimelineItemGUI\getInstance(), and getUserEditAll().

268  {
269  include_once("./Services/News/classes/class.ilNewsItem.php");
270  $news_item = new ilNewsItem();
271  $news_item->setContextObjId($this->ctrl->getContextObjId());
272  $news_item->setContextObjType($this->ctrl->getContextObjType());
273 
274  $excluded = $_POST["rendered_news"];
275 
276  $news_data = $news_item->getNewsForRefId(
277  $this->ref_id,
278  false,
279  false,
280  0,
281  true,
282  false,
283  !$this->include_auto_entries,
284  false,
285  null,
286  self::$items_per_load,
287  $excluded
288  );
289 
290  include_once("./Services/News/Timeline/classes/class.ilTimelineGUI.php");
291  include_once("./Services/News/classes/class.ilNewsTimelineItemGUI.php");
292  $timeline = ilTimelineGUI::getInstance();
293 
294  // get like widget
295  $obj_ids = array_unique(array_map(function ($a) {
296  return $a["context_obj_id"];
297  }, $news_data));
298  include_once("./Services/Like/classes/class.ilLikeFactoryGUI.php");
299  $likef = new ilLikeFactoryGUI();
300  $like_gui = $likef->widget($obj_ids);
301 
302  $js_items = array();
303  foreach ($news_data as $d) {
304  $news_item = new ilNewsItem($d["id"]);
305  $item = ilNewsTimelineItemGUI::getInstance($news_item, $d["ref_id"], $like_gui);
306  $item->setUserEditAll($this->getUserEditAll());
307  $timeline->addItem($item);
308  $js_items[$d["id"]] = array(
309  "id" => $d["id"],
310  "user_id" => $d["user_id"],
311  "title" => $d["title"],
312  "content" => $d["content"] . $d["content_long"],
313  "content_long" => "",
314  "priority" => $d["priority"],
315  "visibility" => $d["visibility"],
316  "content_type" => $d["content_type"],
317  "mob_id" => $d["mob_id"]
318  );
319  }
320 
321  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
322  $obj = new stdClass();
323  $obj->data = $js_items;
324  $obj->html = $timeline->render(true);
325 
326  echo ilJsonUtil::encode($obj);
327  exit;
328  }
static getInstance(ilNewsItem $a_news_item, $a_news_ref_id, \ilLikeGUI $a_like_gui)
Get instance.
static encode($mixed, $suppress_native=false)
exit
Definition: backend.php:16
static getInstance()
Get instance.
$_POST["username"]
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
getUserEditAll()
Get user can edit other users postings.
+ Here is the call graph for this function:

◆ remove()

ilNewsTimelineGUI::remove ( )

Remove (ajax)

Definition at line 444 of file class.ilNewsTimelineGUI.php.

References $_POST, exit, getUserEditAll(), and user().

445  {
446  include_once("./Services/News/classes/class.ilNewsItemGUI.php");
447  $news_item = new ilNewsItem((int) $_POST["id"]);
448  if ($this->user->getId() == $news_item->getUserId() || $this->getUserEditAll()) {
449  $news_item->delete();
450  }
451  exit;
452  }
user()
Definition: user.php:4
exit
Definition: backend.php:16
$_POST["username"]
getUserEditAll()
Get user can edit other users postings.
+ Here is the call graph for this function:

◆ save()

ilNewsTimelineGUI::save ( )

Save (ajax)

Definition at line 352 of file class.ilNewsTimelineGUI.php.

References $form, ilObject\_lookupObjectId(), ilObject\_lookupType(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilNewsItemGUI\getEditForm(), IL_FORM_CREATE, ilNewsItemGUI\isRteActivated(), and user().

Referenced by updateNewsItem().

353  {
354  include_once("./Services/News/classes/class.ilNewsItemGUI.php");
356  if ($form->checkInput()) {
357  $news_item = new ilNewsItem();
358  $news_item->setTitle($form->getInput("news_title"));
359  $news_item->setContent($form->getInput("news_content"));
360  $news_item->setVisibility($form->getInput("news_visibility"));
361  include_once("./Services/News/classes/class.ilNewsItemGUI.php");
363  $news_item->setContentHtml(true);
364  }
365  //$news_item->setContentLong($form->getInput("news_content_long"));
366  $news_item->setContentLong("");
367 
368  $obj_id = ilObject::_lookupObjectId($this->ref_id);
369  $obj_type = ilObject::_lookupType($obj_id);
370  $news_item->setContextObjId($obj_id);
371  $news_item->setContextObjType($obj_type);
372  $news_item->setUserId($this->user->getId());
373 
374  $media = $_FILES["media"];
375  if ($media["name"] != "") {
376  $mob = ilObjMediaObject::_saveTempFileAsMediaObject($media["name"], $media["tmp_name"], true);
377  $news_item->setMobId($mob->getId());
378  }
379 
380  $news_set = new ilSetting("news");
381  if (!$news_set->get("enable_rss_for_internal")) {
382  $news_item->setVisibility("users");
383  }
384 
385  $news_item->create();
386  }
387  }
static isRteActivated()
Is Rte activated.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
user()
Definition: user.php:4
static _lookupObjectId($a_ref_id)
lookup object id
if(isset($_POST['submit'])) $form
static _lookupType($a_id, $a_reference=false)
lookup object type
static getEditForm($a_mode, $a_ref_id)
FORM NewsItem: Init form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setUserEditAll()

ilNewsTimelineGUI::setUserEditAll (   $a_val)

Set user can edit other users postings.

Parameters
bool$a_valuser can edit all postings

Definition at line 91 of file class.ilNewsTimelineGUI.php.

92  {
93  $this->user_edit_all = $a_val;
94  }

◆ show()

ilNewsTimelineGUI::show ( )

Show.

Parameters

Definition at line 175 of file class.ilNewsTimelineGUI.php.

References $d, ilJsonUtil\encode(), getDeleteModal(), getEditModal(), ilUtil\getImagePath(), ilLinkButton\getInstance(), ilTimelineGUI\getInstance(), ilNewsTimelineItemGUI\getInstance(), getUserEditAll(), ilMediaPlayerGUI\initJavascript(), and ilUtil\sendInfo().

176  {
177  // toolbar
178  if ($this->access->checkAccess("news_add_news", "", $this->ref_id)) {
180  $b->setCaption('news_add_news');
181  $b->setOnClick("return il.News.create();");
182  $b->setPrimary(true);
183  $this->toolbar->addButtonInstance($b);
184  }
185 
186  include_once("./Services/News/classes/class.ilNewsItem.php");
187  $news_item = new ilNewsItem();
188  $news_item->setContextObjId($this->ctrl->getContextObjId());
189  $news_item->setContextObjType($this->ctrl->getContextObjType());
190 
191  $news_data = $news_item->getNewsForRefId(
192  $this->ref_id,
193  false,
194  false,
195  0,
196  true,
197  false,
198  !$this->include_auto_entries,
199  false,
200  null,
201  self::$items_per_load
202  );
203 
204  include_once("./Services/News/Timeline/classes/class.ilTimelineGUI.php");
205  include_once("./Services/News/classes/class.ilNewsTimelineItemGUI.php");
206  $timeline = ilTimelineGUI::getInstance();
207 
208  // get like widget
209  $obj_ids = array_unique(array_map(function ($a) {
210  return $a["context_obj_id"];
211  }, $news_data));
212  include_once("./Services/Like/classes/class.ilLikeFactoryGUI.php");
213  $likef = new ilLikeFactoryGUI();
214  $like_gui = $likef->widget($obj_ids);
215 
216  $js_items = array();
217  foreach ($news_data as $d) {
218  $news_item = new ilNewsItem($d["id"]);
219  $item = ilNewsTimelineItemGUI::getInstance($news_item, $d["ref_id"], $like_gui);
220  $item->setUserEditAll($this->getUserEditAll());
221  $timeline->addItem($item);
222  $js_items[$d["id"]] = array(
223  "id" => $d["id"],
224  "user_id" => $d["user_id"],
225  "title" => $d["title"],
226  "content" => $d["content"] . $d["content_long"],
227  "content_long" => "",
228  "priority" => $d["priority"],
229  "visibility" => $d["visibility"],
230  "content_type" => $d["content_type"],
231  "mob_id" => $d["mob_id"]
232  );
233  }
234 
235  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
236  $this->tpl->addOnloadCode("il.News.setItems(" . ilJsonUtil::encode($js_items) . ");");
237  $this->tpl->addOnloadCode("il.News.setAjaxUrl('" . $this->ctrl->getLinkTarget($this, "", "", true) . "');");
238 
239  if (count($news_data) > 0) {
240  $ttpl = new ilTemplate("tpl.news_timeline.html", true, true, "Services/News");
241  $ttpl->setVariable("NEWS", $timeline->render());
242  $ttpl->setVariable("EDIT_MODAL", $this->getEditModal());
243  $ttpl->setVariable("DELETE_MODAL", $this->getDeleteModal());
244  $ttpl->setVariable("LOADER", ilUtil::getImagePath("loader.svg"));
245  $this->tpl->setContent($ttpl->get());
246  } else {
247  ilUtil::sendInfo($this->lng->txt("news_timline_add_entries_info"));
248  $this->tpl->setContent($this->getEditModal());
249  }
250 
251  $this->lng->toJS("create");
252  $this->lng->toJS("edit");
253  $this->lng->toJS("update");
254  $this->lng->toJS("save");
255 
256  $this->tpl->addJavaScript("./Services/News/js/News.js");
257  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
259  }
static initJavascript($a_tpl=null)
Init Javascript.
static getInstance(ilNewsItem $a_news_item, $a_news_ref_id, \ilLikeGUI $a_like_gui)
Get instance.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static encode($mixed, $suppress_native=false)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
special template class to simplify handling of ITX/PEAR
getDeleteModal()
Get delete modal.
getEditModal()
Get edit modal.
static getInstance()
Get instance.
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
getUserEditAll()
Get user can edit other users postings.
+ Here is the call graph for this function:

◆ update()

ilNewsTimelineGUI::update ( )

Update (ajax)

Definition at line 394 of file class.ilNewsTimelineGUI.php.

References $_POST, $form, ilObject\_lookupObjectId(), ilObject\_lookupType(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilNewsItemGUI\getEditForm(), IL_FORM_EDIT, ilNewsItemGUI\isRteActivated(), and user().

Referenced by updateNewsItem().

395  {
396  include_once("./Services/News/classes/class.ilNewsItemGUI.php");
398  if ($form->checkInput()) {
399  $news_item = new ilNewsItem((int) $_POST["id"]);
400  $news_item->setTitle($form->getInput("news_title"));
401  $news_item->setContent($form->getInput("news_content"));
402  $news_item->setVisibility($form->getInput("news_visibility"));
403  //$news_item->setContentLong($form->getInput("news_content_long"));
404  include_once("./Services/News/classes/class.ilNewsItemGUI.php");
406  $news_item->setContentHtml(true);
407  }
408  $news_item->setContentLong("");
409 
410  $media = $_FILES["media"];
411  $old_mob_id = 0;
412 
413  // delete old media object
414  if ($media["name"] != "" || $_POST["media_delete"] != "") {
415  if ($news_item->getMobId() > 0 && ilObject::_lookupType($news_item->getMobId()) == "mob") {
416  $old_mob_id = $news_item->getMobId();
417  }
418  $news_item->setMobId(0);
419  }
420 
421  if ($media["name"] != "") {
422  $mob = ilObjMediaObject::_saveTempFileAsMediaObject($media["name"], $media["tmp_name"], true);
423  $news_item->setMobId($mob->getId());
424  }
425 
426  $obj_id = ilObject::_lookupObjectId($this->ref_id);
427 
428  if ($news_item->getContextObjId() == $obj_id) {
429  $news_item->setUpdateUserId($this->user->getId());
430  $news_item->update();
431 
432  if ($old_mob_id > 0) {
433  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
434  $old_mob = new ilObjMediaObject($old_mob_id);
435  $old_mob->delete();
436  }
437  }
438  }
439  }
static isRteActivated()
Is Rte activated.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
user()
Definition: user.php:4
static _lookupObjectId($a_ref_id)
lookup object id
if(isset($_POST['submit'])) $form
Class ilObjMediaObject.
static _lookupType($a_id, $a_reference=false)
lookup object type
static getEditForm($a_mode, $a_ref_id)
FORM NewsItem: Init form.
$_POST["username"]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateNewsItem()

ilNewsTimelineGUI::updateNewsItem ( )
protected
Parameters

Definition at line 336 of file class.ilNewsTimelineGUI.php.

References $_POST, save(), and update().

337  {
338  if ($_POST["news_action"] == "save") {
339  $this->save();
340  $this->ctrl->redirect($this, "show");
341  }
342  if ($_POST["news_action"] == "update") {
343  $this->update();
344  $this->ctrl->redirect($this, "show");
345  }
346  }
$_POST["username"]
+ Here is the call graph for this function:

Field Documentation

◆ $access

ilNewsTimelineGUI::$access
protected

Definition at line 50 of file class.ilNewsTimelineGUI.php.

◆ $ctrl

ilNewsTimelineGUI::$ctrl
protected

Definition at line 20 of file class.ilNewsTimelineGUI.php.

Referenced by executeCommand().

◆ $items_per_load

ilNewsTimelineGUI::$items_per_load = 10
staticprotected

Definition at line 55 of file class.ilNewsTimelineGUI.php.

◆ $lng

ilNewsTimelineGUI::$lng
protected

Definition at line 35 of file class.ilNewsTimelineGUI.php.

◆ $ref_id

ilNewsTimelineGUI::$ref_id
protected

Definition at line 30 of file class.ilNewsTimelineGUI.php.

◆ $toolbar

ilNewsTimelineGUI::$toolbar
protected

Definition at line 40 of file class.ilNewsTimelineGUI.php.

◆ $tpl

ilNewsTimelineGUI::$tpl
protected

Definition at line 25 of file class.ilNewsTimelineGUI.php.

◆ $user

ilNewsTimelineGUI::$user
protected

Definition at line 45 of file class.ilNewsTimelineGUI.php.

◆ $user_edit_all

ilNewsTimelineGUI::$user_edit_all = false
protected

Definition at line 60 of file class.ilNewsTimelineGUI.php.

Referenced by getUserEditAll().


The documentation for this class was generated from the following file: