ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNewsItemGUIGen.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 define("IL_FORM_EDIT", 0);
6 define("IL_FORM_CREATE", 1);
7 define("IL_FORM_RE_EDIT", 2);
8 define("IL_FORM_RE_CREATE", 3);
9 
17 {
18 
19  protected $enable_edit = 0;
20  protected $context_obj_id;
21  protected $context_obj_type;
24  protected $form_edit_mode;
25 
30  public function __construct()
31  {
32  global $ilCtrl;
33 
34  $this->ctrl = $ilCtrl;
35 
36 
37  include_once("Services/News/classes/class.ilNewsItem.php");
38  if ($_GET["news_item_id"] > 0)
39  {
40  $this->news_item = new ilNewsItem($_GET["news_item_id"]);
41  }
42 
43  $this->ctrl->saveParameter($this, array("news_item_id"));
44 
45  // Init EnableEdit.
46  $this->setEnableEdit(false);
47 
48  // Init Context.
49  $this->setContextObjId($ilCtrl->getContextObjId());
50  $this->setContextObjType($ilCtrl->getContextObjType());
51  $this->setContextSubObjId($ilCtrl->getContextSubObjId());
52  $this->setContextSubObjType($ilCtrl->getContextSubObjType());
53 
54 
55  }
56 
61  public function &executeCommand()
62  {
63  global $ilCtrl;
64 
65  // get next class and command
66  $next_class = $this->ctrl->getNextClass($this);
67  $cmd = $this->ctrl->getCmd();
68 
69  switch ($next_class)
70  {
71  default:
72  $html = $this->$cmd();
73  break;
74  }
75 
76  return $html;
77 
78  }
79 
85  public function setEnableEdit($a_enable_edit = 0)
86  {
87  $this->enable_edit = $a_enable_edit;
88  }
89 
95  public function getEnableEdit()
96  {
97  return $this->enable_edit;
98  }
99 
105  public function setContextObjId($a_context_obj_id)
106  {
107  $this->context_obj_id = $a_context_obj_id;
108  }
109 
115  public function getContextObjId()
116  {
117  return $this->context_obj_id;
118  }
119 
125  public function setContextObjType($a_context_obj_type)
126  {
127  $this->context_obj_type = $a_context_obj_type;
128  }
129 
135  public function getContextObjType()
136  {
138  }
139 
145  public function setContextSubObjId($a_context_sub_obj_id)
146  {
147  $this->context_sub_obj_id = $a_context_sub_obj_id;
148  }
149 
155  public function getContextSubObjId()
156  {
158  }
159 
165  public function setContextSubObjType($a_context_sub_obj_type)
166  {
167  $this->context_sub_obj_type = $a_context_sub_obj_type;
168  }
169 
175  public function getContextSubObjType()
176  {
178  }
179 
185  public function setFormEditMode($a_form_edit_mode)
186  {
187  $this->form_edit_mode = $a_form_edit_mode;
188  }
189 
195  public function getFormEditMode()
196  {
197  return $this->form_edit_mode;
198  }
199 
204  public function createNewsItem()
205  {
207  return $this->form_gui->getHtml();
208 
209  }
210 
215  public function editNewsItem()
216  {
218  $this->getValuesNewsItem();
219  return $this->form_gui->getHtml();
220 
221  }
222 
227  public function saveNewsItem()
228  {
230  if ($this->form_gui->checkInput())
231  {
232  $this->news_item = new ilNewsItem();
233  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
234  $this->news_item->setContent($this->form_gui->getInput("news_content"));
235  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
236  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
237  $this->prepareSaveNewsItem($this->news_item);
238  $this->news_item->create();
239  $this->exitSaveNewsItem();
240  }
241  else
242  {
243  $this->form_gui->setValuesByPost();
244  return $this->form_gui->getHtml();
245  }
246 
247  }
248 
253  public function updateNewsItem()
254  {
256  if ($this->form_gui->checkInput())
257  {
258 
259  $this->news_item->setTitle($this->form_gui->getInput("news_title"));
260  $this->news_item->setContent($this->form_gui->getInput("news_content"));
261  $this->news_item->setVisibility($this->form_gui->getInput("news_visibility"));
262  $this->news_item->setContentLong($this->form_gui->getInput("news_content_long"));
263  $this->news_item->update();
264  $this->exitUpdateNewsItem();
265  }
266  else
267  {
268  $this->form_gui->setValuesByPost();
269  return $this->form_gui->getHtml();
270  }
271 
272  }
273 
279  public function initFormNewsItem($a_mode)
280  {
281  global $lng;
282 
283  $lng->loadLanguageModule("news");
284 
285  include("Services/Form/classes/class.ilPropertyFormGUI.php");
286 
287  $this->form_gui = new ilPropertyFormGUI();
288 
289 
290  // Property Title
291  $text_input = new ilTextInputGUI($lng->txt("news_news_item_title"), "news_title");
292  $text_input->setInfo("");
293  $text_input->setRequired(true);
294  $text_input->setMaxLength(200);
295  $this->form_gui->addItem($text_input);
296 
297  // Property Content
298  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content"), "news_content");
299  $text_area->setInfo("");
300  $text_area->setRequired(false);
301  $this->form_gui->addItem($text_area);
302 
303  // Property Visibility
304  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_news_item_visibility"), "news_visibility");
305  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "users");
306  $radio_group->addOption($radio_option);
307  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "public");
308  $radio_group->addOption($radio_option);
309  $radio_group->setInfo($lng->txt("news_news_item_visibility_info"));
310  $radio_group->setRequired(false);
311  $radio_group->setValue("users");
312  $this->form_gui->addItem($radio_group);
313 
314  // Property ContentLong
315  $text_area = new ilTextAreaInputGUI($lng->txt("news_news_item_content_long"), "news_content_long");
316  $text_area->setInfo($lng->txt("news_news_item_content_long_info"));
317  $text_area->setRequired(false);
318  $text_area->setCols("40");
319  $text_area->setRows("8");
320  $text_area->setUseRte(true);
321  $this->form_gui->addItem($text_area);
322 
323 
324  // save and cancel commands
325  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
326  {
327  $this->form_gui->addCommandButton("saveNewsItem", $lng->txt("save"));
328  $this->form_gui->addCommandButton("cancelSaveNewsItem", $lng->txt("cancel"));
329  }
330  else
331  {
332  $this->form_gui->addCommandButton("updateNewsItem", $lng->txt("save"));
333  $this->form_gui->addCommandButton("cancelUpdateNewsItem", $lng->txt("cancel"));
334  }
335 
336  $this->form_gui->setTitle($lng->txt("news_news_item_head"));
337  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
338 
339  $this->prepareFormNewsItem($this->form_gui);
340 
341  }
342 
347  public function getValuesNewsItem()
348  {
349  $values = array();
350 
351  $values["news_title"] = $this->news_item->getTitle();
352  $values["news_content"] = $this->news_item->getContent();
353  $values["news_visibility"] = $this->news_item->getVisibility();
354  $values["news_content_long"] = $this->news_item->getContentLong();
355 
356  $this->form_gui->setValuesByArray($values);
357 
358  }
359 
364  public function cancelSaveNewsItem()
365  {
366  global $ilCtrl;
367 
368  $ilCtrl->returnToParent($this);
369  }
370 
375  public function cancelUpdateNewsItem()
376  {
377  global $ilCtrl;
378 
379  $ilCtrl->returnToParent($this);
380  }
381 
386  public function exitSaveNewsItem()
387  {
388  global $ilCtrl;
389 
390  $ilCtrl->returnToParent($this);
391  }
392 
397  public function exitUpdateNewsItem()
398  {
399  global $ilCtrl;
400 
401  $ilCtrl->returnToParent($this);
402  }
403 
409  public function prepareSaveNewsItem(&$a_news_item)
410  {
411 
412  }
413 
419  public function prepareFormNewsItem(&$a_form_gui)
420  {
421 
422  }
423 
428  public function getNewsForContextBlock()
429  {
430  global $lng;
431 
432  include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
433  $block_gui = new ilNewsForContextBlockGUI(get_class($this));
434  $this->prepareBlockNewsForContext($block_gui);
435 
436  $news_item = new ilNewsItem();
437  $this->prepareBlockQueryNewsForContext($news_item);
438  $data = $news_item->queryNewsForContext();
439 
440  $block_gui->setTitle($lng->txt("news_block_news_for_context"));
441  $block_gui->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
442  $block_gui->setData($data);
443 
444  return $block_gui->getHTML();
445 
446  }
447 
453  public function prepareBlockNewsForContext(&$a_block_gui)
454  {
455 
456  }
457 
463  public function prepareBlockQueryNewsForContext(&$a_news_item)
464  {
465 
466  $a_news_item->setContextObjId($this->getContextObjId());
467  $a_news_item->setContextObjType($this->getContextObjType());
468  $a_news_item->setContextSubObjId($this->getContextSubObjId());
469  $a_news_item->setContextSubObjType($this->getContextSubObjType());
470 
471  }
472 
477  public function getNewsForContextTable()
478  {
479  global $lng;
480 
481  include_once("Services/News/classes/class.ilNewsForContextTableGUI.php");
482  $table_gui = new ilNewsForContextTableGUI($this, "getNewsForContextTable");
483 
484  $news_item = new ilNewsItem();
485  $this->prepareTableQueryNewsForContext($news_item);
486  $data = $news_item->queryNewsForContext();
487 
488  $table_gui->setTitle($lng->txt("news_table_news_for_context"));
489  $table_gui->setRowTemplate("tpl.table_row_news_for_context.html", "Services/News");
490  $table_gui->setData($data);
491  $this->prepareTableNewsForContext($table_gui);
492 
493  return $table_gui->getHTML();
494 
495  }
496 
502  public function prepareTableQueryNewsForContext(&$a_news_item)
503  {
504 
505  $a_news_item->setContextObjId($this->getContextObjId());
506  $a_news_item->setContextObjType($this->getContextObjType());
507  $a_news_item->setContextSubObjId($this->getContextSubObjId());
508  $a_news_item->setContextSubObjType($this->getContextSubObjType());
509 
510  }
511 
517  public function prepareTableNewsForContext(&$a_table_gui)
518  {
519 
520  }
521 
522 
523 }
524 ?>