ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
25  protected $ctrl;
26 
30  protected $lng;
31 
35  protected $tabs;
36 
40  protected $user;
41 
45  protected $toolbar;
46 
47  protected $enable_edit = 0;
48  protected $context_obj_id;
49  protected $context_obj_type;
52  protected $form_edit_mode;
53 
54 
58  public function __construct()
59  {
60  global $DIC;
61 
62  $this->lng = $DIC->language();
63  $this->tabs = $DIC->tabs();
64  $this->user = $DIC->user();
65  $this->toolbar = $DIC->toolbar();
66  $ilCtrl = $DIC->ctrl();
67  $lng = $DIC->language();
68 
69  $this->ctrl = $ilCtrl;
70 
71  include_once("Services/News/classes/class.ilNewsItem.php");
72  if ($_GET["news_item_id"] > 0) {
73  $this->news_item = new ilNewsItem($_GET["news_item_id"]);
74  }
75 
76  $this->ctrl->saveParameter($this, array("news_item_id"));
77 
78  // Init EnableEdit.
79  $this->setEnableEdit(false);
80 
81  // Init Context.
82  $this->setContextObjId($ilCtrl->getContextObjId());
83  $this->setContextObjType($ilCtrl->getContextObjType());
84  $this->setContextSubObjId($ilCtrl->getContextSubObjId());
85  $this->setContextSubObjType($ilCtrl->getContextSubObjType());
86 
87  $lng->loadLanguageModule("news");
88 
89  $ilCtrl->saveParameter($this, "add_mode");
90  }
91 
97  public function getHTML()
98  {
99  $lng = $this->lng;
101 
102  $lng->LoadLanguageModule("news");
103 
104  return $this->getNewsForContextBlock();
105  }
106 
111  public function executeCommand()
112  {
114 
115  // check, if news item id belongs to context
116  if (is_object($this->news_item) && $this->news_item->getId() > 0
117  && ilNewsItem::_lookupContextObjId($this->news_item->getId()) != $this->getContextObjId()) {
118  throw new ilException("News ID does not match object context.");
119  }
120 
121 
122  // get next class and command
123  $next_class = $this->ctrl->getNextClass($this);
124  $cmd = $this->ctrl->getCmd();
125 
126  switch ($next_class) {
127  default:
128  $html = $this->$cmd();
129  break;
130  }
131 
132  return $html;
133  }
134 
140  public function setEnableEdit($a_enable_edit = 0)
141  {
142  $this->enable_edit = $a_enable_edit;
143  }
144 
150  public function getEnableEdit()
151  {
152  return $this->enable_edit;
153  }
154 
160  public function setContextObjId($a_context_obj_id)
161  {
162  $this->context_obj_id = $a_context_obj_id;
163  }
164 
170  public function getContextObjId()
171  {
172  return $this->context_obj_id;
173  }
174 
180  public function setContextObjType($a_context_obj_type)
181  {
182  $this->context_obj_type = $a_context_obj_type;
183  }
184 
190  public function getContextObjType()
191  {
193  }
194 
200  public function setContextSubObjId($a_context_sub_obj_id)
201  {
202  $this->context_sub_obj_id = $a_context_sub_obj_id;
203  }
204 
210  public function getContextSubObjId()
211  {
213  }
214 
220  public function setContextSubObjType($a_context_sub_obj_type)
221  {
222  $this->context_sub_obj_type = $a_context_sub_obj_type;
223  }
224 
230  public function getContextSubObjType()
231  {
233  }
234 
240  public function setFormEditMode($a_form_edit_mode)
241  {
242  $this->form_edit_mode = $a_form_edit_mode;
243  }
244 
250  public function getFormEditMode()
251  {
252  return $this->form_edit_mode;
253  }
254 
259  public function createNewsItem()
260  {
262  return $form->getHtml();
263  }
264 
269  public function editNewsItem()
270  {
272  $this->getValuesNewsItem($form);
273  return $form->getHtml();
274  }
275 
276 
283  protected function initFormNewsItem($a_mode)
284  {
285  $ilTabs = $this->tabs;
286 
287  $ilTabs->clearTargets();
288  $form = self::getEditForm($a_mode, (int) $_GET["ref_id"]);
289  $form->setFormAction($this->ctrl->getFormAction($this));
290 
291  return $form;
292  }
293 
300  public static function getEditForm($a_mode, $a_ref_id)
301  {
302  global $DIC;
303 
304  $lng = $DIC->language();
305 
306  $lng->loadLanguageModule("news");
307 
308  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
309 
310  $form = new ilPropertyFormGUI();
311 
312  // Property Title
313  $text_input = new ilTextInputGUI($lng->txt("news_news_item_title"), "news_title");
314  $text_input->setInfo("");
315  $text_input->setRequired(true);
316  $text_input->setMaxLength(200);
317  $form->addItem($text_input);
318 
319  // Property Content
320  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content"), "news_content");
321  $text_area->setInfo("");
322  $text_area->setRequired(false);
323  $text_area->setRows("4");
324  $text_area->setUseRte(true);
325  $form->addItem($text_area);
326 
327  // Property Visibility
328  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_news_item_visibility"), "news_visibility");
329  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
330  $radio_group->addOption($radio_option);
331  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
332  $radio_group->addOption($radio_option);
333  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
334  $radio_group->setRequired(false);
335  $radio_group->setValue("users");
336  $form->addItem($radio_group);
337 
338  // Property ContentLong
339  /*
340  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content_long"), "news_content_long");
341  $text_area->setInfo($lng->txt("news_news_item_content_long_info"));
342  $text_area->setRequired(false);
343  $text_area->setCols("40");
344  $text_area->setRows("8");
345  $text_area->setUseRte(true);
346  $form->addItem($text_area);*/
347 
348 
349  // save and cancel commands
350  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE))) {
351  $form->addCommandButton("saveNewsItem", $lng->txt("save"), "news_btn_create");
352  $form->addCommandButton("cancelSaveNewsItem", $lng->txt("cancel"), "news_btn_cancel_create");
353  } else {
354  $form->addCommandButton("updateNewsItem", $lng->txt("save"), "news_btn_update");
355  $form->addCommandButton("cancelUpdateNewsItem", $lng->txt("cancel"), "news_btn_cancel_update");
356  }
357 
358  $form->setTitle($lng->txt("news_news_item_head"));
359 
360  $news_set = new ilSetting("news");
361  if (!$news_set->get("enable_rss_for_internal")) {
362  $form->removeItemByPostVar("news_visibility");
363  } else {
364  $nv = $form->getItemByPostVar("news_visibility");
365  if (is_object($nv)) {
366  $nv->setValue(ilNewsItem::_getDefaultVisibilityForRefId($a_ref_id));
367  }
368  }
369 
370  return $form;
371  }
372 
377  public function getValuesNewsItem($a_form)
378  {
379  $values = array();
380 
381  $values["news_title"] = $this->news_item->getTitle();
382  $values["news_content"] = $this->news_item->getContent() . $this->news_item->getContentLong();
383  $values["news_visibility"] = $this->news_item->getVisibility();
384  //$values["news_content_long"] = $this->news_item->getContentLong();
385  $values["news_content_long"] = "";
386 
387  $a_form->setValuesByArray($values);
388  }
389 
394  public function saveNewsItem()
395  {
397 
398  if (!$this->getEnableEdit()) {
399  return;
400  }
401 
403  if ($form->checkInput()) {
404  $this->news_item = new ilNewsItem();
405  $this->news_item->setTitle($form->getInput("news_title"));
406  $this->news_item->setContent($form->getInput("news_content"));
407  $this->news_item->setVisibility($form->getInput("news_visibility"));
408  $this->news_item->setContentLong("");
409  if (self::isRteActivated()) {
410  $this->news_item->setContentHtml(true);
411  }
412  //$this->news_item->setContentLong($form->getInput("news_content_long"));
413 
414  // changed
415  //$this->news_item->setContextObjId($this->ctrl->getContextObjId());
416  //$this->news_item->setContextObjType($this->ctrl->getContextObjType());
417  $this->news_item->setContextObjId($this->getContextObjId());
418  $this->news_item->setContextObjType($this->getContextObjType());
419  $this->news_item->setContextSubObjId($this->getContextSubObjId());
420  $this->news_item->setContextSubObjType($this->getContextSubObjType());
421  $this->news_item->setUserId($ilUser->getId());
422 
423  $news_set = new ilSetting("news");
424  if (!$news_set->get("enable_rss_for_internal")) {
425  $this->news_item->setVisibility("users");
426  }
427 
428  $this->news_item->create();
429  $this->exitSaveNewsItem();
430  } else {
431  $form->setValuesByPost();
432  return $form->getHtml();
433  }
434  }
435 
436  public function exitSaveNewsItem()
437  {
439 
440  if ($_GET["add_mode"] == "block") {
441  $ilCtrl->returnToParent($this);
442  } else {
443  $ilCtrl->redirect($this, "editNews");
444  }
445  }
446 
451  public function updateNewsItem()
452  {
454 
455  if (!$this->getEnableEdit()) {
456  return "";
457  }
458 
460  if ($form->checkInput()) {
461  $this->news_item->setUpdateUserId($ilUser->getId());
462  $this->news_item->setTitle($form->getInput("news_title"));
463  $this->news_item->setContent($form->getInput("news_content"));
464  $this->news_item->setVisibility($form->getInput("news_visibility"));
465  //$this->news_item->setContentLong($form->getInput("news_content_long"));
466  $this->news_item->setContentLong("");
467  if (self::isRteActivated()) {
468  $this->news_item->setContentHtml(true);
469  }
470  $this->news_item->update();
471  $this->exitUpdateNewsItem();
472  } else {
473  $form->setValuesByPost();
474  return $form->getHtml();
475  }
476  }
477 
478  public function exitUpdateNewsItem()
479  {
481 
482  $ilCtrl->redirect($this, "editNews");
483  }
484 
489  public function cancelUpdateNewsItem()
490  {
491  return $this->editNews();
492  }
493 
498  public function cancelSaveNewsItem()
499  {
501 
502  if ($_GET["add_mode"] == "block") {
503  $ilCtrl->returnToParent($this);
504  } else {
505  return $this->editNews();
506  }
507  }
508 
514  public function editNews()
515  {
516  $ilTabs = $this->tabs;
517  $ilToolbar = $this->toolbar;
518  $lng = $this->lng;
520 
521  $this->setTabs();
522 
523  $ilToolbar->addButton(
524  $lng->txt("news_add_news"),
525  $ilCtrl->getLinkTarget($this, "createNewsItem")
526  );
527 
528  if (!$this->getEnableEdit()) {
529  return;
530  }
531  return $this->getNewsForContextTable();
532  }
533 
537  public function cancelUpdate()
538  {
539  return $this->editNews();
540  }
541 
545  public function confirmDeletionNewsItems()
546  {
548  $lng = $this->lng;
549  $ilTabs = $this->tabs;
550 
551  if (!$this->getEnableEdit()) {
552  return;
553  }
554 
555  // check whether at least one item is selected
556  if (count($_POST["news_id"]) == 0) {
557  ilUtil::sendFailure($lng->txt("no_checkbox"));
558  return $this->editNews();
559  }
560 
561  $ilTabs->clearTargets();
562 
563  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
564  $c_gui = new ilConfirmationGUI();
565 
566  // set confirm/cancel commands
567  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteNewsItems"));
568  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
569  $c_gui->setCancel($lng->txt("cancel"), "editNews");
570  $c_gui->setConfirm($lng->txt("confirm"), "deleteNewsItems");
571 
572  // add items to delete
573  foreach ($_POST["news_id"] as $news_id) {
574  $news = new ilNewsItem($news_id);
575  $c_gui->addItem("news_id[]", $news_id, $news->getTitle());
576  }
577 
578  return $c_gui->getHTML();
579  }
580 
584  public function deleteNewsItems()
585  {
586  if (!$this->getEnableEdit()) {
587  return;
588  }
589  // delete all selected news items
590  foreach ($_POST["news_id"] as $news_id) {
591  $news = new ilNewsItem($news_id);
592  $news->delete();
593  }
594 
595  return $this->editNews();
596  }
597 
602  public function getNewsForContextBlock()
603  {
604  $lng = $this->lng;
605 
606  include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
607  $block_gui = new ilNewsForContextBlockGUI(get_class($this));
608 
609  $block_gui->setParentClass("ilinfoscreengui");
610  $block_gui->setParentCmd("showSummary");
611  $block_gui->setEnableEdit($this->getEnableEdit());
612 
613 
614  $news_item = new ilNewsItem();
615 
616  // changed
617  //$news_item->setContextObjId($this->ctrl->getContextObjId());
618  //$news_item->setContextObjType($this->ctrl->getContextObjType());
619  $news_item->setContextObjId($this->getContextObjId());
620  $news_item->setContextObjType($this->getContextObjType());
621  $news_item->setContextSubObjId($this->getContextSubObjId());
622  $news_item->setContextSubObjType($this->getContextSubObjType());
623 
624  $data = $news_item->queryNewsForContext();
625 
626  $block_gui->setTitle($lng->txt("news_block_news_for_context"));
627  $block_gui->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
628  $block_gui->setData($data);
629 
630  return $block_gui->getHTML();
631  }
632 
633 
638  public function getNewsForContextTable()
639  {
640  $lng = $this->lng;
641 
642  $news_item = new ilNewsItem();
643  $news_item->setContextObjId($this->getContextObjId());
644  $news_item->setContextObjType($this->getContextObjType());
645  $news_item->setContextSubObjId($this->getContextSubObjId());
646  $news_item->setContextSubObjType($this->getContextSubObjType());
647 
648  $perm_ref_id = 0;
649  if (in_array($this->getContextObjType(), array("cat", "grp", "crs", "root"))) {
650  $data = $news_item->getNewsForRefId(
651  $_GET["ref_id"],
652  false,
653  false,
654  0,
655  true,
656  false,
657  true,
658  true
659  );
660  } else {
661  $perm_ref_id = $_GET["ref_id"];
662  if ($this->getContextSubObjId() > 0) {
663  $data = $news_item->queryNewsForContext(
664  false,
665  0,
666  "",
667  true,
668  true
669  );
670  } else {
671  $data = $news_item->queryNewsForContext();
672  }
673  }
674 
675  include_once("Services/News/classes/class.ilNewsForContextTableGUI.php");
676  $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable", $perm_ref_id);
677 
678  $table_gui->setTitle($lng->txt("news_table_news_for_context"));
679  $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News");
680  $table_gui->setData($data);
681 
682  $table_gui->setDefaultOrderField("creation_date");
683  $table_gui->setDefaultOrderDirection("desc");
684  $table_gui->addMultiCommand("confirmDeletionNewsItems", $lng->txt("delete"));
685  $table_gui->setTitle($lng->txt("news"));
686  $table_gui->setSelectAllCheckbox("news_id");
687 
688 
689  return $table_gui->getHTML();
690  }
691 
698  public function setTabs()
699  {
700  $ilTabs = $this->tabs;
702  $lng = $this->lng;
703 
704  $ilTabs->clearTargets();
705  $ilTabs->setBackTarget(
706  $lng->txt("back"),
707  $ilCtrl->getParentReturnByClass("ilnewsitemgui")
708  );
709  }
710 
716  public static function isRteActivated()
717  {
718  include_once("./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php");
720  return false;
721  }
722  return true;
723  }
724 }
This class represents an option in a radio group.
getContextSubObjId()
Get ContextSubObjId.
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.
global $DIC
Definition: saml.php:7
getNewsForContextBlock()
BLOCK NewsForContext: Get block HTML.
$_GET["client_id"]
editNews()
Edit news.
setContextObjId($a_context_obj_id)
Set ContextObjId.
getFormEditMode()
Get FormEditMode.
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.
user()
Definition: user.php:4
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.
if(isset($_POST['submit'])) $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.
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.