ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_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 $lng;
118
119 $res = array();
120
121 if ($this->getMaxLength() !== null) {
122 $res[$lng->txt("md_adv_text_max_length")] = $this->getMaxLength();
123 }
124 if ($this->isMulti()) {
125 $res[$lng->txt("md_adv_text_multi")] = $lng->txt("yes");
126 }
127
128 return $res;
129 }
130
137 public function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false)
138 {
139 global $lng;
140
141 $max = new ilNumberInputGUI($lng->txt("md_adv_text_max_length"), "max");
142 $max->setValue($this->getMaxLength());
143 $max->setSize(10);
144 $max->setMinValue(1);
145 $max->setMaxValue(4000); // DB limit
146 $a_form->addItem($max);
147
148 $multi = new ilCheckboxInputGUI($lng->txt("md_adv_text_multi"), "multi");
149 $multi->setValue(1);
150 $multi->setChecked($this->isMulti());
151 $a_form->addItem($multi);
152
153 if ($a_disabled) {
154 $max->setDisabled(true);
155 $multi->setDisabled(true);
156 }
157 }
158
165 {
166 $max = $a_form->getInput("max");
167 $this->setMaxLength(($max !== "") ? $max : null);
168
169 $this->setMulti($a_form->getInput("multi"));
170 }
171
172 //
173 // import/export
174 //
175
176 protected function addPropertiesToXML(ilXmlWriter $a_writer)
177 {
178 $a_writer->xmlElement('FieldValue', array("id"=>"max"), $this->getMaxLength());
179 $a_writer->xmlElement('FieldValue', array("id"=>"multi"), $this->isMulti());
180 }
181
182 public function importXMLProperty($a_key, $a_value)
183 {
184 if ($a_key == "max") {
185 $this->setMaxLength($a_value != "" ? $a_value : null);
186 }
187 if ($a_key == "multi") {
188 $this->setMulti($a_value != "" ? $a_value : null);
189 }
190 }
191
192 public function getValueForXML(ilADT $element)
193 {
194 return $element->getText();
195 }
196
197 public function importValueFromXML($a_cdata)
198 {
199 $this->getADT()->setText($a_cdata);
200 }
201
202 public function importFromECS($a_ecs_type, $a_value, $a_sub_id)
203 {
204 switch ($a_ecs_type) {
206 $value = implode(',', (array) $a_value);
207 break;
208
210 $value = (int) $a_value;
211 break;
212
214 $value = (string) $a_value;
215 break;
216
218 if ($a_value instanceof ilECSTimePlace) {
219 $value = $a_value->{'get' . ucfirst($a_sub_id)}();
220 }
221 break;
222 }
223
224 if (trim($value)) {
225 $this->getADT()->setText($value);
226 return true;
227 }
228 return false;
229 }
230
231 //
232 // presentation
233 //
234
236 {
237 assert($a_text instanceof ilADTTextFormBridge);
238
239 // seems to be default in course info editor
240 $a_text->setMulti($this->isMulti(), 80, 6);
241 }
242
243
244 //
245 // search
246 //
247
248 public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
249 {
250 return $a_adt_search->getADT()->getText();
251 }
252
253 protected function parseSearchObjects(array $a_records, array $a_object_types)
254 {
255 global $ilDB;
256
257 $res = array();
258
259 $obj_ids = array();
260 foreach ($a_records as $record) {
261 if ($record["sub_type"] == "-") {
262 // keep found information
263 $obj_ids[$record["obj_id"]] = $record;
264 }
265 }
266
267 $sql = "SELECT obj_id,type" .
268 " FROM object_data" .
269 " WHERE " . $ilDB->in("obj_id", array_keys($obj_ids), "", "integer") .
270 " AND " . $ilDB->in("type", $a_object_types, "", "text");
271 $set = $ilDB->query($sql);
272 while ($row = $ilDB->fetchAssoc($set)) {
273 $row["found"] = array();
274 foreach ($obj_ids[$row["obj_id"]] as $field => $value) {
275 if (substr($field, 0, 5) == "found") {
276 $row["found"][$field] = $value;
277 }
278 }
279 $res[] = $row;
280 }
281
282 return $res;
283 }
284
295 public function searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
296 {
297 // :TODO: search type (like, fulltext)
298
299 include_once('Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
300 $condition = $a_adt_search->getSQLCondition(
303 $a_parser->getQuotedWords()
304 );
305 if ($condition) {
306 $objects = ilADTActiveRecordByType::find("adv_md_values", $this->getADT()->getType(), $this->getFieldId(), $condition, $a_locate);
307 if (sizeof($objects)) {
308 return $this->parseSearchObjects($objects, $a_object_types);
309 }
310 return array();
311 }
312 }
313}
An exception for terminatinating execution or to throw for unit testing.
static find($a_table, $a_type, $a_field_id, $a_condition, $a_additional_fields=null)
Find entries.
static getInstance()
Get singleton.
ADT form bridge base class.
ADT search bridge base class.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
ADT base class.
Definition: class.ilADT.php:12
parseSearchObjects(array $a_records, array $a_object_types)
Add object-data needed for global search to AMD search results.
searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
Search.
importXMLProperty($a_key, $a_value)
Import property from XML.
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
prepareElementForEditor(ilADTFormBridge $a_text)
Prepare editor form elements.
getFieldDefinition()
Get (type-specific) field definition.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false)
Add input elements to definition form.
importFromECS($a_ecs_type, $a_value, $a_sub_id)
Import meta data from ECS.
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form)
Import custom post values from definition form.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
getFieldDefinitionForTableGUI()
Parse properties for table gui.
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Get value for search query parser.
This class represents a checkbox property in a property form.
Representation of ECS EContent Time Place.
const TYPE_TIMEPLACE
This class represents a number property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getQuotedWords($with_quotation=false)
XML writer class.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
$def
Definition: croninfo.php:21
global $lng
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res
global $ilDB