ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilADTFormBridge Class Reference

ADT form bridge base class. More...

+ Inheritance diagram for ilADTFormBridge:
+ Collaboration diagram for ilADTFormBridge:

Public Member Functions

 __construct (ilADT $a_adt)
 Constructor. More...
 
 getADT ()
 Get ADT. More...
 
 setForm (ilPropertyFormGUI $a_form)
 Set form. More...
 
 getForm ()
 Get form. More...
 
 setElementId ($a_value)
 Set element id (aka form field) More...
 
 getElementId ()
 Get element id. More...
 
 setTitle ($a_value)
 Set title (aka form field caption) More...
 
 getTitle ()
 Get title. More...
 
 setInfo ($a_value)
 Set info (aka form field info text) More...
 
 getInfo ()
 Get info. More...
 
 setParentElement ($a_value)
 Set parent element. More...
 
 getParentElement ()
 Get parent element. More...
 
 setDisabled ($a_value)
 Set disabled. More...
 
 isDisabled ()
 Get disabled. More...
 
 setRequired ($a_value)
 Set required. More...
 
 isRequired ()
 Get required. More...
 
 addToForm ()
 Add ADT-specific fields to form. More...
 
 addJS (ilTemplate $a_tpl)
 Add ADT-specific JS-files to template. More...
 
 shouldBeImportedFromPost (ilADTFormBridge $a_parent_adt=null)
 Check if incoming values should be imported at all. More...
 
 importFromPost ()
 Import values from form request POST data. More...
 
 validate ()
 Validate ADT and parse error codes. More...
 
 setExternalErrors ($a_errors)
 

Protected Member Functions

 isValidADT (ilADT $a_adt)
 Check if given ADT is valid. More...
 
 setADT (ilADT $a_adt)
 Set ADT. More...
 
 addBasicFieldProperties (ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
 Helper method to handle generic properties like setRequired(), setInfo() More...
 
 findParentElementInForm ()
 Try to find parent element in form (could be option) More...
 
 addToParentElement (ilFormPropertyGUI $a_field)
 Add form field to parent element. More...
 
 isActiveForSubItems ($a_parent_option=null)
 Check if element is currently active for subitem(s) More...
 

Protected Attributes

 $adt
 
 $form
 
 $id
 
 $title
 
 $info
 
 $parent_element
 
 $required
 
 $disabled
 

Detailed Description

ADT form bridge base class.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 11 of file class.ilADTFormBridge.php.

Constructor & Destructor Documentation

◆ __construct()

ilADTFormBridge::__construct ( ilADT  $a_adt)

Constructor.

Parameters
ilADT$a_adt
Returns
self

Definition at line 28 of file class.ilADTFormBridge.php.

References isValidADT(), and setADT().

29  {
30  $this->setADT($a_adt);
31  }
setADT(ilADT $a_adt)
Set ADT.
+ Here is the call graph for this function:

Member Function Documentation

◆ addBasicFieldProperties()

ilADTFormBridge::addBasicFieldProperties ( ilFormPropertyGUI  $a_field,
ilADTDefinition  $a_def 
)
protected

Helper method to handle generic properties like setRequired(), setInfo()

Parameters
ilFormPropertyGUI$a_field
ilADTDefinition$a_def

Definition at line 227 of file class.ilADTFormBridge.php.

References $info, getInfo(), isDisabled(), isRequired(), ilFormPropertyGUI\setDisabled(), ilFormPropertyGUI\setInfo(), and ilFormPropertyGUI\setRequired().

Referenced by ilADTBooleanFormBridge\addToForm(), ilADTLocationFormBridge\addToForm(), ilADTMultiTextFormBridge\addToForm(), ilADTFloatFormBridge\addToForm(), ilADTIntegerFormBridge\addToForm(), ilADTDateFormBridge\addToForm(), ilADTDateTimeFormBridge\addToForm(), ilADTMultiEnumFormBridge\addToForm(), ilADTInternalLinkFormBridge\addToForm(), ilADTExternalLinkFormBridge\addToForm(), ilADTEnumFormBridge\addToForm(), and ilADTTextFormBridge\addToForm().

228  {
229  if ((bool) $this->isDisabled()) {
230  $a_field->setDisabled(true);
231  } elseif ($this->isRequired()) {
232  $a_field->setRequired(true);
233  }
234 
235  $info = $this->getInfo();
236  if ($info) {
237  $a_field->setInfo($info);
238  }
239  }
isRequired()
Get required.
isDisabled()
Get disabled.
setInfo($a_info)
Set Information Text.
setDisabled($a_disabled)
Set Disabled.
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addJS()

ilADTFormBridge::addJS ( ilTemplate  $a_tpl)

Add ADT-specific JS-files to template.

Parameters
ilTemplate$a_tpl

Definition at line 301 of file class.ilADTFormBridge.php.

302  {
303  }

◆ addToForm()

ilADTFormBridge::addToForm ( )
abstract

Add ADT-specific fields to form.

Referenced by addToParentElement().

+ Here is the caller graph for this function:

◆ addToParentElement()

ilADTFormBridge::addToParentElement ( ilFormPropertyGUI  $a_field)
protected

Add form field to parent element.

Parameters
ilFormPropertyGUI$a_field

Definition at line 281 of file class.ilADTFormBridge.php.

References addToForm(), findParentElementInForm(), and getForm().

Referenced by ilADTBooleanFormBridge\addToForm(), ilADTLocationFormBridge\addToForm(), ilADTMultiTextFormBridge\addToForm(), ilADTFloatFormBridge\addToForm(), ilADTIntegerFormBridge\addToForm(), ilADTDateFormBridge\addToForm(), ilADTDateTimeFormBridge\addToForm(), ilADTMultiEnumFormBridge\addToForm(), ilADTInternalLinkFormBridge\addToForm(), ilADTExternalLinkFormBridge\addToForm(), ilADTEnumFormBridge\addToForm(), and ilADTTextFormBridge\addToForm().

282  {
283  $field = $this->findParentElementInForm();
284  if ($field) {
285  $field->addSubItem($a_field);
286  } elseif ($this->getForm() instanceof ilPropertyFormGUI) {
287  $this->getForm()->addItem($a_field);
288  }
289  }
findParentElementInForm()
Try to find parent element in form (could be option)
This class represents a property form user interface.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findParentElementInForm()

ilADTFormBridge::findParentElementInForm ( )
protected

Try to find parent element in form (could be option)

Returns
ilFormPropertyGUI

Definition at line 246 of file class.ilADTFormBridge.php.

References getForm(), and getParentElement().

Referenced by addToParentElement().

247  {
248  $parent_def = $this->getParentElement();
249  if ($parent_def) {
250  if (is_array($parent_def)) {
251  $parent_option = $parent_def[1];
252  $parent_def = $parent_def[0];
253  }
254 
255  // :TODO: throw exception on invalid definition ?!
256 
257  $parent_field = $this->getForm()->getItemByPostVar($parent_def);
258  if ($parent_field instanceof ilSubEnabledFormPropertyGUI) {
259  // radio/checkbox group
260  if ($parent_option && method_exists($parent_field, "getOptions")) {
261  foreach ($parent_field->getOptions() as $option) {
262  if ($option->getValue() == $parent_option) {
263  $parent_field = $option;
264  break;
265  }
266  }
267  }
268  }
269 
270  if ($parent_field) {
271  return $parent_field;
272  }
273  }
274  }
getParentElement()
Get parent element.
This class represents a property that may include a sub form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getADT()

◆ getElementId()

◆ getForm()

◆ getInfo()

ilADTFormBridge::getInfo ( )

Get info.

Returns
string

Definition at line 148 of file class.ilADTFormBridge.php.

References $info.

Referenced by addBasicFieldProperties(), and ilADTGroupFormBridge\addToForm().

149  {
150  return $this->info;
151  }
+ Here is the caller graph for this function:

◆ getParentElement()

ilADTFormBridge::getParentElement ( )

Get parent element.

Returns
string

Definition at line 171 of file class.ilADTFormBridge.php.

Referenced by findParentElementInForm(), and shouldBeImportedFromPost().

172  {
173  return $this->parent;
174  }
+ Here is the caller graph for this function:

◆ getTitle()

◆ importFromPost()

ilADTFormBridge::importFromPost ( )
abstract

Import values from form request POST data.

Referenced by shouldBeImportedFromPost().

+ Here is the caller graph for this function:

◆ isActiveForSubItems()

ilADTFormBridge::isActiveForSubItems (   $a_parent_option = null)
protected

Check if element is currently active for subitem(s)

Parameters
mixed$a_parent_option
Returns
bool

Definition at line 311 of file class.ilADTFormBridge.php.

References getADT().

312  {
313  return !$this->getADT()->isNull();
314  }
+ Here is the call graph for this function:

◆ isDisabled()

ilADTFormBridge::isDisabled ( )

Get disabled.

Returns
bool

Definition at line 191 of file class.ilADTFormBridge.php.

References $disabled.

Referenced by addBasicFieldProperties(), and shouldBeImportedFromPost().

192  {
193  return $this->disabled;
194  }
+ Here is the caller graph for this function:

◆ isRequired()

ilADTFormBridge::isRequired ( )

Get required.

Returns
required

Definition at line 211 of file class.ilADTFormBridge.php.

References $required.

Referenced by addBasicFieldProperties(), ilADTLocationFormBridge\addToForm(), ilADTEnumFormBridge\addToForm(), ilADTLocationFormBridge\importFromPost(), and validate().

212  {
213  return $this->required;
214  }
+ Here is the caller graph for this function:

◆ isValidADT()

ilADTFormBridge::isValidADT ( ilADT  $a_adt)
abstractprotected

Check if given ADT is valid.

:TODO: This could be avoided with type-specifc constructors :TODO: bridge base class?

Parameters
ilADT$a_adt

Referenced by __construct(), and setADT().

+ Here is the caller graph for this function:

◆ setADT()

ilADTFormBridge::setADT ( ilADT  $a_adt)
protected

Set ADT.

Exceptions
Exception
Parameters
ilADT$a_adt

Definition at line 54 of file class.ilADTFormBridge.php.

References isValidADT().

Referenced by __construct().

55  {
56  if (!$this->isValidADT($a_adt)) {
57  throw new Exception('ADTFormBridge Type mismatch.');
58  }
59 
60  $this->adt = $a_adt;
61  }
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDisabled()

ilADTFormBridge::setDisabled (   $a_value)

Set disabled.

Parameters
bool$a_value

Definition at line 181 of file class.ilADTFormBridge.php.

182  {
183  $this->disabled = (bool) $a_value;
184  }

◆ setElementId()

ilADTFormBridge::setElementId (   $a_value)

Set element id (aka form field)

Parameters
string$a_value

Definition at line 98 of file class.ilADTFormBridge.php.

References string.

99  {
100  $this->id = (string) $a_value;
101  }
Add rich text string

◆ setExternalErrors()

ilADTFormBridge::setExternalErrors (   $a_errors)

Definition at line 379 of file class.ilADTFormBridge.php.

References getElementId(), and getForm().

380  {
381  $field = $this->getForm()->getItemByPostvar($this->getElementId());
382  $field->setAlert(implode("<br />", $a_errors));
383  }
getElementId()
Get element id.
+ Here is the call graph for this function:

◆ setForm()

ilADTFormBridge::setForm ( ilPropertyFormGUI  $a_form)

Set form.

Parameters
ilPropertyFormGUI$a_form

Definition at line 78 of file class.ilADTFormBridge.php.

79  {
80  $this->form = $a_form;
81  }

◆ setInfo()

ilADTFormBridge::setInfo (   $a_value)

Set info (aka form field info text)

Parameters
string$a_value

Definition at line 138 of file class.ilADTFormBridge.php.

Referenced by ilADTTestGUI\prepareFormElements().

139  {
140  $this->info = trim($a_value);
141  }
+ Here is the caller graph for this function:

◆ setParentElement()

ilADTFormBridge::setParentElement (   $a_value)

Set parent element.

Parameters
string | array$a_value

Definition at line 158 of file class.ilADTFormBridge.php.

References string.

159  {
160  if (!is_array($a_value)) {
161  $a_value = (string) $a_value;
162  }
163  $this->parent = $a_value;
164  }
Add rich text string

◆ setRequired()

ilADTFormBridge::setRequired (   $a_value)

Set required.

Parameters
bool$a_value

Definition at line 201 of file class.ilADTFormBridge.php.

202  {
203  $this->required = (bool) $a_value;
204  }

◆ setTitle()

ilADTFormBridge::setTitle (   $a_value)

Set title (aka form field caption)

Parameters
string$a_value

Definition at line 118 of file class.ilADTFormBridge.php.

Referenced by ilADTTestGUI\prepareFormElements().

119  {
120  $this->title = trim($a_value);
121  }
+ Here is the caller graph for this function:

◆ shouldBeImportedFromPost()

ilADTFormBridge::shouldBeImportedFromPost ( ilADTFormBridge  $a_parent_adt = null)

Check if incoming values should be imported at all.

Parameters
ilADTFormBridge$a_parent_adt
Returns
bool

Definition at line 322 of file class.ilADTFormBridge.php.

References $parent_element, getParentElement(), importFromPost(), and isDisabled().

323  {
324  if ($this->isDisabled()) {
325  return false;
326  }
327 
328  // inactive parent elements disable importing
329  if ($a_parent_adt) {
330  $parent_option = null;
332  if (is_array($parent_element)) {
333  $parent_option = $parent_element[1];
334  }
335  return $a_parent_adt->isActiveForSubItems($parent_option);
336  }
337 
338  return true;
339  }
isDisabled()
Get disabled.
isActiveForSubItems($a_parent_option=null)
Check if element is currently active for subitem(s)
getParentElement()
Get parent element.
+ Here is the call graph for this function:

◆ validate()

ilADTFormBridge::validate ( )

Validate ADT and parse error codes.

Returns
boolean

Definition at line 351 of file class.ilADTFormBridge.php.

References $lng, array, getADT(), getElementId(), getForm(), and isRequired().

352  {
353  global $lng;
354 
355  // ilADTFormBridge->isRequired() != ilADT->allowNull()
356  if ($this->isRequired() && $this->getADT()->isNull()) {
357  $field = $this->getForm()->getItemByPostvar($this->getElementId());
358  $field->setAlert($lng->txt("msg_input_is_required"));
359  return false;
360  }
361  // no need to further validate if no value given
362  elseif (!$this->getADT()->isValid()) {
363  $tmp = array();
364 
365  $mess = $this->getADT()->getValidationErrors();
366  foreach ($mess as $error_code) {
367  $tmp[] = $this->getADT()->translateErrorCode($error_code);
368  }
369 
370  $field = $this->getForm()->getItemByPostvar($this->getElementId());
371  $field->setAlert(implode("<br />", $tmp));
372 
373  return false;
374  }
375 
376  return true;
377  }
isRequired()
Get required.
Create styles array
The data for the language used.
getElementId()
Get element id.
global $lng
Definition: privfeed.php:17
+ Here is the call graph for this function:

Field Documentation

◆ $adt

ilADTFormBridge::$adt
protected

Definition at line 13 of file class.ilADTFormBridge.php.

Referenced by ilADTLocationFormBridge\addToForm(), and getADT().

◆ $disabled

ilADTFormBridge::$disabled
protected

Definition at line 20 of file class.ilADTFormBridge.php.

Referenced by isDisabled().

◆ $form

ilADTFormBridge::$form
protected

Definition at line 14 of file class.ilADTFormBridge.php.

Referenced by getForm().

◆ $id

ilADTFormBridge::$id
protected

Definition at line 15 of file class.ilADTFormBridge.php.

Referenced by getElementId().

◆ $info

ilADTFormBridge::$info
protected

Definition at line 17 of file class.ilADTFormBridge.php.

Referenced by addBasicFieldProperties(), and getInfo().

◆ $parent_element

ilADTFormBridge::$parent_element
protected

Definition at line 18 of file class.ilADTFormBridge.php.

Referenced by shouldBeImportedFromPost().

◆ $required

ilADTFormBridge::$required
protected

Definition at line 19 of file class.ilADTFormBridge.php.

Referenced by isRequired().

◆ $title

ilADTFormBridge::$title
protected

The documentation for this class was generated from the following file: