ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
16  protected $max_length; // [int]
17  protected $multi; // [bool]
18 
19 
20  //
21  // generic types
22  //
23 
24  public function getType()
25  {
26  return self::TYPE_TEXT;
27  }
28 
29 
30  //
31  // ADT
32  //
33 
34  protected function initADTDefinition()
35  {
36  $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Text");
37 
38  $max = $this->getMaxLength();
39  if(is_numeric($max))
40  {
41  $def->setMaxLength($max);
42  }
43 
44  // multi-line is presentation property
45 
46  return $def;
47  }
48 
49 
50  //
51  // properties
52  //
53 
59  public function setMaxLength($a_value)
60  {
61  if($a_value !== null)
62  {
63  $a_value = (int)$a_value;
64  }
65  $this->max_length = $a_value;
66  }
67 
73  public function getMaxLength()
74  {
75  return $this->max_length;
76  }
77 
83  public function setMulti($a_value)
84  {
85  $this->multi = (bool)$a_value;
86  }
87 
93  public function isMulti()
94  {
95  return $this->multi;
96  }
97 
98 
99  //
100  // definition (NOT ADT-based)
101  //
102 
103  protected function importFieldDefinition(array $a_def)
104  {
105  $this->setMaxLength($a_def["max"]);
106  $this->setMulti($a_def["multi"]);
107  }
108 
109  protected function getFieldDefinition()
110  {
111  return array(
112  "max" => $this->getMaxLength(),
113  "multi" => $this->isMulti()
114  );
115  }
116 
118  {
119  global $lng;
120 
121  $res = array();
122 
123  if($this->getMaxLength() !== null)
124  {
125  $res[$lng->txt("md_adv_text_max_length")] = $this->getMaxLength();
126  }
127  if($this->isMulti())
128  {
129  $res[$lng->txt("md_adv_text_multi")] = $lng->txt("yes");
130  }
131 
132  return $res;
133  }
134 
141  public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
142  {
143  global $lng;
144 
145  $max = new ilNumberInputGUI($lng->txt("md_adv_text_max_length"), "max");
146  $max->setValue($this->getMaxLength());
147  $max->setSize(10);
148  $max->setMinValue(1);
149  $max->setMaxValue(4000); // DB limit
150  $a_form->addItem($max);
151 
152  $multi = new ilCheckboxInputGUI($lng->txt("md_adv_text_multi"), "multi");
153  $multi->setValue(1);
154  $multi->setChecked($this->isMulti());
155  $a_form->addItem($multi);
156 
157  if($a_disabled)
158  {
159  $max->setDisabled(true);
160  $multi->setDisabled(true);
161  }
162  }
163 
170  {
171  $max = $a_form->getInput("max");
172  $this->setMaxLength(($max !== "") ? $max : null);
173 
174  $this->setMulti($a_form->getInput("multi"));
175  }
176 
177  //
178  // import/export
179  //
180 
181  protected function addPropertiesToXML(ilXmlWriter $a_writer)
182  {
183  $a_writer->xmlElement('FieldValue',array("id"=>"max"),$this->getMaxLength());
184  $a_writer->xmlElement('FieldValue',array("id"=>"multi"),$this->isMulti());
185  }
186 
187  public function importXMLProperty($a_key, $a_value)
188  {
189  if($a_key == "max")
190  {
191  $this->setMaxLength($a_value != "" ? $a_value : null);
192  }
193  if($a_key == "multi")
194  {
195  $this->setMulti($a_value != "" ? $a_value : null);
196  }
197  }
198 
199  public function getValueForXML(ilADT $element)
200  {
201  return $element->getText();
202  }
203 
204  public function importValueFromXML($a_cdata)
205  {
206  $this->getADT()->setText($a_cdata);
207  }
208 
209  public function importFromECS($a_ecs_type, $a_value, $a_sub_id)
210  {
211  switch($a_ecs_type)
212  {
214  $value = implode(',', (array)$a_value);
215  break;
216 
218  $value = (int)$a_value;
219  break;
220 
222  $value = (string)$a_value;
223  break;
224 
226  if($a_value instanceof ilECSTimePlace)
227  {
228  $value = $a_value->{'get'.ucfirst($a_sub_id)}();
229  }
230  break;
231  }
232 
233  if(trim($value))
234  {
235  $this->getADT()->setText($value);
236  return true;
237  }
238  return false;
239  }
240 
241  //
242  // presentation
243  //
244 
245  public function prepareElementForEditor(ilADTFormBridge $a_text)
246  {
247  assert($a_text instanceof ilADTTextFormBridge);
248 
249  // seems to be default in course info editor
250  $a_text->setMulti($this->isMulti(), 80, 6);
251  }
252 
253 
254  //
255  // search
256  //
257 
258  public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
259  {
260  return $a_adt_search->getADT()->getText();
261  }
262 
263  protected function parseSearchObjects(array $a_records, array $a_object_types)
264  {
265  global $ilDB;
266 
267  $res = array();
268 
269  $obj_ids = array();
270  foreach($a_records as $record)
271  {
272  if($record["sub_type"] == "-")
273  {
274  // keep found information
275  $obj_ids[$record["obj_id"]] = $record;
276  }
277  }
278 
279  $sql = "SELECT obj_id,type".
280  " FROM object_data".
281  " WHERE ".$ilDB->in("obj_id", array_keys($obj_ids), "", "integer").
282  " AND ".$ilDB->in("type", $a_object_types, "", "text");
283  $set = $ilDB->query($sql);
284  while($row = $ilDB->fetchAssoc($set))
285  {
286  $row["found"] = array();
287  foreach($obj_ids[$row["obj_id"]] as $field => $value)
288  {
289  if(substr($field, 0, 5) == "found")
290  {
291  $row["found"][$field] = $value;
292  }
293  }
294  $res[] = $row;
295  }
296 
297  return $res;
298  }
299 
310  public function searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
311  {
312  // :TODO: search type (like, fulltext)
313 
314  include_once('Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
315  $condition = $a_adt_search->getSQLCondition(
318  $a_parser->getQuotedWords());
319  if($condition)
320  {
321  $objects = ilADTActiveRecordByType::find("adv_md_values", $this->getADT()->getType(), $this->getFieldId(), $condition, $a_locate);
322  if(sizeof($objects))
323  {
324  return $this->parseSearchObjects($objects, $a_object_types);
325  }
326  return array();
327  }
328  }
329 }
330 
331 ?>
setValue($a_value)
Set Value.
Representation of ECS EContent Time Place.
This class represents a property form user interface.
getQuotedWords($with_quotation=false)
ADT form bridge base class.
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.
searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
Search.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
This class represents a checkbox property in a property form.
Add rich text string
The name of the decorator.
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.
This class represents a number property in a property form.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Create styles array
The data for the language used.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false)
Add input elements to definition form.
ADT search bridge base class.
parseSearchObjects(array $a_records, array $a_object_types)
global $lng
Definition: privfeed.php:17
global $ilDB
getSQLCondition($a_element_id)
Get SQL condition for current value(s)