ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADTTextFormBridge.php
Go to the documentation of this file.
1<?php
2
20{
21 protected $multi; // [bool]
22 protected $multi_rows; // [int]
23 protected $multi_cols; // [int]
24
28 private $language = null;
29
30 public function __construct(ilADT $a_adt)
31 {
32 global $DIC;
33
34 parent::__construct($a_adt);
35 $this->language = $DIC->language();
36 $this->language->loadLanguageModule('meta');
37 }
38
39
40 //
41 // properties
42 //
43
51 public function setMulti($a_value, $a_cols = null, $a_rows = null)
52 {
53 $this->multi = (bool) $a_value;
54 $this->multi_rows = ($a_rows === null) ? null : (int) $a_rows;
55 $this->multi_cols = ($a_cols === null) ? null : (int) $a_cols;
56 }
57
63 public function isMulti()
64 {
65 return $this->multi;
66 }
67
68
69 //
70 // form
71 //
72
73 protected function isValidADT(ilADT $a_adt)
74 {
75 return ($a_adt instanceof ilADTText);
76 }
77
85 protected function addElementToForm(string $title, string $element_id, string $value, bool $is_translation = false, string $language = '')
86 {
87 $def = $this->getADT()->getCopyOfDefinition();
88
89 if (!$this->isMulti()) {
90 $text = new ilTextInputGUI($title, $element_id);
91
92 if ($def->getMaxLength()) {
93 $max = $def->getMaxLength();
94 $size = $text->getSize();
95
96 $text->setMaxLength($max);
97
98 if ($size && $max < $size) {
99 $text->setSize($max);
100 }
101 }
102 } else {
103 $text = new ilTextAreaInputGUI($title, $element_id);
104 if ($this->multi_rows) {
105 $text->setRows($this->multi_rows);
106 }
107 if ($this->multi_cols) {
108 $text->setCols($this->multi_cols);
109 }
110
111 if ($def->getMaxLength()) {
112 $max = $def->getMaxLength();
113 $text->setMaxNumOfChars($max);
114 }
115 }
116 $this->addBasicFieldProperties($text, $def);
117
118 if ($is_translation) {
119 $text->setInfo($this->language->txt('md_adv_int_translation_info') . ' ' . $this->language->txt('meta_l_' . $language));
120 $text->setRequired(false);
121 }
122 $text->setValue($value);
123 $this->addToParentElement($text);
124 }
125
126 public function addToForm()
127 {
128 $this->addElementToForm(
129 (string) $this->getTitle(),
130 (string) $this->getElementId(),
131 (string) $this->getADT()->getText()
132 );
133 }
134
135 public function importFromPost()
136 {
137 // ilPropertyFormGUI::checkInput() is pre-requisite
138 $this->getADT()->setText($this->getForm()->getInput($this->getElementId()));
139 $field = $this->getForm()->getItemByPostvar($this->getElementId());
140 $field->setValue($this->getADT()->getText());
141 }
142}
$size
Definition: RandomTest.php:84
An exception for terminatinating execution or to throw for unit testing.
ADT form bridge base class.
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
getElementId()
Get element id.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilADT $a_adt)
Constructor.
addToForm()
Add ADT-specific fields to form.
setMulti($a_value, $a_cols=null, $a_rows=null)
Set multi-line.
addElementToForm(string $title, string $element_id, string $value, bool $is_translation=false, string $language='')
importFromPost()
Import values from form request POST data.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
ADT base class.
Definition: class.ilADT.php:12
This class represents a text area property in a property form.
This class represents a text property in a property form.
global $DIC
Definition: goto.php:24
language()
Definition: language.php:2
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc