ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAdvancedMDFieldDefinitionText.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php";
5 
15 {
18 
22  protected $max_length;
26  protected $multi;
27 
28 
29  //
30  // generic types
31  //
32 
33  public function getType()
34  {
35  return self::TYPE_TEXT;
36  }
37 
38 
39  public function getADTGroup()
40  {
41  return $this->getADTDefinition();
42  }
43 
44  public function getTitles()
45  {
46  return [];
47  }
48 
49  public function hasComplexOptions()
50  {
51  return false;
52  }
53 
58  protected function initADTDefinition()
59  {
61 
62  $definition = ilADTFactory::getInstance()->getDefinitionInstanceByType(ilADTFactory::TYPE_LOCALIZED_TEXT);
63  $definition->setMaxLength((int) $this->getMaxLength());
64  $definition->setActiveLanguages($field_translations->getActivatedLanguages($this->getFieldId(), true));
65  $definition->setDefaultLanguage($field_translations->getDefaultLanguage());
66  return $definition;
67  }
68 
69 
70  //
71  // properties
72  //
73 
79  public function setMaxLength($a_value)
80  {
81  if ($a_value !== null) {
82  $a_value = (int) $a_value;
83  }
84  $this->max_length = $a_value;
85  }
86 
92  public function getMaxLength()
93  {
94  return $this->max_length;
95  }
96 
102  public function setMulti($a_value)
103  {
104  $this->multi = (bool) $a_value;
105  }
106 
112  public function isMulti()
113  {
114  return $this->multi;
115  }
116 
117 
118  //
119  // definition (NOT ADT-based)
120  //
121 
122  protected function importFieldDefinition(array $a_def)
123  {
124  $this->setMaxLength($a_def["max"]);
125  $this->setMulti($a_def["multi"]);
126  }
127 
128  protected function getFieldDefinition()
129  {
130  return array(
131  "max" => $this->getMaxLength(),
132  "multi" => $this->isMulti()
133  );
134  }
135 
136  public function getFieldDefinitionForTableGUI(string $content_language)
137  {
138  global $DIC;
139 
140  $lng = $DIC['lng'];
141 
142  $res = array();
143 
144  if ($this->getMaxLength() !== null) {
145  $res[$lng->txt("md_adv_text_max_length")] = $this->getMaxLength();
146  }
147  if ($this->isMulti()) {
148  $res[$lng->txt("md_adv_text_multi")] = $lng->txt("yes");
149  }
150 
151  return $res;
152  }
153 
160  public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false, string $language = '')
161  {
162  global $DIC;
163 
164  $lng = $DIC['lng'];
165 
166  $max = new ilNumberInputGUI($lng->txt("md_adv_text_max_length"), "max");
167  $max->setValue($this->getMaxLength());
168  $max->setSize(10);
169  $max->setSuffix($lng->txt("characters"));
170  $max->setMinValue(1);
171  $max->setMaxValue(4000); // DB limit
172  $a_form->addItem($max);
173 
174  $multi = new ilCheckboxInputGUI($lng->txt("md_adv_text_multi"), "multi");
175  $multi->setValue(1);
176  $multi->setChecked($this->isMulti());
177  $a_form->addItem($multi);
178 
179  if ($a_disabled) {
180  $max->setDisabled(true);
181  $multi->setDisabled(true);
182  }
183  }
184 
191  {
192  $max = $a_form->getInput("max");
193  $this->setMaxLength(($max !== "") ? $max : null);
194 
195  $this->setMulti($a_form->getInput("multi"));
196  }
197 
198  //
199  // import/export
200  //
201 
202  protected function addPropertiesToXML(ilXmlWriter $a_writer)
203  {
204  $a_writer->xmlElement('FieldValue', array("id" => "max"), $this->getMaxLength());
205  $a_writer->xmlElement('FieldValue', array("id" => "multi"), $this->isMulti());
206  }
207 
208  public function importXMLProperty($a_key, $a_value)
209  {
210  if ($a_key == "max") {
211  $this->setMaxLength($a_value != "" ? $a_value : null);
212  }
213  if ($a_key == "multi") {
214  $this->setMulti($a_value != "" ? $a_value : null);
215  }
216  }
217 
218  public function getValueForXML(ilADT $element)
219  {
223  $translations = $element->getTranslations();
224  $serialized_values = [];
225  foreach ($translations as $lang_key => $translation) {
226  $serialized_values[] = $lang_key . self::XML_SEPARATOR_TRANSLATION . $translation;
227  }
228  return implode(self::XML_SEPARATOR_TRANSLATIONS, $serialized_values);
229  }
230 
234  public function importValueFromXML($a_cdata)
235  {
236  // an import from release < 7
237  if (strpos($a_cdata, self::XML_SEPARATOR_TRANSLATION) === false) {
238  $this->getADT()->setText($a_cdata);
239  return;
240  }
241 
242  $translations = explode(self::XML_SEPARATOR_TRANSLATIONS, $a_cdata);
243  foreach ($translations as $translation) {
244  $parts = explode(self::XML_SEPARATOR_TRANSLATION, $translation);
245  if ($parts === false) {
246  continue;
247  }
248  $this->getADT()->setTranslation((string) $parts[0], (string) $parts[1]);
249  }
250  }
251 
252  public function importFromECS($a_ecs_type, $a_value, $a_sub_id)
253  {
254  switch ($a_ecs_type) {
256  $value = implode(',', (array) $a_value);
257  break;
258 
260  $value = (int) $a_value;
261  break;
262 
264  $value = (string) $a_value;
265  break;
266 
268  if ($a_value instanceof ilECSTimePlace) {
269  $value = $a_value->{'get' . ucfirst($a_sub_id)}();
270  }
271  break;
272  }
273 
274  if (trim($value)) {
275  $this->getADT()->setText($value);
276  return true;
277  }
278  return false;
279  }
280 
282  {
283  if (!$form instanceof ilADTLocalizedTextFormBridge) {
284  $this->logger->warning('Passed ' . get_class($form));
285  return;
286  }
287  $form->setMulti($this->isMulti());
288  }
289 
290 
291  public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
292  {
293  return $a_adt_search->getADT()->getText();
294  }
295 
296  protected function parseSearchObjects(array $a_records, array $a_object_types)
297  {
298  global $DIC;
299 
300  $ilDB = $DIC['ilDB'];
301 
302  $res = array();
303 
304  $obj_ids = array();
305  foreach ($a_records as $record) {
306  if ($record["sub_type"] == "-") {
307  // keep found information
308  $obj_ids[$record["obj_id"]] = $record;
309  }
310  }
311 
312  $sql = "SELECT obj_id,type" .
313  " FROM object_data" .
314  " WHERE " . $ilDB->in("obj_id", array_keys($obj_ids), "", "integer") .
315  " AND " . $ilDB->in("type", $a_object_types, "", "text");
316  $set = $ilDB->query($sql);
317  while ($row = $ilDB->fetchAssoc($set)) {
318  $row["found"] = array();
319  foreach ($obj_ids[$row["obj_id"]] as $field => $value) {
320  if (substr($field, 0, 5) == "found") {
321  $row["found"][$field] = $value;
322  }
323  }
324  $res[] = $row;
325  }
326 
327  return $res;
328  }
329 
340  public function searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
341  {
342  // :TODO: search type (like, fulltext)
343 
344  include_once('Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
345  $condition = $a_adt_search->getSQLCondition(
348  $a_parser->getQuotedWords()
349  );
350  if ($condition) {
352  'adv_md_values',
353  $this->getADT()->getType(),
354  $this->getFieldId(),
355  $condition,
356  $a_locate);
357  if (isset($objects) && count($objects)) {
358  return $this->parseSearchObjects($objects, $a_object_types);
359  }
360  return [];
361  }
362  }
363 }
setValue($a_value)
Set Value.
Representation of ECS EContent Time Place.
This class represents a property form user interface.
getQuotedWords($with_quotation=false)
getADTDefinition()
Get ADT definition instance.
ADT form bridge base class.
searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
Search.
XML writer class.
This class represents a checkbox property in a property form.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false, string $language='')
Add input elements to definition form.
addItem($a_item)
Add Item (Property, SectionHeader).
static getInstance()
Get singleton.
ADT base class.
Definition: class.ilADT.php:11
const TYPE_TIMEPLACE
static find($a_table, $a_type, $a_field_id, $a_condition, $a_additional_fields=null)
Find entries.
Class ilADTLocalizedTextDBBridge.
foreach($_POST as $key=> $value) $res
$lng
This class represents a number property in a property form.
global $DIC
Definition: goto.php:24
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
ADT search bridge base class.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
parseSearchObjects(array $a_records, array $a_object_types)
global $ilDB
getSQLCondition($a_element_id)
Get SQL condition for current value(s)