ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  // get next class and command
84  $next_class = $this->ctrl->getNextClass($this);
85  $cmd = $this->ctrl->getCmd();
86 
87  switch ($next_class)
88  {
89  default:
90  $html = $this->$cmd();
91  break;
92  }
93 
94  return $html;
95 
96  }
97 
103  public function setEnableEdit($a_enable_edit = 0)
104  {
105  $this->enable_edit = $a_enable_edit;
106  }
107 
113  public function getEnableEdit()
114  {
115  return $this->enable_edit;
116  }
117 
123  public function setContextObjId($a_context_obj_id)
124  {
125  $this->context_obj_id = $a_context_obj_id;
126  }
127 
133  public function getContextObjId()
134  {
135  return $this->context_obj_id;
136  }
137 
143  public function setContextObjType($a_context_obj_type)
144  {
145  $this->context_obj_type = $a_context_obj_type;
146  }
147 
153  public function getContextObjType()
154  {
156  }
157 
163  public function setContextSubObjId($a_context_sub_obj_id)
164  {
165  $this->context_sub_obj_id = $a_context_sub_obj_id;
166  }
167 
173  public function getContextSubObjId()
174  {
176  }
177 
183  public function setContextSubObjType($a_context_sub_obj_type)
184  {
185  $this->context_sub_obj_type = $a_context_sub_obj_type;
186  }
187 
193  public function getContextSubObjType()
194  {
196  }
197 
203  public function setFormEditMode($a_form_edit_mode)
204  {
205  $this->form_edit_mode = $a_form_edit_mode;
206  }
207 
213  public function getFormEditMode()
214  {
215  return $this->form_edit_mode;
216  }
217 
222  public function createNewsItem()
223  {
225  return $this->form_gui->getHtml();
226  }
227 
232  public function editNewsItem()
233  {
235  $this->getValuesNewsItem();
236  return $this->form_gui->getHtml();
237 
238  }
239 
240 
246  public function initFormNewsItem($a_mode)
247  {
248  global $lng, $ilTabs;
249 
250  $ilTabs->clearTargets();
251  //$this->setTabs();
252 
253  $lng->loadLanguageModule("news");
254 
255  include("Services/Form/classes/class.ilPropertyFormGUI.php");
256 
257  $this->form_gui = new ilPropertyFormGUI();
258 
259 
260  // Property Title
261  $text_input = new ilTextInputGUI($lng->txt("news_news_item_title"), "news_title");
262  $text_input->setInfo("");
263  $text_input->setRequired(true);
264  $text_input->setMaxLength(200);
265  $this->form_gui->addItem($text_input);
266 
267  // Property Content
268  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content"), "news_content");
269  $text_area->setInfo("");
270  $text_area->setRequired(false);
271  $this->form_gui->addItem($text_area);
272 
273  // Property Visibility
274  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_news_item_visibility"), "news_visibility");
275  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
276  $radio_group->addOption($radio_option);
277  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
278  $radio_group->addOption($radio_option);
279  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
280  $radio_group->setRequired(false);
281  $radio_group->setValue("users");
282  $this->form_gui->addItem($radio_group);
283 
284  // Property ContentLong
285  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content_long"), "news_content_long");
286  $text_area->setInfo($lng->txt("news_news_item_content_long_info"));
287  $text_area->setRequired(false);
288  $text_area->setCols("40");
289  $text_area->setRows("8");
290  $text_area->setUseRte(true);
291  $this->form_gui->addItem($text_area);
292 
293 
294  // save and cancel commands
295  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
296  {
297  $this->form_gui->addCommandButton("saveNewsItem", $lng->txt("save"));
298  $this->form_gui->addCommandButton("cancelSaveNewsItem", $lng->txt("cancel"));
299  }
300  else
301  {
302  $this->form_gui->addCommandButton("updateNewsItem", $lng->txt("save"));
303  $this->form_gui->addCommandButton("cancelUpdateNewsItem", $lng->txt("cancel"));
304  }
305 
306  $this->form_gui->setTitle($lng->txt("news_news_item_head"));
307  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
308 
309  $news_set = new ilSetting("news");
310  if (!$news_set->get("enable_rss_for_internal"))
311  {
312  $this->form_gui->removeItemByPostVar("news_visibility");
313  }
314  else
315  {
316  $nv = $this->form_gui->getItemByPostVar("news_visibility");
317  if (is_object($nv))
318  {
319  $nv->setValue(ilNewsItem::_getDefaultVisibilityForRefId($_GET["ref_id"]));
320  }
321  }
322 
323  }
324 
329  public function getValuesNewsItem()
330  {
331  $values = array();
332 
333  $values["news_title"] = $this->news_item->getTitle();
334  $values["news_content"] = $this->news_item->getContent();
335  $values["news_visibility"] = $this->news_item->getVisibility();
336  $values["news_content_long"] = $this->news_item->getContentLong();
337 
338  $this->form_gui->setValuesByArray($values);
339 
340  }
341 
346  function saveNewsItem()
347  {
348  global $ilUser;
349 
350  if (!$this->getEnableEdit())
351  {
352  return;
353  }
354 
356  if ($this->form_gui->checkInput())
357  {
358  $this->news_item = new ilNewsItem();
359  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
360  $this->news_item->setContent($this->form_gui->getInput("news_content"));
361  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
362  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
363 
364 // changed
365  //$this->news_item->setContextObjId($this->ctrl->getContextObjId());
366  //$this->news_item->setContextObjType($this->ctrl->getContextObjType());
367  $this->news_item->setContextObjId($this->getContextObjId());
368  $this->news_item->setContextObjType($this->getContextObjType());
369  $this->news_item->setContextSubObjId($this->getContextSubObjId());
370  $this->news_item->setContextSubObjType($this->getContextSubObjType());
371  $this->news_item->setUserId($ilUser->getId());
372 
373  $news_set = new ilSetting("news");
374  if (!$news_set->get("enable_rss_for_internal"))
375  {
376  $this->news_item->setVisibility("users");
377  }
378 
379  $this->news_item->create();
380  $this->exitSaveNewsItem();
381  }
382  else
383  {
384  $this->form_gui->setValuesByPost();
385  return $this->form_gui->getHtml();
386  }
387 
388  }
389 
390  function exitSaveNewsItem()
391  {
392  global $ilCtrl;
393 
394  if ($_GET["add_mode"] == "block")
395  {
396  $ilCtrl->returnToParent($this);
397  }
398  else
399  {
400  $ilCtrl->redirect($this, "editNews");
401  }
402  }
403 
408  function updateNewsItem()
409  {
410  if (!$this->getEnableEdit())
411  {
412  return;
413  }
414 
416  if ($this->form_gui->checkInput())
417  {
418 
419  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
420  $this->news_item->setContent($this->form_gui->getInput("news_content"));
421  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
422  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
423  $this->news_item->update();
424  $this->exitUpdateNewsItem();
425  }
426  else
427  {
428  $this->form_gui->setValuesByPost();
429  return $this->form_gui->getHtml();
430  }
431  }
432 
434  {
435  global $ilCtrl;
436 
437  $ilCtrl->redirect($this, "editNews");
438  }
439 
445  {
446  return $this->editNews();
447  }
448 
454  {
455  global $ilCtrl;
456 
457  if ($_GET["add_mode"] == "block")
458  {
459  $ilCtrl->returnToParent($this);
460  }
461  else
462  {
463  return $this->editNews();
464  }
465  }
466 
472  function editNews()
473  {
474  global $ilTabs, $ilToolbar, $lng, $ilCtrl;
475 
476  $this->setTabs();
477 
478  $ilToolbar->addButton($lng->txt("news_add_news"),
479  $ilCtrl->getLinkTarget($this, "createNewsItem"));
480 
481  if (!$this->getEnableEdit())
482  {
483  return;
484  }
485  return $this->getNewsForContextTable();
486  }
487 
491  function cancelUpdate()
492  {
493  return $this->editNews();
494  }
495 
500  {
501  global $ilCtrl, $lng, $ilTabs;
502 
503  if (!$this->getEnableEdit())
504  {
505  return;
506  }
507 
508  // check whether at least one item is selected
509  if (count($_POST["news_id"]) == 0)
510  {
511  ilUtil::sendFailure($lng->txt("no_checkbox"));
512  return $this->editNews();
513  }
514 
515  $ilTabs->clearTargets();
516 
517  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
518  $c_gui = new ilConfirmationGUI();
519 
520  // set confirm/cancel commands
521  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteNewsItems"));
522  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
523  $c_gui->setCancel($lng->txt("cancel"), "editNews");
524  $c_gui->setConfirm($lng->txt("confirm"), "deleteNewsItems");
525 
526  // add items to delete
527  foreach($_POST["news_id"] as $news_id)
528  {
529  $news = new ilNewsItem($news_id);
530  $c_gui->addItem("news_id[]", $news_id, $news->getTitle());
531  }
532 
533  return $c_gui->getHTML();
534  }
535 
539  function deleteNewsItems()
540  {
541  if (!$this->getEnableEdit())
542  {
543  return;
544  }
545  // delete all selected news items
546  foreach($_POST["news_id"] as $news_id)
547  {
548  $news = new ilNewsItem($news_id);
549  $news->delete();
550  }
551 
552  return $this->editNews();
553  }
554 
559  public function getNewsForContextBlock()
560  {
561  global $lng;
562 
563  include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
564  $block_gui = new ilNewsForContextBlockGUI(get_class($this));
565 
566  $block_gui->setParentClass("ilinfoscreengui");
567  $block_gui->setParentCmd("showSummary");
568  $block_gui->setEnableEdit($this->getEnableEdit());
569 
570 
571  $news_item = new ilNewsItem();
572 
573 // changed
574  //$news_item->setContextObjId($this->ctrl->getContextObjId());
575  //$news_item->setContextObjType($this->ctrl->getContextObjType());
576  $news_item->setContextObjId($this->getContextObjId());
577  $news_item->setContextObjType($this->getContextObjType());
578  $news_item->setContextSubObjId($this->getContextSubObjId());
579  $news_item->setContextSubObjType($this->getContextSubObjType());
580 
581  $data = $news_item->queryNewsForContext();
582 
583  $block_gui->setTitle($lng->txt("news_block_news_for_context"));
584  $block_gui->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
585  $block_gui->setData($data);
586 
587  return $block_gui->getHTML();
588 
589  }
590 
591 
596  public function getNewsForContextTable()
597  {
598  global $lng;
599 
600  $news_item = new ilNewsItem();
601  $news_item->setContextObjId($this->getContextObjId());
602  $news_item->setContextObjType($this->getContextObjType());
603  $news_item->setContextSubObjId($this->getContextSubObjId());
604  $news_item->setContextSubObjType($this->getContextSubObjType());
605 
606  $perm_ref_id = 0;
607  if (in_array($this->getContextObjType(), array("cat", "grp", "crs", "root")))
608  {
609  $data = $news_item->getNewsForRefId($_GET["ref_id"], false, false,
610  0, true, false, true, true);
611  }
612  else
613  {
614  $perm_ref_id = $_GET["ref_id"];
615  if ($this->getContextSubObjId() > 0)
616  {
617  $data = $news_item->queryNewsForContext(false, 0,
618  "", true, true);
619  }
620  else
621  {
622  $data = $news_item->queryNewsForContext();
623  }
624  }
625 
626  include_once("Services/News/classes/class.ilNewsForContextTableGUI.php");
627  $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable", $perm_ref_id);
628 
629  $table_gui->setTitle($lng->txt("news_table_news_for_context"));
630  $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News");
631  $table_gui->setData($data);
632 
633  $table_gui->setDefaultOrderField("creation_date");
634  $table_gui->setDefaultOrderDirection("desc");
635  $table_gui->addMultiCommand("confirmDeletionNewsItems", $lng->txt("delete"));
636  $table_gui->setTitle($lng->txt("news"));
637  $table_gui->setSelectAllCheckbox("news_id");
638 
639 
640  return $table_gui->getHTML();
641 
642  }
643 
650  function setTabs()
651  {
652  global $ilTabs, $ilCtrl, $lng;
653 
654  $ilTabs->clearTargets();
655  $ilTabs->setBackTarget($lng->txt("back"),
656  $ilCtrl->getParentReturnByClass("ilnewsitemgui"));
657  }
658 }