ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNewsItemGUIGen.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 define("IL_FORM_EDIT", 0);
25 define("IL_FORM_CREATE", 1);
26 define("IL_FORM_RE_EDIT", 2);
27 define("IL_FORM_RE_CREATE", 3);
28 
36 {
37 
38  protected $enable_edit = 0;
39  protected $context_obj_id;
40  protected $context_obj_type;
43  protected $form_edit_mode;
44 
49  public function __construct()
50  {
51  global $ilCtrl;
52 
53  $this->ctrl = $ilCtrl;
54 
55 
56  include_once("Services/News/classes/class.ilNewsItemGen.php");
57  if ($_GET["news_item_id"] > 0)
58  {
59  $this->news_item = new ilNewsItemGen($_GET["news_item_id"]);
60  }
61 
62  $this->ctrl->saveParameter($this, array("news_item_id"));
63 
64  // Init EnableEdit.
65  $this->setEnableEdit(false);
66 
67  // Init Context.
68  $this->setContextObjId($ilCtrl->getContextObjId());
69  $this->setContextObjType($ilCtrl->getContextObjType());
70  $this->setContextSubObjId($ilCtrl->getContextSubObjId());
71  $this->setContextSubObjType($ilCtrl->getContextSubObjType());
72 
73 
74  }
75 
80  public function &executeCommand()
81  {
82  global $ilCtrl;
83 
84  // get next class and command
85  $next_class = $this->ctrl->getNextClass($this);
86  $cmd = $this->ctrl->getCmd();
87 
88  switch ($next_class)
89  {
90  default:
91  $html = $this->$cmd();
92  break;
93  }
94 
95  return $html;
96 
97  }
98 
104  public function setEnableEdit($a_enable_edit = 0)
105  {
106  $this->enable_edit = $a_enable_edit;
107  }
108 
114  public function getEnableEdit()
115  {
116  return $this->enable_edit;
117  }
118 
124  public function setContextObjId($a_context_obj_id)
125  {
126  $this->context_obj_id = $a_context_obj_id;
127  }
128 
134  public function getContextObjId()
135  {
136  return $this->context_obj_id;
137  }
138 
144  public function setContextObjType($a_context_obj_type)
145  {
146  $this->context_obj_type = $a_context_obj_type;
147  }
148 
154  public function getContextObjType()
155  {
157  }
158 
164  public function setContextSubObjId($a_context_sub_obj_id)
165  {
166  $this->context_sub_obj_id = $a_context_sub_obj_id;
167  }
168 
174  public function getContextSubObjId()
175  {
177  }
178 
184  public function setContextSubObjType($a_context_sub_obj_type)
185  {
186  $this->context_sub_obj_type = $a_context_sub_obj_type;
187  }
188 
194  public function getContextSubObjType()
195  {
197  }
198 
204  public function setFormEditMode($a_form_edit_mode)
205  {
206  $this->form_edit_mode = $a_form_edit_mode;
207  }
208 
214  public function getFormEditMode()
215  {
216  return $this->form_edit_mode;
217  }
218 
223  public function createNewsItem()
224  {
226  return $this->form_gui->getHtml();
227 
228  }
229 
234  public function editNewsItem()
235  {
237  $this->getValuesNewsItem();
238  return $this->form_gui->getHtml();
239 
240  }
241 
246  public function saveNewsItem()
247  {
249  if ($this->form_gui->checkInput())
250  {
251  $this->news_item = new ilNewsItem();
252  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
253  $this->news_item->setContent($this->form_gui->getInput("news_content"));
254  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
255  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
256  $this->prepareSaveNewsItem($this->news_item);
257  $this->news_item->create();
258  $this->exitSaveNewsItem();
259  }
260  else
261  {
262  $this->form_gui->setValuesByPost();
263  return $this->form_gui->getHtml();
264  }
265 
266  }
267 
272  public function updateNewsItem()
273  {
275  if ($this->form_gui->checkInput())
276  {
277 
278  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
279  $this->news_item->setContent($this->form_gui->getInput("news_content"));
280  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
281  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
282  $this->news_item->update();
283  $this->exitUpdateNewsItem();
284  }
285  else
286  {
287  $this->form_gui->setValuesByPost();
288  return $this->form_gui->getHtml();
289  }
290 
291  }
292 
298  public function initFormNewsItem($a_mode)
299  {
300  global $lng;
301 
302  $lng->loadLanguageModule("news");
303 
304  include("Services/Form/classes/class.ilPropertyFormGUI.php");
305 
306  $this->form_gui = new ilPropertyFormGUI();
307 
308 
309  // Property Title
310  $text_input = new ilTextInputGUI($lng->txt("news_news_item_title"), "news_title");
311  $text_input->setInfo("");
312  $text_input->setRequired(true);
313  $text_input->setMaxLength(200);
314  $this->form_gui->addItem($text_input);
315 
316  // Property Content
317  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content"), "news_content");
318  $text_area->setInfo("");
319  $text_area->setRequired(false);
320  $this->form_gui->addItem($text_area);
321 
322  // Property Visibility
323  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_news_item_visibility"), "news_visibility");
324  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
325  $radio_group->addOption($radio_option);
326  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
327  $radio_group->addOption($radio_option);
328  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
329  $radio_group->setRequired(false);
330  $radio_group->setValue("users");
331  $this->form_gui->addItem($radio_group);
332 
333  // Property ContentLong
334  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content_long"), "news_content_long");
335  $text_area->setInfo($lng->txt("news_news_item_content_long_info"));
336  $text_area->setRequired(false);
337  $text_area->setCols("40");
338  $text_area->setRows("8");
339  $text_area->setUseRte(true);
340  $this->form_gui->addItem($text_area);
341 
342 
343  // save and cancel commands
344  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
345  {
346  $this->form_gui->addCommandButton("saveNewsItem", $lng->txt("save"));
347  $this->form_gui->addCommandButton("cancelSaveNewsItem", $lng->txt("cancel"));
348  }
349  else
350  {
351  $this->form_gui->addCommandButton("updateNewsItem", $lng->txt("save"));
352  $this->form_gui->addCommandButton("cancelUpdateNewsItem", $lng->txt("cancel"));
353  }
354 
355  $this->form_gui->setTitle($lng->txt("news_news_item_head"));
356  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
357 
358  $this->prepareFormNewsItem($this->form_gui);
359 
360  }
361 
366  public function getValuesNewsItem()
367  {
368  $values = array();
369 
370  $values["news_title"] = $this->news_item->getTitle();
371  $values["news_content"] = $this->news_item->getContent();
372  $values["news_visibility"] = $this->news_item->getVisibility();
373  $values["news_content_long"] = $this->news_item->getContentLong();
374 
375  $this->form_gui->setValuesByArray($values);
376 
377  }
378 
383  public function cancelSaveNewsItem()
384  {
385  global $ilCtrl;
386 
387  $ilCtrl->returnToParent($this);
388  }
389 
394  public function cancelUpdateNewsItem()
395  {
396  global $ilCtrl;
397 
398  $ilCtrl->returnToParent($this);
399  }
400 
405  public function exitSaveNewsItem()
406  {
407  global $ilCtrl;
408 
409  $ilCtrl->returnToParent($this);
410  }
411 
416  public function exitUpdateNewsItem()
417  {
418  global $ilCtrl;
419 
420  $ilCtrl->returnToParent($this);
421  }
422 
428  public function prepareSaveNewsItem(&$a_news_item)
429  {
430 
431  }
432 
438  public function prepareFormNewsItem(&$a_form_gui)
439  {
440 
441  }
442 
447  public function getNewsForContextBlock()
448  {
449  global $lng;
450 
451  include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
452  $block_gui = new ilNewsForContextBlockGUI(get_class($this));
453  $this->prepareBlockNewsForContext($block_gui);
454 
455  $news_item = new ilNewsItemGen();
456  $this->prepareBlockQueryNewsForContext($news_item);
457  $data = $news_item->queryNewsForContext();
458 
459  $block_gui->setTitle($lng->txt("news_block_news_for_context"));
460  $block_gui->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
461  $block_gui->setData($data);
462 
463  return $block_gui->getHTML();
464 
465  }
466 
472  public function prepareBlockNewsForContext(&$a_block_gui)
473  {
474 
475  }
476 
482  public function prepareBlockQueryNewsForContext(&$a_news_item)
483  {
484 
485  $a_news_item->setContextObjId($this->getContextObjId());
486  $a_news_item->setContextObjType($this->getContextObjType());
487  $a_news_item->setContextSubObjId($this->getContextSubObjId());
488  $a_news_item->setContextSubObjType($this->getContextSubObjType());
489 
490  }
491 
496  public function getNewsForContextTable()
497  {
498  global $lng;
499 
500  include_once("Services/News/classes/class.ilNewsForContextTableGUI.php");
501  $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable");
502 
503  $news_item = new ilNewsItemGen();
504  $this->prepareTableQueryNewsForContext($news_item);
505  $data = $news_item->queryNewsForContext();
506 
507  $table_gui->setTitle($lng->txt("news_table_news_for_context"));
508  $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News");
509  $table_gui->setData($data);
510  $this->prepareTableNewsForContext($table_gui);
511 
512  return $table_gui->getHTML();
513 
514  }
515 
521  public function prepareTableQueryNewsForContext(&$a_news_item)
522  {
523 
524  $a_news_item->setContextObjId($this->getContextObjId());
525  $a_news_item->setContextObjType($this->getContextObjType());
526  $a_news_item->setContextSubObjId($this->getContextSubObjId());
527  $a_news_item->setContextSubObjType($this->getContextSubObjType());
528 
529  }
530 
536  public function prepareTableNewsForContext(&$a_table_gui)
537  {
538 
539  }
540 
541 
542 }
543 ?>