ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNewsItemGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once ("Services/News/classes/class.ilNewsItemGUIGen.php");
25 
35 {
36 
37  function __construct()
38  {
39  global $ilCtrl;
40 
42 
43  $ilCtrl->saveParameter($this, "add_mode");
44  }
45 
46  function getHTML()
47  {
48  global $lng, $ilCtrl;
49 
50  $lng->LoadLanguageModule("news");
51 
52  return $this->getNewsForContextBlock();
53  }
54 
60  public function prepareBlockNewsForContext(&$a_block_gui)
61  {
62  $a_block_gui->setParentClass("ilinfoscreengui");
63  $a_block_gui->setParentCmd("showSummary");
64  $a_block_gui->setEnableEdit($this->getEnableEdit());
65  }
66 
70  function prepareBlockQueryNewsForContext(&$a_news_item)
71  {
72  $a_news_item->setContextObjId($this->ctrl->getContextObjId());
73  $a_news_item->setContextObjType($this->ctrl->getContextObjType());
74  }
75 
79  function prepareSaveNewsItem(&$a_news_item)
80  {
81  global $ilUser;
82 
83  $a_news_item->setContextObjId($this->ctrl->getContextObjId());
84  $a_news_item->setContextObjType($this->ctrl->getContextObjType());
85  $a_news_item->setUserId($ilUser->getId());
86 
87  $news_set = new ilSetting("news");
88  if (!$news_set->get("enable_rss_for_internal"))
89  {
90  $a_news_item->setVisibility("users");
91  }
92  }
93 
99  public function prepareFormNewsItem(&$a_form_gui)
100  {
101  $a_form_gui->setTitleIcon(ilUtil::getImagePath("icon_news.gif"));
102 
103  $news_set = new ilSetting("news");
104  if (!$news_set->get("enable_rss_for_internal"))
105  {
106  $a_form_gui->removeItemByPostVar("news_visibility");
107  }
108  else
109  {
110  $nv = $a_form_gui->getItemByPostVar("news_visibility");
111  if (is_object($nv))
112  {
113  $nv->setValue(ilNewsItem::_getDefaultVisibilityForRefId($_GET["ref_id"]));
114  }
115  }
116  }
117 
122  function saveNewsItem()
123  {
124  if (!$this->getEnableEdit())
125  {
126  return;
127  }
128 
129  return parent::saveNewsItem();
130  }
131 
132  function exitSaveNewsItem()
133  {
134  global $ilCtrl;
135 
136  if ($_GET["add_mode"] == "block")
137  {
138  $ilCtrl->returnToParent($this);
139  }
140  else
141  {
142  $ilCtrl->redirect($this, "editNews");
143  }
144  }
145 
150  function updateNewsItem()
151  {
152  if (!$this->getEnableEdit())
153  {
154  return;
155  }
156 
157  return parent::updateNewsItem();
158  }
159 
161  {
162  global $ilCtrl;
163 
164  $ilCtrl->redirect($this, "editNews");
165  }
166 
172  {
173  return $this->editNews();
174  }
175 
181  {
182  global $ilCtrl;
183 
184  if ($_GET["add_mode"] == "block")
185  {
186  $ilCtrl->returnToParent($this);
187  }
188  else
189  {
190  return $this->editNews();
191  }
192  }
193 
194  function editNews()
195  {
196  if (!$this->getEnableEdit())
197  {
198  return;
199  }
200  return $this->getNewsForContextTable();
201  }
202 
203 
204  function cancelUpdate()
205  {
206  return $this->editNews();
207  }
208 
212  function prepareTableNewsForContext(&$a_table_gui)
213  {
214  global $ilCtrl, $lng;
215 
216  $a_table_gui->setDefaultOrderField("creation_date");
217  $a_table_gui->setDefaultOrderDirection("desc");
218  $a_table_gui->addCommandButton("createNewsItem", $lng->txt("add"));
219  $a_table_gui->addMultiCommand("confirmDeletionNewsItems", $lng->txt("delete"));
220  $a_table_gui->setTitle($lng->txt("news"), "icon_news.gif", $lng->txt("news"));
221  $a_table_gui->setSelectAllCheckbox("news_id");
222  }
223 
228  {
229  global $ilCtrl, $lng;
230 
231  if (!$this->getEnableEdit())
232  {
233  return;
234  }
235 
236  // check whether at least one item is selected
237  if (count($_POST["news_id"]) == 0)
238  {
239  ilUtil::sendInfo($lng->txt("no_checkbox"));
240  return $this->editNews();
241  }
242 
243  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
244  $c_gui = new ilConfirmationGUI();
245 
246  // set confirm/cancel commands
247  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteNewsItems"));
248  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
249  $c_gui->setCancel($lng->txt("cancel"), "editNews");
250  $c_gui->setConfirm($lng->txt("confirm"), "deleteNewsItems");
251 
252  // add items to delete
253  foreach($_POST["news_id"] as $news_id)
254  {
255  $news = new ilNewsItem($news_id);
256  $c_gui->addItem("news_id[]", $news_id, $news->getTitle(),
257  ilUtil::getImagePath("icon_news.gif"));
258  }
259 
260  return $c_gui->getHTML();
261  }
262 
266  function deleteNewsItems()
267  {
268  if (!$this->getEnableEdit())
269  {
270  return;
271  }
272  // delete all selected news items
273  foreach($_POST["news_id"] as $news_id)
274  {
275  $news = new ilNewsItem($news_id);
276  $news->delete();
277  }
278 
279  return $this->editNews();
280  }
281 }