ILIAS  Release_4_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 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once ("Services/News/classes/class.ilNewsItemGUIGen.php");
5 
15 {
16 
17  function __construct()
18  {
19  global $ilCtrl;
20 
22 
23  $ilCtrl->saveParameter($this, "add_mode");
24  }
25 
26  function getHTML()
27  {
28  global $lng, $ilCtrl;
29 
30  $lng->LoadLanguageModule("news");
31 
32  return $this->getNewsForContextBlock();
33  }
34 
40  public function prepareBlockNewsForContext(&$a_block_gui)
41  {
42  $a_block_gui->setParentClass("ilinfoscreengui");
43  $a_block_gui->setParentCmd("showSummary");
44  $a_block_gui->setEnableEdit($this->getEnableEdit());
45  }
46 
50  function prepareBlockQueryNewsForContext(&$a_news_item)
51  {
52  $a_news_item->setContextObjId($this->ctrl->getContextObjId());
53  $a_news_item->setContextObjType($this->ctrl->getContextObjType());
54  }
55 
59  function prepareSaveNewsItem(&$a_news_item)
60  {
61  global $ilUser;
62 
63  $a_news_item->setContextObjId($this->ctrl->getContextObjId());
64  $a_news_item->setContextObjType($this->ctrl->getContextObjType());
65  $a_news_item->setUserId($ilUser->getId());
66 
67  $news_set = new ilSetting("news");
68  if (!$news_set->get("enable_rss_for_internal"))
69  {
70  $a_news_item->setVisibility("users");
71  }
72  }
73 
79  public function prepareFormNewsItem(&$a_form_gui)
80  {
81  $a_form_gui->setTitleIcon(ilUtil::getImagePath("icon_news.gif"));
82 
83  $news_set = new ilSetting("news");
84  if (!$news_set->get("enable_rss_for_internal"))
85  {
86  $a_form_gui->removeItemByPostVar("news_visibility");
87  }
88  else
89  {
90  $nv = $a_form_gui->getItemByPostVar("news_visibility");
91  if (is_object($nv))
92  {
93  $nv->setValue(ilNewsItem::_getDefaultVisibilityForRefId($_GET["ref_id"]));
94  }
95  }
96  }
97 
102  function saveNewsItem()
103  {
104  if (!$this->getEnableEdit())
105  {
106  return;
107  }
108 
109  return parent::saveNewsItem();
110  }
111 
112  function exitSaveNewsItem()
113  {
114  global $ilCtrl;
115 
116  if ($_GET["add_mode"] == "block")
117  {
118  $ilCtrl->returnToParent($this);
119  }
120  else
121  {
122  $ilCtrl->redirect($this, "editNews");
123  }
124  }
125 
130  function updateNewsItem()
131  {
132  if (!$this->getEnableEdit())
133  {
134  return;
135  }
136 
137  return parent::updateNewsItem();
138  }
139 
141  {
142  global $ilCtrl;
143 
144  $ilCtrl->redirect($this, "editNews");
145  }
146 
152  {
153  return $this->editNews();
154  }
155 
161  {
162  global $ilCtrl;
163 
164  if ($_GET["add_mode"] == "block")
165  {
166  $ilCtrl->returnToParent($this);
167  }
168  else
169  {
170  return $this->editNews();
171  }
172  }
173 
174  function editNews()
175  {
176  if (!$this->getEnableEdit())
177  {
178  return;
179  }
180  return $this->getNewsForContextTable();
181  }
182 
183 
184  function cancelUpdate()
185  {
186  return $this->editNews();
187  }
188 
192  function prepareTableNewsForContext(&$a_table_gui)
193  {
194  global $ilCtrl, $lng;
195 
196  $a_table_gui->setDefaultOrderField("creation_date");
197  $a_table_gui->setDefaultOrderDirection("desc");
198  $a_table_gui->addCommandButton("createNewsItem", $lng->txt("add"));
199  $a_table_gui->addMultiCommand("confirmDeletionNewsItems", $lng->txt("delete"));
200  $a_table_gui->setTitle($lng->txt("news"), "icon_news.gif", $lng->txt("news"));
201  $a_table_gui->setSelectAllCheckbox("news_id");
202  }
203 
208  {
209  global $ilCtrl, $lng;
210 
211  if (!$this->getEnableEdit())
212  {
213  return;
214  }
215 
216  // check whether at least one item is selected
217  if (count($_POST["news_id"]) == 0)
218  {
219  ilUtil::sendFailure($lng->txt("no_checkbox"));
220  return $this->editNews();
221  }
222 
223  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
224  $c_gui = new ilConfirmationGUI();
225 
226  // set confirm/cancel commands
227  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteNewsItems"));
228  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
229  $c_gui->setCancel($lng->txt("cancel"), "editNews");
230  $c_gui->setConfirm($lng->txt("confirm"), "deleteNewsItems");
231 
232  // add items to delete
233  foreach($_POST["news_id"] as $news_id)
234  {
235  $news = new ilNewsItem($news_id);
236  $c_gui->addItem("news_id[]", $news_id, $news->getTitle(),
237  ilUtil::getImagePath("icon_news.gif"));
238  }
239 
240  return $c_gui->getHTML();
241  }
242 
246  function deleteNewsItems()
247  {
248  if (!$this->getEnableEdit())
249  {
250  return;
251  }
252  // delete all selected news items
253  foreach($_POST["news_id"] as $news_id)
254  {
255  $news = new ilNewsItem($news_id);
256  $news->delete();
257  }
258 
259  return $this->editNews();
260  }
261 }