ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 {
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  $def->setMaxLength($max);
41  }
42 
43  // multi-line is presentation property
44 
45  return $def;
46  }
47 
48 
49  //
50  // properties
51  //
52 
58  public function setMaxLength($a_value)
59  {
60  if ($a_value !== null) {
61  $a_value = (int) $a_value;
62  }
63  $this->max_length = $a_value;
64  }
65 
71  public function getMaxLength()
72  {
73  return $this->max_length;
74  }
75 
81  public function setMulti($a_value)
82  {
83  $this->multi = (bool) $a_value;
84  }
85 
91  public function isMulti()
92  {
93  return $this->multi;
94  }
95 
96 
97  //
98  // definition (NOT ADT-based)
99  //
100 
101  protected function importFieldDefinition(array $a_def)
102  {
103  $this->setMaxLength($a_def["max"]);
104  $this->setMulti($a_def["multi"]);
105  }
106 
107  protected function getFieldDefinition()
108  {
109  return array(
110  "max" => $this->getMaxLength(),
111  "multi" => $this->isMulti()
112  );
113  }
114 
116  {
117  global $DIC;
118 
119  $lng = $DIC['lng'];
120 
121  $res = array();
122 
123  if ($this->getMaxLength() !== null) {
124  $res[$lng->txt("md_adv_text_max_length")] = $this->getMaxLength();
125  }
126  if ($this->isMulti()) {
127  $res[$lng->txt("md_adv_text_multi")] = $lng->txt("yes");
128  }
129 
130  return $res;
131  }
132 
139  public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
140  {
141  global $DIC;
142 
143  $lng = $DIC['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->setSuffix($lng->txt("characters"));
149  $max->setMinValue(1);
150  $max->setMaxValue(4000); // DB limit
151  $a_form->addItem($max);
152 
153  $multi = new ilCheckboxInputGUI($lng->txt("md_adv_text_multi"), "multi");
154  $multi->setValue(1);
155  $multi->setChecked($this->isMulti());
156  $a_form->addItem($multi);
157 
158  if ($a_disabled) {
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  $this->setMaxLength($a_value != "" ? $a_value : null);
191  }
192  if ($a_key == "multi") {
193  $this->setMulti($a_value != "" ? $a_value : null);
194  }
195  }
196 
197  public function getValueForXML(ilADT $element)
198  {
199  return $element->getText();
200  }
201 
202  public function importValueFromXML($a_cdata)
203  {
204  $this->getADT()->setText($a_cdata);
205  }
206 
207  public function importFromECS($a_ecs_type, $a_value, $a_sub_id)
208  {
209  switch ($a_ecs_type) {
211  $value = implode(',', (array) $a_value);
212  break;
213 
215  $value = (int) $a_value;
216  break;
217 
219  $value = (string) $a_value;
220  break;
221 
223  if ($a_value instanceof ilECSTimePlace) {
224  $value = $a_value->{'get' . ucfirst($a_sub_id)}();
225  }
226  break;
227  }
228 
229  if (trim($value)) {
230  $this->getADT()->setText($value);
231  return true;
232  }
233  return false;
234  }
235 
236  //
237  // presentation
238  //
239 
240  public function prepareElementForEditor(ilADTFormBridge $a_text)
241  {
242  assert($a_text instanceof ilADTTextFormBridge);
243 
244  // seems to be default in course info editor
245  $a_text->setMulti($this->isMulti(), 80, 6);
246  }
247 
248 
249  //
250  // search
251  //
252 
253  public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
254  {
255  return $a_adt_search->getADT()->getText();
256  }
257 
258  protected function parseSearchObjects(array $a_records, array $a_object_types)
259  {
260  global $DIC;
261 
262  $ilDB = $DIC['ilDB'];
263 
264  $res = array();
265 
266  $obj_ids = array();
267  foreach ($a_records as $record) {
268  if ($record["sub_type"] == "-") {
269  // keep found information
270  $obj_ids[$record["obj_id"]] = $record;
271  }
272  }
273 
274  $sql = "SELECT obj_id,type" .
275  " FROM object_data" .
276  " WHERE " . $ilDB->in("obj_id", array_keys($obj_ids), "", "integer") .
277  " AND " . $ilDB->in("type", $a_object_types, "", "text");
278  $set = $ilDB->query($sql);
279  while ($row = $ilDB->fetchAssoc($set)) {
280  $row["found"] = array();
281  foreach ($obj_ids[$row["obj_id"]] as $field => $value) {
282  if (substr($field, 0, 5) == "found") {
283  $row["found"][$field] = $value;
284  }
285  }
286  $res[] = $row;
287  }
288 
289  return $res;
290  }
291 
302  public function searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
303  {
304  // :TODO: search type (like, fulltext)
305 
306  include_once('Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
307  $condition = $a_adt_search->getSQLCondition(
310  $a_parser->getQuotedWords()
311  );
312  if ($condition) {
313  $objects = ilADTActiveRecordByType::find("adv_md_values", $this->getADT()->getType(), $this->getFieldId(), $condition, $a_locate);
314  if (sizeof($objects)) {
315  return $this->parseSearchObjects($objects, $a_object_types);
316  }
317  return array();
318  }
319  }
320 }
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.
This class represents a checkbox property in a property 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.
foreach($_POST as $key=> $value) $res
$lng
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)
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false)
Add input elements to 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
$DIC
Definition: xapitoken.php:46
getSQLCondition($a_element_id)
Get SQL condition for current value(s)