ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 229 of file class.ilADTFormBridge.php.

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

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

230  {
231  if((bool)$this->isDisabled())
232  {
233  $a_field->setDisabled(true);
234  }
235  else if($this->isRequired())
236  {
237  $a_field->setRequired(true);
238  }
239 
240  $info = $this->getInfo();
241  if($info)
242  {
243  $a_field->setInfo($info);
244  }
245  }
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 317 of file class.ilADTFormBridge.php.

318  {
319 
320  }

◆ 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 294 of file class.ilADTFormBridge.php.

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

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

295  {
296  $field = $this->findParentElementInForm();
297  if($field)
298  {
299  $field->addSubItem($a_field);
300  }
301  else if($this->getForm() instanceof ilPropertyFormGUI)
302  {
303  $this->getForm()->addItem($a_field);
304  }
305  }
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 252 of file class.ilADTFormBridge.php.

References getForm(), and getParentElement().

Referenced by addToParentElement().

253  {
254  $parent_def = $this->getParentElement();
255  if($parent_def)
256  {
257  if(is_array($parent_def))
258  {
259  $parent_option = $parent_def[1];
260  $parent_def = $parent_def[0];
261  }
262 
263  // :TODO: throw exception on invalid definition ?!
264 
265  $parent_field = $this->getForm()->getItemByPostVar($parent_def);
266  if($parent_field instanceof ilSubEnabledFormPropertyGUI)
267  {
268  // radio/checkbox group
269  if($parent_option && method_exists($parent_field, "getOptions"))
270  {
271  foreach($parent_field->getOptions() as $option)
272  {
273  if($option->getValue() == $parent_option)
274  {
275  $parent_field = $option;
276  break;
277  }
278  }
279  }
280  }
281 
282  if($parent_field)
283  {
284  return $parent_field;
285  }
286  }
287  }
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 149 of file class.ilADTFormBridge.php.

References $info.

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

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

◆ getParentElement()

ilADTFormBridge::getParentElement ( )

Get parent element.

Returns
string

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

Referenced by findParentElementInForm(), and shouldBeImportedFromPost().

174  {
175  return $this->parent;
176  }
+ 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 328 of file class.ilADTFormBridge.php.

References getADT().

329  {
330  return !$this->getADT()->isNull();
331  }
+ Here is the call graph for this function:

◆ isDisabled()

ilADTFormBridge::isDisabled ( )

Get disabled.

Returns
bool

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

References $disabled.

Referenced by addBasicFieldProperties(), and shouldBeImportedFromPost().

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

◆ isRequired()

◆ 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  {
58  throw new Exception('ADTFormBridge Type mismatch.');
59  }
60 
61  $this->adt = $a_adt;
62  }
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 183 of file class.ilADTFormBridge.php.

184  {
185  $this->disabled = (bool)$a_value;
186  }

◆ setElementId()

ilADTFormBridge::setElementId (   $a_value)

Set element id (aka form field)

Parameters
string$a_value

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

100  {
101  $this->id = (string)$a_value;
102  }

◆ setExternalErrors()

ilADTFormBridge::setExternalErrors (   $a_errors)

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

References getElementId(), and getForm().

403  {
404  $field = $this->getForm()->getItemByPostvar($this->getElementId());
405  $field->setAlert(implode("<br />", $a_errors));
406  }
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 79 of file class.ilADTFormBridge.php.

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

◆ setInfo()

ilADTFormBridge::setInfo (   $a_value)

Set info (aka form field info text)

Parameters
string$a_value

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

Referenced by ilADTTestGUI\prepareFormElements().

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

◆ setParentElement()

ilADTFormBridge::setParentElement (   $a_value)

Set parent element.

Parameters
string | array$a_value

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

160  {
161  if(!is_array($a_value))
162  {
163  $a_value = (string)$a_value;
164  }
165  $this->parent = $a_value;
166  }

◆ setRequired()

ilADTFormBridge::setRequired (   $a_value)

Set required.

Parameters
bool$a_value

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

204  {
205  $this->required = (bool)$a_value;
206  }

◆ setTitle()

ilADTFormBridge::setTitle (   $a_value)

Set title (aka form field caption)

Parameters
string$a_value

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

Referenced by ilADTTestGUI\prepareFormElements().

120  {
121  $this->title = trim($a_value);
122  }
+ 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 339 of file class.ilADTFormBridge.php.

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

340  {
341  if($this->isDisabled())
342  {
343  return false;
344  }
345 
346  // inactive parent elements disable importing
347  if($a_parent_adt)
348  {
349  $parent_option = null;
351  if(is_array($parent_element))
352  {
353  $parent_option = $parent_element[1];
354  }
355  return $a_parent_adt->isActiveForSubItems($parent_option);
356  }
357 
358  return true;
359  }
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 371 of file class.ilADTFormBridge.php.

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

372  {
373  global $lng;
374 
375  // ilADTFormBridge->isRequired() != ilADT->allowNull()
376  if($this->isRequired() && $this->getADT()->isNull())
377  {
378  $field = $this->getForm()->getItemByPostvar($this->getElementId());
379  $field->setAlert($lng->txt("msg_input_is_required"));
380  return false;
381  }
382  // no need to further validate if no value given
383  else if(!$this->getADT()->isValid())
384  {
385  $tmp = array();
386 
387  $mess = $this->getADT()->getValidationErrors();
388  foreach($mess as $error_code)
389  {
390  $tmp[] = $this->getADT()->translateErrorCode($error_code);
391  }
392 
393  $field = $this->getForm()->getItemByPostvar($this->getElementId());
394  $field->setAlert(implode("<br />", $tmp));
395 
396  return false;
397  }
398 
399  return true;
400  }
isRequired()
Get required.
getElementId()
Get element id.
global $lng
Definition: privfeed.php:40
+ 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

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

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


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