ILIAS  release_8 Revision v8.24
class.ilAdvancedMDFieldDefinitionText.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 public const XML_SEPARATOR_TRANSLATIONS = "~|~";
29 public const XML_SEPARATOR_TRANSLATION = '~+~';
30 public const KEY_MULTI = "multi";
31
32 protected ?int $max_length = null;
33 protected bool $multi = false;
34
35 //
36 // generic types
37 //
38
39 public function getType(): int
40 {
41 return self::TYPE_TEXT;
42 }
43
44 public function getADTGroup(): ilADTDefinition
45 {
46 return $this->getADTDefinition();
47 }
48
49 public function getTitles(): array
50 {
51 return [];
52 }
53
54 public function hasComplexOptions(): bool
55 {
56 return false;
57 }
58
63 protected function initADTDefinition(): ilADTDefinition
64 {
66
67 $definition = ilADTFactory::getInstance()->getDefinitionInstanceByType(ilADTFactory::TYPE_LOCALIZED_TEXT);
68 $definition->setMaxLength($this->getMaxLength());
69 $definition->setActiveLanguages($field_translations->getActivatedLanguages($this->getFieldId(), true));
70 $definition->setDefaultLanguage($field_translations->getDefaultLanguage());
71 return $definition;
72 }
73
74
75 //
76 // properties
77 //
78
79 public function setMaxLength(?int $max_length)
80 {
81 $this->max_length = $max_length;
82 }
83
84 public function getMaxLength(): ?int
85 {
86 return $this->max_length;
87 }
88
89 public function setMulti(bool $a_value): void
90 {
91 $this->multi = $a_value;
92 }
93
94 public function isMulti(): bool
95 {
96 return $this->multi;
97 }
98
99
100 //
101 // definition (NOT ADT-based)
102 //
103
104 protected function importFieldDefinition(array $a_def): void
105 {
106 $this->setMaxLength(isset($a_def["max"]) ? (int) $a_def["max"] : null);
107 $this->setMulti((bool) ($a_def[self::KEY_MULTI] ?? false));
108 }
109
110 protected function getFieldDefinition(): array
111 {
112 return array(
113 "max" => $this->getMaxLength(),
114 self::KEY_MULTI => $this->isMulti()
115 );
116 }
117
118 public function getFieldDefinitionForTableGUI(string $content_language): array
119 {
120 global $DIC;
121
122 $lng = $DIC['lng'];
123
124 $res = array();
125
126 if ($this->getMaxLength() !== null) {
127 $res[$lng->txt("md_adv_text_max_length")] = $this->getMaxLength();
128 }
129 if ($this->isMulti()) {
130 $res[$lng->txt("md_adv_text_multi")] = $lng->txt("yes");
131 }
132
133 return $res;
134 }
135
143 ilPropertyFormGUI $a_form,
144 bool $a_disabled = false,
145 string $language = ''
146 ): void {
147 global $DIC;
148
149 $lng = $DIC['lng'];
150
151 $max = new ilNumberInputGUI($lng->txt("md_adv_text_max_length"), "max");
152 $max->setValue((string) $this->getMaxLength());
153 $max->setSize(10);
154 $max->setSuffix($lng->txt("characters"));
155 $max->setMinValue(1);
156 $max->setMaxValue(4000); // DB limit
157 $a_form->addItem($max);
158
159 $multi = new ilCheckboxInputGUI($lng->txt("md_adv_text_multi"), self::KEY_MULTI);
160 $multi->setValue("1");
161 $multi->setChecked($this->isMulti());
162 $a_form->addItem($multi);
163
164 if ($a_disabled) {
165 $max->setDisabled(true);
166 $multi->setDisabled(true);
167 }
168 }
169
175 public function importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language = ''): void
176 {
177 $max = $a_form->getInput("max");
178 $this->setMaxLength(($max !== "" && $max !== null) ? (int) $max : null);
179 $this->setMulti((bool) $a_form->getInput(self::KEY_MULTI));
180 }
181
182 //
183 // import/export
184 //
185
186 protected function addPropertiesToXML(ilXmlWriter $a_writer): void
187 {
188 $a_writer->xmlElement('FieldValue', array("id" => "max"), $this->getMaxLength());
189 $a_writer->xmlElement('FieldValue', array("id" => self::KEY_MULTI), $this->isMulti());
190 }
191
192 public function importXMLProperty(string $a_key, string $a_value): void
193 {
194 if ($a_key === "max") {
195 $this->setMaxLength($a_value !== "" ? (int) $a_value : null);
196 }
197 if ($a_key === self::KEY_MULTI) {
198 $this->setMulti((bool) $a_value);
199 }
200 }
201
202 public function getValueForXML(ilADT $element): string
203 {
207 $translations = $element->getTranslations();
208 $serialized_values = [];
209 foreach ($translations as $lang_key => $translation) {
210 $serialized_values[] = $lang_key . self::XML_SEPARATOR_TRANSLATION . $translation;
211 }
212 return implode(self::XML_SEPARATOR_TRANSLATIONS, $serialized_values);
213 }
214
218 public function importValueFromXML(string $a_cdata): void
219 {
220 // an import from release < 7
221 if (strpos($a_cdata, self::XML_SEPARATOR_TRANSLATION) === false) {
222 $this->getADT()->setText($a_cdata);
223 $record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
224 $this->getADT()->setTranslation($record->getDefaultLanguage(), $a_cdata);
225 return;
226 }
227
228 $translations = explode(self::XML_SEPARATOR_TRANSLATIONS, $a_cdata);
229 foreach ($translations as $translation) {
230 $parts = explode(self::XML_SEPARATOR_TRANSLATION, $translation);
231 if ($parts === false) {
232 continue;
233 }
234 $this->getADT()->setTranslation($parts[0], $parts[1]);
235 }
236 }
237
238 public function importFromECS(string $a_ecs_type, $a_value, string $a_sub_id): bool
239 {
240 $value = '';
241 switch ($a_ecs_type) {
243 $value = implode(',', (array) $a_value);
244 break;
245
247 $value = (int) $a_value;
248 break;
249
251 $value = (string) $a_value;
252 break;
253
255 if ($a_value instanceof ilECSTimePlace) {
256 $value = $a_value->{'get' . ucfirst($a_sub_id)}();
257 }
258 break;
259 }
260
261 if (trim((string) $value)) {
262 $this->getADT()->setText(is_null($value) ? null : (string) $value);
263 return true;
264 }
265 return false;
266 }
267
268 public function prepareElementForEditor(ilADTFormBridge $a_bridge): void
269 {
270 if (!$a_bridge instanceof ilADTLocalizedTextFormBridge) {
271 $this->logger->warning('Passed ' . get_class($a_bridge));
272 return;
273 }
274 $a_bridge->setMulti($this->isMulti());
275 }
276
277 public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search): string
278 {
279 return (string) $a_adt_search->getADT()->getText();
280 }
281
282 protected function parseSearchObjects(array $a_records, array $a_object_types): array
283 {
284 global $DIC;
285
286 $ilDB = $DIC->database();
287
288 $res = array();
289
290 $obj_ids = array();
291 foreach ($a_records as $record) {
292 if ($record["sub_type"] == "-") {
293 // keep found information
294 $obj_ids[$record["obj_id"]] = $record;
295 }
296 }
297
298 $sql = "SELECT obj_id,type" .
299 " FROM object_data" .
300 " WHERE " . $ilDB->in("obj_id", array_keys($obj_ids), false, "integer") .
301 " AND " . $ilDB->in("type", $a_object_types, false, "text");
302 $set = $ilDB->query($sql);
303 while ($row = $ilDB->fetchAssoc($set)) {
304 $row["found"] = array();
305 foreach ($obj_ids[(int) $row["obj_id"]] as $field => $value) {
306 if (substr($field, 0, 5) == "found") {
307 $row["found"][$field] = $value;
308 }
309 }
310 $res[] = $row;
311 }
312
313 return $res;
314 }
315
316 public function searchObjects(
317 ilADTSearchBridge $a_adt_search,
318 ilQueryParser $a_parser,
319 array $a_object_types,
320 string $a_locate,
321 string $a_search_type
322 ): array {
323 // :TODO: search type (like, fulltext)
324
325 $condition = $a_adt_search->getSQLCondition(
326 ilADTActiveRecordByType::SINGLE_COLUMN_NAME,
328 $a_parser->getQuotedWords()
329 );
330 if ($condition) {
332 'adv_md_values',
333 $this->getADT()->getType(),
334 $this->getFieldId(),
335 $condition,
336 $a_locate
337 );
338 if (isset($objects) && count($objects)) {
339 return $this->parseSearchObjects($objects, $a_object_types);
340 }
341 return [];
342 }
343 return [];
344 }
345}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static find(string $a_table, string $a_type, int $a_field_id, string $a_condition, ?string $a_additional_fields=null)
Find entries.
ADT definition base class.
ADT form bridge base class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ADT base class.
Definition: class.ilADT.php:12
searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, string $a_locate, string $a_search_type)
Search objects.
parseSearchObjects(array $a_records, array $a_object_types)
Add object-data needed for global search to AMD search results.
importXMLProperty(string $a_key, string $a_value)
Import property from XML.
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, bool $a_disabled=false, string $language='')
Add input elements to definition form.
importFromECS(string $a_ecs_type, $a_value, string $a_sub_id)
Import meta data from ECS.
getFieldDefinition()
Get (type-specific) field definition.
prepareElementForEditor(ilADTFormBridge $a_bridge)
Prepare editor form elements.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Get value for search query parser.
getADTDefinition()
Get ADT definition instance.
static _getInstanceByRecordId(int $a_record_id)
This class represents a checkbox property in a property form.
Representation of ECS EContent Time Place.
const TYPE_TIMEPLACE
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This class represents a number property in a property form.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64