ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilADTBasedObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 abstract class ilADTBasedObjectGUI
12 {
13  protected $object; // [ilADTBasedObject]
14 
23  public function __construct(ilObjectGUI $a_parent_gui)
24  {
25  $this->gui = $a_parent_gui;
26  $this->object = $this->initObject();
27  }
28 
32  abstract protected function initObject();
33 
34 
35  //
36  // VERY BASIC EXAMPLE OF FORM HANDLING
37  //
38 
44  public function editAction(ilADTGroupFormBridge $a_form = null)
45  {
46  global $tpl;
47 
48  if(!$a_form)
49  {
50  $a_form = $this->initForm();
51  }
52 
53  $tpl->setContent($a_form->getForm()->getHTML());
54  }
55 
61  abstract protected function prepareFormElements(ilADTGroupFormBridge $a_adt_form);
62 
68  protected function initForm()
69  {
70  global $tpl, $lng, $ilCtrl;
71 
72  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
73  $form = new ilPropertyFormGUI();
74  $form->setFormAction($ilCtrl->getFormAction($this->gui, "updateAction"));
75 
76  $adt_form = ilADTFactory::getInstance()->getFormBridgeForInstance($this->object->getProperties());
77 
78  // has to be done BEFORE prepareFormElements() ...
79  $adt_form->setForm($form);
80 
81  $this->prepareFormElements($adt_form);
82 
83  $adt_form->addToForm();
84  $adt_form->addJS($tpl);
85 
86  // :TODO:
87  $form->addCommandButton("updateAction", $lng->txt("save"));
88 
89  return $adt_form;
90  }
91 
95  public function updateAction()
96  {
97  global $lng, $ilCtrl;
98 
99  $adt_form = $this->initForm();
100  $valid = $adt_form->getForm()->checkInput(); // :TODO: return value is obsolete
101 
102  $old_chksum = $this->object->getProperties()->getCheckSum();
103 
104  $adt_form->importFromPost();
105  $valid = $adt_form->validate();
106 
107  $changed = ($old_chksum != $this->object->getProperties()->getCheckSum());
108 
109  // validation errors have top priority
110  if(!$valid)
111  {
112  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
113  return $this->editAction($adt_form);
114  }
115 
116  // :TODO: experimental, update only if necessary
117  if($changed)
118  {
119  if($this->object->update())
120  {
121  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
122  }
123  else
124  {
125  // error occured in db-layer (primary/unique)
126  foreach($this->object->getDBErrors() as $element_id => $codes)
127  {
128  $element = $adt_form->getElement($element_id);
129  if($element)
130  {
131  $element->setExternalErrors($this->object->translateDBErrorCodes($codes));
132  }
133  }
134 
135  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
136  return $this->editAction($adt_form);
137  }
138  }
139 
140  $ilCtrl->redirect($this->gui, "edit");
141  }
142 }
143 
144 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents a property form user interface.
$valid
getProperties()
Get properties.
Definition: PHPExcel.php:425
static getInstance()
Get singleton.
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
prepareFormElements(ilADTGroupFormBridge $a_adt_form)
Prepare/customize form elements.
updateAction()
Parse incoming values and update if valid.
Class ilObjectGUI Basic methods of all Output classes.
__construct(ilObjectGUI $a_parent_gui)
Constructor.
initObject()
Init ADT-based object.
editAction(ilADTGroupFormBridge $a_form=null)
Edit object ADT properties.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
initForm()
Init ADT-based form.
Create new PHPExcel object
obj_idprivate
global $lng
Definition: privfeed.php:17
ADT based-object GUI base class.