ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
11abstract 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 $DIC;
47
48 $tpl = $DIC['tpl'];
49
50 if (!$a_form) {
51 $a_form = $this->initForm();
52 }
53
54 $tpl->setContent($a_form->getForm()->getHTML());
55 }
56
62 abstract protected function prepareFormElements(ilADTGroupFormBridge $a_adt_form);
63
69 protected function initForm()
70 {
71 global $DIC;
72
73 $tpl = $DIC['tpl'];
74 $lng = $DIC['lng'];
75 $ilCtrl = $DIC['ilCtrl'];
76
77 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
79 $form->setFormAction($ilCtrl->getFormAction($this->gui, "updateAction"));
80
81 $adt_form = ilADTFactory::getInstance()->getFormBridgeForInstance($this->object->getProperties());
82
83 // has to be done BEFORE prepareFormElements() ...
84 $adt_form->setForm($form);
85
86 $this->prepareFormElements($adt_form);
87
88 $adt_form->addToForm();
89 $adt_form->addJS($tpl);
90
91 // :TODO:
92 $form->addCommandButton("updateAction", $lng->txt("save"));
93
94 return $adt_form;
95 }
96
100 public function updateAction()
101 {
102 global $DIC;
103
104 $lng = $DIC['lng'];
105 $ilCtrl = $DIC['ilCtrl'];
106
107 $adt_form = $this->initForm();
108 $valid = $adt_form->getForm()->checkInput(); // :TODO: return value is obsolete
109
110 $old_chksum = $this->object->getProperties()->getCheckSum();
111
112 $adt_form->importFromPost();
113 $valid = $adt_form->validate();
114
115 $changed = ($old_chksum != $this->object->getProperties()->getCheckSum());
116
117 // validation errors have top priority
118 if (!$valid) {
119 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
120 return $this->editAction($adt_form);
121 }
122
123 // :TODO: experimental, update only if necessary
124 if ($changed) {
125 if ($this->object->update()) {
126 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
127 } else {
128 // error occured in db-layer (primary/unique)
129 foreach ($this->object->getDBErrors() as $element_id => $codes) {
130 $element = $adt_form->getElement($element_id);
131 if ($element) {
132 $element->setExternalErrors($this->object->translateDBErrorCodes($codes));
133 }
134 }
135
136 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
137 return $this->editAction($adt_form);
138 }
139 }
140
141 $ilCtrl->redirect($this->gui, "edit");
142 }
143}
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
ADT based-object GUI base class.
editAction(ilADTGroupFormBridge $a_form=null)
Edit object ADT properties.
updateAction()
Parse incoming values and update if valid.
initObject()
Init ADT-based object.
initForm()
Init ADT-based form.
prepareFormElements(ilADTGroupFormBridge $a_adt_form)
Prepare/customize form elements.
__construct(ilObjectGUI $a_parent_gui)
Constructor.
static getInstance()
Get singleton.
Class ilObjectGUI Basic methods of all Output classes.
This class represents a property form user interface.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$valid
global $ilCtrl
Definition: ilias.php:18
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$lng