ILIAS  Release_4_1_x_branch Revision 61804
 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.ilNewsItemGen.php");
40  if ($_GET["news_item_id"] > 0)
41  {
42  $this->news_item = new ilNewsItemGen($_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  $this->form_gui->setTitleIcon(ilUtil::getImagePath("icon_news.gif"));
310 
311  $news_set = new ilSetting("news");
312  if (!$news_set->get("enable_rss_for_internal"))
313  {
314  $this->form_gui->removeItemByPostVar("news_visibility");
315  }
316  else
317  {
318  $nv = $this->form_gui->getItemByPostVar("news_visibility");
319  if (is_object($nv))
320  {
321  $nv->setValue(ilNewsItem::_getDefaultVisibilityForRefId($_GET["ref_id"]));
322  }
323  }
324 
325  }
326 
331  public function getValuesNewsItem()
332  {
333  $values = array();
334 
335  $values["news_title"] = $this->news_item->getTitle();
336  $values["news_content"] = $this->news_item->getContent();
337  $values["news_visibility"] = $this->news_item->getVisibility();
338  $values["news_content_long"] = $this->news_item->getContentLong();
339 
340  $this->form_gui->setValuesByArray($values);
341 
342  }
343 
348  function saveNewsItem()
349  {
350  global $ilUser;
351 
352  if (!$this->getEnableEdit())
353  {
354  return;
355  }
356 
358  if ($this->form_gui->checkInput())
359  {
360  $this->news_item = new ilNewsItem();
361  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
362  $this->news_item->setContent($this->form_gui->getInput("news_content"));
363  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
364  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
365 
366 // changed
367  //$this->news_item->setContextObjId($this->ctrl->getContextObjId());
368  //$this->news_item->setContextObjType($this->ctrl->getContextObjType());
369  $this->news_item->setContextObjId($this->getContextObjId());
370  $this->news_item->setContextObjType($this->getContextObjType());
371  $this->news_item->setContextSubObjId($this->getContextSubObjId());
372  $this->news_item->setContextSubObjType($this->getContextSubObjType());
373  $this->news_item->setUserId($ilUser->getId());
374 
375  $news_set = new ilSetting("news");
376  if (!$news_set->get("enable_rss_for_internal"))
377  {
378  $this->news_item->setVisibility("users");
379  }
380 
381  $this->news_item->create();
382  $this->exitSaveNewsItem();
383  }
384  else
385  {
386  $this->form_gui->setValuesByPost();
387  return $this->form_gui->getHtml();
388  }
389 
390  }
391 
392  function exitSaveNewsItem()
393  {
394  global $ilCtrl;
395 
396  if ($_GET["add_mode"] == "block")
397  {
398  $ilCtrl->returnToParent($this);
399  }
400  else
401  {
402  $ilCtrl->redirect($this, "editNews");
403  }
404  }
405 
410  function updateNewsItem()
411  {
412  if (!$this->getEnableEdit())
413  {
414  return;
415  }
416 
418  if ($this->form_gui->checkInput())
419  {
420 
421  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
422  $this->news_item->setContent($this->form_gui->getInput("news_content"));
423  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
424  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
425  $this->news_item->update();
426  $this->exitUpdateNewsItem();
427  }
428  else
429  {
430  $this->form_gui->setValuesByPost();
431  return $this->form_gui->getHtml();
432  }
433  }
434 
436  {
437  global $ilCtrl;
438 
439  $ilCtrl->redirect($this, "editNews");
440  }
441 
447  {
448  return $this->editNews();
449  }
450 
456  {
457  global $ilCtrl;
458 
459  if ($_GET["add_mode"] == "block")
460  {
461  $ilCtrl->returnToParent($this);
462  }
463  else
464  {
465  return $this->editNews();
466  }
467  }
468 
474  function editNews()
475  {
476  global $ilTabs, $ilToolbar, $lng, $ilCtrl;
477 
478  $this->setTabs();
479 
480  $ilToolbar->addButton($lng->txt("news_add_news"),
481  $ilCtrl->getLinkTarget($this, "createNewsItem"));
482 
483  if (!$this->getEnableEdit())
484  {
485  return;
486  }
487  return $this->getNewsForContextTable();
488  }
489 
493  function cancelUpdate()
494  {
495  return $this->editNews();
496  }
497 
502  {
503  global $ilCtrl, $lng, $ilTabs;
504 
505  if (!$this->getEnableEdit())
506  {
507  return;
508  }
509 
510  // check whether at least one item is selected
511  if (count($_POST["news_id"]) == 0)
512  {
513  ilUtil::sendFailure($lng->txt("no_checkbox"));
514  return $this->editNews();
515  }
516 
517  $ilTabs->clearTargets();
518 
519  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
520  $c_gui = new ilConfirmationGUI();
521 
522  // set confirm/cancel commands
523  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteNewsItems"));
524  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
525  $c_gui->setCancel($lng->txt("cancel"), "editNews");
526  $c_gui->setConfirm($lng->txt("confirm"), "deleteNewsItems");
527 
528  // add items to delete
529  foreach($_POST["news_id"] as $news_id)
530  {
531  $news = new ilNewsItem($news_id);
532  $c_gui->addItem("news_id[]", $news_id, $news->getTitle(),
533  ilUtil::getImagePath("icon_news.gif"));
534  }
535 
536  return $c_gui->getHTML();
537  }
538 
542  function deleteNewsItems()
543  {
544  if (!$this->getEnableEdit())
545  {
546  return;
547  }
548  // delete all selected news items
549  foreach($_POST["news_id"] as $news_id)
550  {
551  $news = new ilNewsItem($news_id);
552  $news->delete();
553  }
554 
555  return $this->editNews();
556  }
557 
562  public function getNewsForContextBlock()
563  {
564  global $lng;
565 
566  include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
567  $block_gui = new ilNewsForContextBlockGUI(get_class($this));
568 
569  $block_gui->setParentClass("ilinfoscreengui");
570  $block_gui->setParentCmd("showSummary");
571  $block_gui->setEnableEdit($this->getEnableEdit());
572 
573 
574  $news_item = new ilNewsItemGen();
575 
576 // changed
577  //$news_item->setContextObjId($this->ctrl->getContextObjId());
578  //$news_item->setContextObjType($this->ctrl->getContextObjType());
579  $news_item->setContextObjId($this->getContextObjId());
580  $news_item->setContextObjType($this->getContextObjType());
581  $news_item->setContextSubObjId($this->getContextSubObjId());
582  $news_item->setContextSubObjType($this->getContextSubObjType());
583 
584  $data = $news_item->queryNewsForContext();
585 
586  $block_gui->setTitle($lng->txt("news_block_news_for_context"));
587  $block_gui->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
588  $block_gui->setData($data);
589 
590  return $block_gui->getHTML();
591 
592  }
593 
594 
599  public function getNewsForContextTable()
600  {
601  global $lng;
602 
603  $news_item = new ilNewsItem();
604  $news_item->setContextObjId($this->getContextObjId());
605  $news_item->setContextObjType($this->getContextObjType());
606  $news_item->setContextSubObjId($this->getContextSubObjId());
607  $news_item->setContextSubObjType($this->getContextSubObjType());
608 
609  $perm_ref_id = 0;
610  if (in_array($this->getContextObjType(), array("cat", "grp", "crs", "root")))
611  {
612  $data = $news_item->getNewsForRefId($_GET["ref_id"], false, false,
613  0, true, false, true, true);
614  }
615  else
616  {
617  $perm_ref_id = $_GET["ref_id"];
618  if ($this->getContextSubObjId() > 0)
619  {
620  $data = $news_item->queryNewsForContext(false, 0,
621  "", true, true);
622  }
623  else
624  {
625  $data = $news_item->queryNewsForContext();
626  }
627  }
628 
629  include_once("Services/News/classes/class.ilNewsForContextTableGUI.php");
630  $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable", $perm_ref_id);
631 
632  $table_gui->setTitle($lng->txt("news_table_news_for_context"));
633  $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News");
634  $table_gui->setData($data);
635 
636  $table_gui->setDefaultOrderField("creation_date");
637  $table_gui->setDefaultOrderDirection("desc");
638  $table_gui->addMultiCommand("confirmDeletionNewsItems", $lng->txt("delete"));
639  $table_gui->setTitle($lng->txt("news"), "icon_news.gif", $lng->txt("news"));
640  $table_gui->setSelectAllCheckbox("news_id");
641 
642 
643  return $table_gui->getHTML();
644 
645  }
646 
653  function setTabs()
654  {
655  global $ilTabs, $ilCtrl, $lng;
656 
657  $ilTabs->clearTargets();
658  $ilTabs->setBackTarget($lng->txt("back"),
659  $ilCtrl->getParentReturnByClass("ilnewsitemgui"));
660  }
661 }