ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 protected bool $multilingual_value_support = true;
35
36
37 //
38 // generic types
39 //
40
41 public function getType(): int
42 {
43 return self::TYPE_TEXT;
44 }
45
46 public function getADTGroup(): ilADTDefinition
47 {
48 return $this->getADTDefinition();
49 }
50
51 public function getTitles(): array
52 {
53 return [];
54 }
55
56 public function hasComplexOptions(): bool
57 {
58 return false;
59 }
60
65 protected function initADTDefinition(): ilADTDefinition
66 {
68
69 $definition = ilADTFactory::getInstance()->getDefinitionInstanceByType(ilADTFactory::TYPE_LOCALIZED_TEXT);
70 $definition->setMaxLength($this->getMaxLength());
71 $definition->setActiveLanguages($field_translations->getActivatedLanguages($this->getFieldId(), true));
72 $definition->setDefaultLanguage($field_translations->getDefaultLanguage());
73 $definition->setMultilingualValueSupport($this->isMultilingualValueSupport());
74 return $definition;
75 }
76
77
78 public function isMultilingualValueSupport(): bool
79 {
81 }
82
84 {
85 $this->multilingual_value_support = $multilingual_value_support;
86 }
87
88 public function setMaxLength(?int $max_length)
89 {
90 $this->max_length = $max_length;
91 }
92
93 public function getMaxLength(): ?int
94 {
95 return $this->max_length;
96 }
97
98 public function setMulti(bool $a_value): void
99 {
100 $this->multi = $a_value;
101 }
102
103 public function isMulti(): bool
104 {
105 return $this->multi;
106 }
107
108
109 //
110 // definition (NOT ADT-based)
111 //
112
113 protected function importFieldDefinition(array $a_def): void
114 {
115 $this->setMaxLength(isset($a_def["max"]) ? (int) $a_def["max"] : null);
116 $this->setMulti((bool) ($a_def[self::KEY_MULTI] ?? false));
117 $multilingual_values = (bool) ($a_def['multilingual_values'] ?? true);
118 $this->setMultilingualValueSupport($multilingual_values);
119 }
120
121 protected function getFieldDefinition(): array
122 {
123 return [
124 "max" => $this->getMaxLength(),
125 self::KEY_MULTI => $this->isMulti(),
126 'multilingual_values' => $this->isMultilingualValueSupport()
127 ];
128 }
129
130 public function getFieldDefinitionForTableGUI(string $content_language): array
131 {
132 global $DIC;
133
134 $lng = $DIC['lng'];
135
136 $res = array();
137
138 if ($this->getMaxLength() !== null) {
139 $res[$lng->txt("md_adv_text_max_length")] = $this->getMaxLength();
140 }
141 if ($this->isMulti()) {
142 $res[$lng->txt("md_adv_text_multi")] = $lng->txt("yes");
143 }
144
145 return $res;
146 }
147
155 ilPropertyFormGUI $a_form,
156 bool $a_disabled = false,
157 string $language = ''
158 ): void {
159 global $DIC;
160
161 $lng = $DIC['lng'];
162 $lng->loadLanguageModule('meta');
163
164 $max = new ilNumberInputGUI($lng->txt("md_adv_text_max_length"), "max");
165 $max->setValue((string) $this->getMaxLength());
166 $max->setSize(10);
167 $max->setSuffix($lng->txt("characters"));
168 $max->setMinValue(1);
169 $max->setMaxValue(4000); // DB limit
170 $a_form->addItem($max);
171
172 $multi = new ilCheckboxInputGUI($lng->txt("md_adv_text_multi"), self::KEY_MULTI);
173 $multi->setValue("1");
174 $multi->setChecked($this->isMulti());
175 $a_form->addItem($multi);
176
177 if ($a_disabled) {
178 $max->setDisabled(true);
179 $multi->setDisabled(true);
180 }
182 if (!count($record_translations->getTranslations())) {
183 return;
184 }
185 $multilingual_values = new ilCheckboxInputGUI(
186 $lng->txt('md_adv_text_multi_val'),
187 'multilingual'
188 );
189 $multilingual_values->setInfo($lng->txt('md_adv_text_multi_val_info'));
190 $multilingual_values->setChecked($this->isMultilingualValueSupport());
191 $multilingual_values->setValue("1");
192 $a_form->addItem($multilingual_values);
193 }
194
200 public function importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language = ''): void
201 {
202 $max = $a_form->getInput("max");
203 $this->setMaxLength(($max !== "" && $max !== null) ? (int) $max : null);
204 $this->setMulti((bool) $a_form->getInput(self::KEY_MULTI));
205 $this->setMultilingualValueSupport((bool) $a_form->getInput('multilingual'));
206 }
207
208 //
209 // import/export
210 //
211
212 protected function addPropertiesToXML(ilXmlWriter $a_writer): void
213 {
214 $a_writer->xmlElement('FieldValue', array("id" => "max"), $this->getMaxLength());
215 $a_writer->xmlElement('FieldValue', array("id" => self::KEY_MULTI), $this->isMulti());
216 $a_writer->xmlElement('FieldValue', ['id' => 'multilingual_values'], $this->isMultilingualValueSupport());
217 }
218
219 public function importXMLProperty(string $a_key, string $a_value): void
220 {
221 if ($a_key === "max") {
222 $this->setMaxLength($a_value !== "" ? (int) $a_value : null);
223 }
224 if ($a_key === self::KEY_MULTI) {
225 $this->setMulti((bool) $a_value);
226 }
227 if ($a_key == 'multilingual_values') {
228 $this->setMultilingualValueSupport(
229 $a_value != '' ? true : false
230 );
231 }
232 }
233
234 public function getValueForXML(ilADT $element): string
235 {
239 $translations = $element->getTranslations();
240 $serialized_values = [];
241 foreach ($translations as $lang_key => $translation) {
242 $serialized_values[] = $lang_key . self::XML_SEPARATOR_TRANSLATION . $translation;
243 }
244 return implode(self::XML_SEPARATOR_TRANSLATIONS, $serialized_values);
245 }
246
250 public function importValueFromXML(string $a_cdata): void
251 {
252 // an import from release < 7
253 if (strpos($a_cdata, self::XML_SEPARATOR_TRANSLATION) === false) {
254 $this->getADT()->setText($a_cdata);
255 $record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
256 $this->getADT()->setTranslation($record->getDefaultLanguage(), $a_cdata);
257 return;
258 }
259
260 $translations = explode(self::XML_SEPARATOR_TRANSLATIONS, $a_cdata);
261 foreach ($translations as $translation) {
262 $parts = explode(self::XML_SEPARATOR_TRANSLATION, $translation);
263 if ($parts === false) {
264 continue;
265 }
266 $this->getADT()->setTranslation($parts[0], $parts[1]);
267 }
268 }
269
270 public function importFromECS(string $a_ecs_type, $a_value, string $a_sub_id): bool
271 {
272 $value = '';
273 switch ($a_ecs_type) {
275 $value = implode(',', (array) $a_value);
276 break;
277
279 $value = (int) $a_value;
280 break;
281
283 $value = (string) $a_value;
284 break;
285
287 if ($a_value instanceof ilECSTimePlace) {
288 $value = $a_value->{'get' . ucfirst($a_sub_id)}();
289 }
290 break;
291 }
292
293 if (trim((string) $value)) {
294 $this->getADT()->setText(is_null($value) ? null : (string) $value);
295 return true;
296 }
297 return false;
298 }
299
300 public function prepareElementForEditor(ilADTFormBridge $a_bridge): void
301 {
302 if (!$a_bridge instanceof ilADTLocalizedTextFormBridge) {
303 $this->logger->warning('Passed ' . get_class($a_bridge));
304 return;
305 }
306 $a_bridge->setMulti($this->isMulti());
307 }
308
309 public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search): string
310 {
311 return (string) $a_adt_search->getADT()->getText();
312 }
313
314 protected function parseSearchObjects(array $a_records, array $a_object_types): array
315 {
316 global $DIC;
317
318 $ilDB = $DIC->database();
319
320 $res = array();
321
322 $obj_ids = array();
323 foreach ($a_records as $record) {
324 if ($record["sub_type"] == "-") {
325 // keep found information
326 $obj_ids[$record["obj_id"]] = $record;
327 }
328 }
329
330 $sql = "SELECT obj_id,type" .
331 " FROM object_data" .
332 " WHERE " . $ilDB->in("obj_id", array_keys($obj_ids), false, "integer") .
333 " AND " . $ilDB->in("type", $a_object_types, false, "text");
334 $set = $ilDB->query($sql);
335 while ($row = $ilDB->fetchAssoc($set)) {
336 $row["found"] = array();
337 foreach ($obj_ids[(int) $row["obj_id"]] as $field => $value) {
338 if (substr($field, 0, 5) == "found") {
339 $row["found"][$field] = $value;
340 }
341 }
342 $res[] = $row;
343 }
344
345 return $res;
346 }
347
348 public function searchObjects(
349 ilADTSearchBridge $a_adt_search,
350 ilQueryParser $a_parser,
351 array $a_object_types,
352 string $a_locate,
353 string $a_search_type
354 ): array {
355 // :TODO: search type (like, fulltext)
356
357 $condition = $a_adt_search->getSQLCondition(
358 ilADTActiveRecordByType::SINGLE_COLUMN_NAME,
360 $a_parser->getQuotedWords()
361 );
362 if ($condition) {
364 'adv_md_values',
365 $this->getADT()->getType(),
366 $this->getFieldId(),
367 $condition,
368 $a_locate
369 );
370 if (isset($objects) && count($objects)) {
371 return $this->parseSearchObjects($objects, $a_object_types);
372 }
373 return [];
374 }
375 return [];
376 }
377}
ADT Active Record by type helper class This class expects a valid primary for all actions!
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.
ADT search bridge base class.
ADT base class.
Definition: class.ilADT.php:26
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.
setMultilingualValueSupport(bool $multilingual_value_support)
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
loadLanguageModule(string $a_module)
Load language module.
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)
$res
Definition: ltiservices.php:69
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
global $DIC
Definition: shib_login.php:26