ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilNewsItemGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/News/classes/class.ilNewsItem.php");
6 
7 define("IL_FORM_EDIT", 0);
8 define("IL_FORM_CREATE", 1);
9 define("IL_FORM_RE_EDIT", 2);
10 define("IL_FORM_RE_CREATE", 3);
11 
21 {
22  protected $enable_edit = 0;
23  protected $context_obj_id;
24  protected $context_obj_type;
27  protected $form_edit_mode;
28 
29 
33  function __construct()
34  {
35  global $ilCtrl, $lng;
36 
37  $this->ctrl = $ilCtrl;
38 
39  include_once("Services/News/classes/class.ilNewsItem.php");
40  if ($_GET["news_item_id"] > 0)
41  {
42  $this->news_item = new ilNewsItem($_GET["news_item_id"]);
43  }
44 
45  $this->ctrl->saveParameter($this, array("news_item_id"));
46 
47  // Init EnableEdit.
48  $this->setEnableEdit(false);
49 
50  // Init Context.
51  $this->setContextObjId($ilCtrl->getContextObjId());
52  $this->setContextObjType($ilCtrl->getContextObjType());
53  $this->setContextSubObjId($ilCtrl->getContextSubObjId());
54  $this->setContextSubObjType($ilCtrl->getContextSubObjType());
55 
56  $lng->loadLanguageModule("news");
57 
58  $ilCtrl->saveParameter($this, "add_mode");
59  }
60 
66  function getHTML()
67  {
68  global $lng, $ilCtrl;
69 
70  $lng->LoadLanguageModule("news");
71 
72  return $this->getNewsForContextBlock();
73  }
74 
79  public function executeCommand()
80  {
81  global $ilCtrl;
82 
83  // check, if news item id belongs to context
84  if (is_object($this->news_item) && $this->news_item->getId() > 0
85  && ilNewsItem::_lookupContextObjId($this->news_item->getId()) != $this->getContextObjId())
86  {
87  throw new ilException("News ID does not match object context.");
88  }
89 
90 
91  // get next class and command
92  $next_class = $this->ctrl->getNextClass($this);
93  $cmd = $this->ctrl->getCmd();
94 
95  switch ($next_class)
96  {
97  default:
98  $html = $this->$cmd();
99  break;
100  }
101 
102  return $html;
103 
104  }
105 
111  public function setEnableEdit($a_enable_edit = 0)
112  {
113  $this->enable_edit = $a_enable_edit;
114  }
115 
121  public function getEnableEdit()
122  {
123  return $this->enable_edit;
124  }
125 
131  public function setContextObjId($a_context_obj_id)
132  {
133  $this->context_obj_id = $a_context_obj_id;
134  }
135 
141  public function getContextObjId()
142  {
143  return $this->context_obj_id;
144  }
145 
151  public function setContextObjType($a_context_obj_type)
152  {
153  $this->context_obj_type = $a_context_obj_type;
154  }
155 
161  public function getContextObjType()
162  {
164  }
165 
171  public function setContextSubObjId($a_context_sub_obj_id)
172  {
173  $this->context_sub_obj_id = $a_context_sub_obj_id;
174  }
175 
181  public function getContextSubObjId()
182  {
184  }
185 
191  public function setContextSubObjType($a_context_sub_obj_type)
192  {
193  $this->context_sub_obj_type = $a_context_sub_obj_type;
194  }
195 
201  public function getContextSubObjType()
202  {
204  }
205 
211  public function setFormEditMode($a_form_edit_mode)
212  {
213  $this->form_edit_mode = $a_form_edit_mode;
214  }
215 
221  public function getFormEditMode()
222  {
223  return $this->form_edit_mode;
224  }
225 
230  public function createNewsItem()
231  {
232  $form = $this->initFormNewsItem(IL_FORM_CREATE);
233  return $form->getHtml();
234  }
235 
240  public function editNewsItem()
241  {
242  $form = $this->initFormNewsItem(IL_FORM_EDIT);
243  $this->getValuesNewsItem($form);
244  return $form->getHtml();
245 
246  }
247 
248 
255  protected function initFormNewsItem($a_mode)
256  {
257  global $ilTabs;
258 
259  $ilTabs->clearTargets();
260  $form = self::getEditForm($a_mode, (int) $_GET["ref_id"]);
261  $form->setFormAction($this->ctrl->getFormAction($this));
262 
263  return $form;
264  }
265 
272  static public function getEditForm($a_mode, $a_ref_id)
273  {
274  global $lng;
275 
276  $lng->loadLanguageModule("news");
277 
278  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
279 
280  $form = new ilPropertyFormGUI();
281 
282  // Property Title
283  $text_input = new ilTextInputGUI($lng->txt("news_news_item_title"), "news_title");
284  $text_input->setInfo("");
285  $text_input->setRequired(true);
286  $text_input->setMaxLength(200);
287  $form->addItem($text_input);
288 
289  // Property Content
290  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content"), "news_content");
291  $text_area->setInfo("");
292  $text_area->setRequired(false);
293  $text_area->setRows("4");
294  $text_area->setUseRte(true);
295  $form->addItem($text_area);
296 
297  // Property Visibility
298  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_news_item_visibility"), "news_visibility");
299  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
300  $radio_group->addOption($radio_option);
301  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
302  $radio_group->addOption($radio_option);
303  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
304  $radio_group->setRequired(false);
305  $radio_group->setValue("users");
306  $form->addItem($radio_group);
307 
308  // Property ContentLong
309  /*
310  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content_long"), "news_content_long");
311  $text_area->setInfo($lng->txt("news_news_item_content_long_info"));
312  $text_area->setRequired(false);
313  $text_area->setCols("40");
314  $text_area->setRows("8");
315  $text_area->setUseRte(true);
316  $form->addItem($text_area);*/
317 
318 
319  // save and cancel commands
320  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
321  {
322  $form->addCommandButton("saveNewsItem", $lng->txt("save"), "news_btn_create");
323  $form->addCommandButton("cancelSaveNewsItem", $lng->txt("cancel"), "news_btn_cancel_create");
324  }
325  else
326  {
327  $form->addCommandButton("updateNewsItem", $lng->txt("save"), "news_btn_update");
328  $form->addCommandButton("cancelUpdateNewsItem", $lng->txt("cancel"), "news_btn_cancel_update");
329  }
330 
331  $form->setTitle($lng->txt("news_news_item_head"));
332 
333  $news_set = new ilSetting("news");
334  if (!$news_set->get("enable_rss_for_internal"))
335  {
336  $form->removeItemByPostVar("news_visibility");
337  }
338  else
339  {
340  $nv = $form->getItemByPostVar("news_visibility");
341  if (is_object($nv))
342  {
343  $nv->setValue(ilNewsItem::_getDefaultVisibilityForRefId($a_ref_id));
344  }
345  }
346 
347  return $form;
348  }
349 
354  public function getValuesNewsItem($a_form)
355  {
356  $values = array();
357 
358  $values["news_title"] = $this->news_item->getTitle();
359  $values["news_content"] = $this->news_item->getContent().$this->news_item->getContentLong();
360  $values["news_visibility"] = $this->news_item->getVisibility();
361  //$values["news_content_long"] = $this->news_item->getContentLong();
362  $values["news_content_long"] = "";
363 
364  $a_form->setValuesByArray($values);
365 
366  }
367 
372  function saveNewsItem()
373  {
374  global $ilUser;
375 
376  if (!$this->getEnableEdit())
377  {
378  return;
379  }
380 
381  $form = $this->initFormNewsItem(IL_FORM_CREATE);
382  if ($form->checkInput())
383  {
384  $this->news_item = new ilNewsItem();
385  $this->news_item->setTitle($form->getInput("news_title"));
386  $this->news_item->setContent($form->getInput("news_content"));
387  $this->news_item->setVisibility($form->getInput("news_visibility"));
388  $this->news_item->setContentLong("");
389  if (self::isRteActivated())
390  {
391  $this->news_item->setContentHtml(true);
392  }
393  //$this->news_item->setContentLong($form->getInput("news_content_long"));
394 
395 // changed
396  //$this->news_item->setContextObjId($this->ctrl->getContextObjId());
397  //$this->news_item->setContextObjType($this->ctrl->getContextObjType());
398  $this->news_item->setContextObjId($this->getContextObjId());
399  $this->news_item->setContextObjType($this->getContextObjType());
400  $this->news_item->setContextSubObjId($this->getContextSubObjId());
401  $this->news_item->setContextSubObjType($this->getContextSubObjType());
402  $this->news_item->setUserId($ilUser->getId());
403 
404  $news_set = new ilSetting("news");
405  if (!$news_set->get("enable_rss_for_internal"))
406  {
407  $this->news_item->setVisibility("users");
408  }
409 
410  $this->news_item->create();
411  $this->exitSaveNewsItem();
412  }
413  else
414  {
415  $form->setValuesByPost();
416  return $form->getHtml();
417  }
418 
419  }
420 
421  function exitSaveNewsItem()
422  {
423  global $ilCtrl;
424 
425  if ($_GET["add_mode"] == "block")
426  {
427  $ilCtrl->returnToParent($this);
428  }
429  else
430  {
431  $ilCtrl->redirect($this, "editNews");
432  }
433  }
434 
439  function updateNewsItem()
440  {
441  global $ilUser;
442 
443  if (!$this->getEnableEdit())
444  {
445  return "";
446  }
447 
448  $form = $this->initFormNewsItem(IL_FORM_EDIT);
449  if ($form->checkInput())
450  {
451  $this->news_item->setUpdateUserId($ilUser->getId());
452  $this->news_item->setTitle($form->getInput("news_title"));
453  $this->news_item->setContent($form->getInput("news_content"));
454  $this->news_item->setVisibility($form->getInput("news_visibility"));
455  //$this->news_item->setContentLong($form->getInput("news_content_long"));
456  $this->news_item->setContentLong("");
457  if (self::isRteActivated())
458  {
459  $this->news_item->setContentHtml(true);
460  }
461  $this->news_item->update();
462  $this->exitUpdateNewsItem();
463  }
464  else
465  {
466  $form->setValuesByPost();
467  return $form->getHtml();
468  }
469  }
470 
472  {
473  global $ilCtrl;
474 
475  $ilCtrl->redirect($this, "editNews");
476  }
477 
483  {
484  return $this->editNews();
485  }
486 
492  {
493  global $ilCtrl;
494 
495  if ($_GET["add_mode"] == "block")
496  {
497  $ilCtrl->returnToParent($this);
498  }
499  else
500  {
501  return $this->editNews();
502  }
503  }
504 
510  function editNews()
511  {
512  global $ilTabs, $ilToolbar, $lng, $ilCtrl;
513 
514  $this->setTabs();
515 
516  $ilToolbar->addButton($lng->txt("news_add_news"),
517  $ilCtrl->getLinkTarget($this, "createNewsItem"));
518 
519  if (!$this->getEnableEdit())
520  {
521  return;
522  }
523  return $this->getNewsForContextTable();
524  }
525 
529  function cancelUpdate()
530  {
531  return $this->editNews();
532  }
533 
538  {
539  global $ilCtrl, $lng, $ilTabs;
540 
541  if (!$this->getEnableEdit())
542  {
543  return;
544  }
545 
546  // check whether at least one item is selected
547  if (count($_POST["news_id"]) == 0)
548  {
549  ilUtil::sendFailure($lng->txt("no_checkbox"));
550  return $this->editNews();
551  }
552 
553  $ilTabs->clearTargets();
554 
555  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
556  $c_gui = new ilConfirmationGUI();
557 
558  // set confirm/cancel commands
559  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteNewsItems"));
560  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
561  $c_gui->setCancel($lng->txt("cancel"), "editNews");
562  $c_gui->setConfirm($lng->txt("confirm"), "deleteNewsItems");
563 
564  // add items to delete
565  foreach($_POST["news_id"] as $news_id)
566  {
567  $news = new ilNewsItem($news_id);
568  $c_gui->addItem("news_id[]", $news_id, $news->getTitle());
569  }
570 
571  return $c_gui->getHTML();
572  }
573 
577  function deleteNewsItems()
578  {
579  if (!$this->getEnableEdit())
580  {
581  return;
582  }
583  // delete all selected news items
584  foreach($_POST["news_id"] as $news_id)
585  {
586  $news = new ilNewsItem($news_id);
587  $news->delete();
588  }
589 
590  return $this->editNews();
591  }
592 
597  public function getNewsForContextBlock()
598  {
599  global $lng;
600 
601  include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
602  $block_gui = new ilNewsForContextBlockGUI(get_class($this));
603 
604  $block_gui->setParentClass("ilinfoscreengui");
605  $block_gui->setParentCmd("showSummary");
606  $block_gui->setEnableEdit($this->getEnableEdit());
607 
608 
609  $news_item = new ilNewsItem();
610 
611 // changed
612  //$news_item->setContextObjId($this->ctrl->getContextObjId());
613  //$news_item->setContextObjType($this->ctrl->getContextObjType());
614  $news_item->setContextObjId($this->getContextObjId());
615  $news_item->setContextObjType($this->getContextObjType());
616  $news_item->setContextSubObjId($this->getContextSubObjId());
617  $news_item->setContextSubObjType($this->getContextSubObjType());
618 
619  $data = $news_item->queryNewsForContext();
620 
621  $block_gui->setTitle($lng->txt("news_block_news_for_context"));
622  $block_gui->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
623  $block_gui->setData($data);
624 
625  return $block_gui->getHTML();
626 
627  }
628 
629 
634  public function getNewsForContextTable()
635  {
636  global $lng;
637 
638  $news_item = new ilNewsItem();
639  $news_item->setContextObjId($this->getContextObjId());
640  $news_item->setContextObjType($this->getContextObjType());
641  $news_item->setContextSubObjId($this->getContextSubObjId());
642  $news_item->setContextSubObjType($this->getContextSubObjType());
643 
644  $perm_ref_id = 0;
645  if (in_array($this->getContextObjType(), array("cat", "grp", "crs", "root")))
646  {
647  $data = $news_item->getNewsForRefId($_GET["ref_id"], false, false,
648  0, true, false, true, true);
649  }
650  else
651  {
652  $perm_ref_id = $_GET["ref_id"];
653  if ($this->getContextSubObjId() > 0)
654  {
655  $data = $news_item->queryNewsForContext(false, 0,
656  "", true, true);
657  }
658  else
659  {
660  $data = $news_item->queryNewsForContext();
661  }
662  }
663 
664  include_once("Services/News/classes/class.ilNewsForContextTableGUI.php");
665  $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable", $perm_ref_id);
666 
667  $table_gui->setTitle($lng->txt("news_table_news_for_context"));
668  $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News");
669  $table_gui->setData($data);
670 
671  $table_gui->setDefaultOrderField("creation_date");
672  $table_gui->setDefaultOrderDirection("desc");
673  $table_gui->addMultiCommand("confirmDeletionNewsItems", $lng->txt("delete"));
674  $table_gui->setTitle($lng->txt("news"));
675  $table_gui->setSelectAllCheckbox("news_id");
676 
677 
678  return $table_gui->getHTML();
679 
680  }
681 
688  function setTabs()
689  {
690  global $ilTabs, $ilCtrl, $lng;
691 
692  $ilTabs->clearTargets();
693  $ilTabs->setBackTarget($lng->txt("back"),
694  $ilCtrl->getParentReturnByClass("ilnewsitemgui"));
695  }
696 
702  static function isRteActivated()
703  {
704  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
706  {
707  return false;
708  }
709  return true;
710  }
711 
712 }
This class represents an option in a radio group.
ILIAS Setting Class.
getContextSubObjId()
Get ContextSubObjId.
Base class for ILIAS Exception handling.
static isRteActivated()
Is Rte activated.
getValuesNewsItem($a_form)
FORM NewsItem: Get current values for NewsItem form.
static _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
This class represents a property form user interface.
getNewsForContextBlock()
BLOCK NewsForContext: Get block HTML.
$_GET["client_id"]
editNews()
Edit news.
setContextObjId($a_context_obj_id)
Set ContextObjId.
getFormEditMode()
Get FormEditMode.
$cmd
Definition: sahs_server.php:35
User Interface for NewsItem entities.
confirmDeletionNewsItems()
Confirmation Screen.
getContextObjId()
Get ContextObjId.
BlockGUI class for block NewsForContext.
saveNewsItem()
FORM NewsItem: Save NewsItem.
getEnableEdit()
Get EnableEdit.
setInfo($a_info)
Set Info.
getContextObjType()
Get ContextObjType.
deleteNewsItems()
Delete news items.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
cancelUpdateNewsItem()
FORM NewsItem: Save NewsItem.
This class represents a property in a property form.
initFormNewsItem($a_mode)
FORM NewsItem: Init form.
setContextSubObjId($a_context_sub_obj_id)
Set ContextSubObjId.
getContextSubObjType()
Get ContextSubObjType.
This class represents a text property in a property form.
setContextSubObjType($a_context_sub_obj_type)
Set ContextSubObjType.
$ilUser
Definition: imgupload.php:18
createNewsItem()
FORM NewsItem: Create NewsItem.
editNewsItem()
FORM NewsItem: Edit form.
const IL_FORM_EDIT
getNewsForContextTable()
TABLE NewsForContext: Get table HTML.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:17
This class represents a text area property in a property form.
TableGUI class for table NewsForContext.
static _getDefaultVisibilityForRefId($a_ref_id)
Get default visibility for reference id.
static _lookupContextObjId($a_news_id)
Context Object ID.
cancelSaveNewsItem()
FORM NewsItem: Save NewsItem.
const IL_FORM_RE_CREATE
const IL_FORM_CREATE
setContextObjType($a_context_obj_type)
Set ContextObjType.
setEnableEdit($a_enable_edit=0)
Set EnableEdit.
static getEditForm($a_mode, $a_ref_id)
FORM NewsItem: Init form.
$_POST["username"]
$html
Definition: example_001.php:87
setFormEditMode($a_form_edit_mode)
Set FormEditMode.
executeCommand()
Execute command.
cancelUpdate()
Cancel update.
Confirmation screen class.
__construct()
Constructor.
updateNewsItem()
FORM NewsItem: Save NewsItem.