33 define(
'UDF_TYPE_TEXT',1);
34 define(
'UDF_TYPE_SELECT',2);
35 define(
'UDF_NO_VALUES',1);
36 define(
'UDF_DUPLICATE_VALUES',2);
75 if(!strlen($a_import_id))
79 $parts = explode(
'_',$a_import_id);
85 if($parts[1] != $ilSetting->get(
'inst_id',0))
89 if($parts[2] !=
'udf')
96 if(is_array($this->definitions[
"$parts[3]"]))
105 foreach($this->definitions as $definition)
107 if($definition[
'field_name'] == $a_name)
109 return $definition[
'field_id'];
117 return $this->definitions ? $this->definitions : array();
122 return is_array($this->definitions[$a_id]) ? $this->definitions[$a_id] : array();
127 foreach($this->definitions as $id => $definition)
129 if($definition[
'visible'])
131 $visible_definition[$id] = $definition;
134 return $visible_definition ? $visible_definition : array();
139 foreach($this->definitions as $id => $definition)
141 if($definition[
'searchable'])
143 $searchable_definition[$id] = $definition;
146 return $searchable_definition ? $searchable_definition : array();
158 foreach($this->definitions as $id => $definition)
160 if($definition[
'course_export'])
162 $cexp_definition[$id] = $definition;
165 return $cexp_definition ? $cexp_definition : array();
171 $this->field_name = $a_name;
175 return $this->field_name;
179 $this->field_type = $a_type;
183 return $this->field_type;
187 $this->field_values = array();
188 foreach($a_values as $value)
192 $this->field_values[] = $value;
198 return $this->field_values ? $this->field_values : array();
203 $this->field_visible = $a_visible;
207 return $this->field_visible;
211 $this->field_changeable = $a_changeable;
215 return $this->field_changeable;
219 $this->field_required = $a_required;
223 return $this->field_required;
227 $this->field_searchable = $a_searchable;
231 return $this->field_searchable;
235 $this->field_export = $a_export;
239 return $this->field_export;
243 $this->field_course_export = $a_course_export;
247 return $this->field_course_export;
253 foreach($a_values as $value)
255 $values[$value] = $value;
257 return $values ? $values : array();
271 $unique[$value] = $value;
278 if($number != count($unique))
287 $query =
"SELECT * FROM user_defined_field_definition ".
288 "WHERE field_name = ".$this->db->quote($a_field_name).
" ";
290 $res = $this->db->query($query);
292 return (
bool)
$res->numRows();
298 $query =
"INSERT INTO user_defined_field_definition ".
299 "SET field_name = ".$this->db->quote($this->
getFieldName()).
", ".
300 "field_type = ".$this->db->quote($this->
getFieldType()).
", ".
301 "field_values = '".addslashes(serialize($this->
getFieldValues())).
"', ".
309 $this->db->query($query);
312 $field_id = $this->db->getLastInsertId();
314 $query =
"ALTER TABLE usr_defined_data ADD `".(int) $field_id.
"` TEXT NOT NULL";
315 $this->db->query($query);
321 function delete($a_id)
324 $query =
"DELETE FROM user_defined_field_definition ".
325 "WHERE field_id = ".$this->db->quote($a_id).
" ";
326 $this->db->query($query);
329 $query =
"ALTER TABLE usr_defined_data DROP `".(int) $a_id.
"`";
330 $this->db->query($query);
339 $query =
"UPDATE user_defined_field_definition ".
340 "SET field_name = ".$this->db->quote($this->
getFieldName()).
", ".
341 "field_type = ".$this->db->quote($this->
getFieldType()).
", ".
342 "field_values = '".addslashes(serialize($this->
getFieldValues())).
"', ".
349 "WHERE field_id = ".$this->db->quote($a_id).
" ";
351 $this->db->query($query);
364 $query =
"SELECT * FROM user_defined_field_definition ";
365 $res = $this->db->query($query);
367 $this->definitions = array();
370 $this->definitions[$row->field_id][
'field_id'] = $row->field_id;
371 $this->definitions[$row->field_id][
'field_name'] = $row->field_name;
372 $this->definitions[$row->field_id][
'field_type'] = $row->field_type;
373 $this->definitions[$row->field_id][
'il_id'] =
'il_'.$ilSetting->get(
'inst_id',0).
'_udf_'.$row->field_id;
375 $tmp = unserialize(stripslashes($row->field_values));
377 $this->definitions[$row->field_id][
'field_values'] = $tmp;
379 $this->definitions[$row->field_id][
'visible'] = $row->visible;
380 $this->definitions[$row->field_id][
'changeable'] = $row->changeable;
381 $this->definitions[$row->field_id][
'required'] = $row->required;
382 $this->definitions[$row->field_id][
'searchable'] = $row->searchable;
383 $this->definitions[$row->field_id][
'export'] = $row->export;
384 $this->definitions[$row->field_id][
'course_export'] = $row->course_export;
396 $new_values = array();
397 foreach($definition[
'field_values'] as $value)
399 if($counter++ != $a_value_id)
401 $new_values[] = $value;
408 $query =
"UPDATE user_defined_field_definition ".
409 "SET field_values = '".addslashes(serialize($new_values)).
"' ".
410 "WHERE field_id = ".$this->db->quote($a_field_id).
"";
412 $this->db->query($query);
415 $query =
"UPDATE usr_defined_data ".
416 "SET `".$this->db->quote($a_field_id).
"` = '' ".
417 "WHERE `".$this->db->quote($a_field_id).
"` = ".$this->db->quote($old_value).
"";
418 $this->db->query($query);
428 include_once
'classes/class.ilXmlWriter.php';
433 return $xml_writer->xmlDumpMem(
false);
442 $xml_writer->xmlStartTag (
"UDFDefinitions");
446 "Id" => $definition [
"il_id"],
447 "Type" => $definition[
"field_type"] ==
UDF_TYPE_SELECT?
"SELECT" :
"TEXT",
448 "Visible" => $definition[
"visible"]?
"TRUE" :
"FALSE",
449 "Changeable" => $definition[
"changeable"]?
"TRUE" :
"FALSE",
450 "Required" => $definition[
"required"]?
"TRUE" :
"FALSE",
451 "Searchable" => $definition[
"searchable"]?
"TRUE" :
"FALSE",
452 "CourseExport" => $definition[
"course_export"]?
"TRUE" :
"FALSE",
453 "Export" => $definition[
"export"]?
"TRUE" :
"FALSE",
455 $xml_writer->xmlStartTag (
"UDFDefinition", $attributes);
456 $xml_writer->xmlElement(
'UDFName', null, $definition[
'field_name']);
458 $field_values = $definition[
"field_values"];
459 foreach ($field_values as $field_value)
461 $xml_writer->xmlElement(
'UDFValue', null, $field_value);
464 $xml_writer->xmlEndTag (
"UDFDefinition");
466 $xml_writer->xmlEndTag (
"UDFDefinitions");