4 require_once
"Services/ADT/classes/class.ilADTFactory.php";
45 $this->
read($a_field_id);
55 public static function getInstance($a_field_id, $a_type = null)
61 $set = $ilDB->query(
"SELECT field_type".
62 " FROM adv_mdf_definition".
63 " WHERE field_id = ".$ilDB->quote($a_field_id,
"integer"));
64 $a_type = $ilDB->fetchAssoc($set);
65 $a_type = $a_type[
"field_type"];
68 if(self::isValidType($a_type))
70 $class =
"ilAdvancedMDFieldDefinition".self::getTypeString($a_type);
71 require_once
"Services/AdvancedMetaData/classes/Types/class.".$class.
".php";
72 return new $class($a_field_id);
88 self::TYPE_TEXT =>
"Text",
89 self::TYPE_SELECT =>
"Select",
90 self::TYPE_DATE =>
"Date",
91 self::TYPE_DATETIME =>
"DateTime",
92 self::TYPE_FLOAT =>
"Float",
93 self::TYPE_LOCATION =>
"Location",
94 self::TYPE_INTEGER =>
"Integer",
95 self::TYPE_SELECT_MULTI =>
"SelectMulti"
97 $map = array_flip($map);
98 if(array_key_exists($a_type, $map))
117 $query =
"SELECT * FROM adv_mdf_definition".
118 " WHERE record_id = ".$ilDB->quote($a_record_id,
"integer");
119 if($a_only_searchable)
121 $query .=
" AND searchable = ".$ilDB->quote(1,
"integer");
123 $query .=
" ORDER BY position";
124 $set = $ilDB->query(
$query);
125 while(
$row = $ilDB->fetchAssoc($set))
128 $field->import(
$row);
129 $defs[
$row[
"field_id"]] = $field;
141 $query =
"SELECT amf.* FROM adv_md_record_objs aro".
142 " JOIN adv_md_record amr ON aro.record_id = amr.record_id".
143 " JOIN adv_mdf_definition amf ON aro.record_id = amf.record_id".
144 " WHERE obj_type = ".$ilDB->quote($a_obj_type,
'text');
145 if((
bool)$a_active_only)
147 $query .=
" AND active = ".$ilDB->quote(1,
"integer");
149 $query .=
" ORDER BY aro.record_id,position";
151 while(
$row = $ilDB->fetchAssoc(
$res))
154 $field->import(
$row);
155 $defs[
$row[
"field_id"]] = $field;
170 $query =
"SELECT field_id, field_type FROM adv_mdf_definition".
171 " WHERE import_id = ".$ilDB->quote($a_import_id,
'text');
172 $set = $ilDB->query(
$query);
173 if($ilDB->numRows($set))
175 $row = $ilDB->fetchAssoc($set);
189 $field_ids = array();
191 $query =
"SELECT field_id FROM adv_md_record amr".
192 " JOIN adv_mdf_definition amfd ON (amr.record_id = amfd.record_id)".
193 " WHERE active = ".$ilDB->quote(1,
"integer").
194 " AND searchable = ".$ilDB->quote(1,
"integer");
195 $set = $ilDB->query(
$query);
196 while(
$row = $ilDB->fetchAssoc($set))
198 $field_ids[] =
$row[
"field_id"];
212 $group_def = $factory->getDefinitionInstanceByType(
"Group");
213 foreach($a_defs as $def)
215 $group_def->addElement($def->getFieldId(), $def->getADTDefinition());
217 $group = $factory->getInstanceByDefinition($group_def);
220 foreach($group->getElements() as $element_id => $element)
222 $a_defs[$element_id]->setADT($element);
249 return array(self::TYPE_TEXT, self::TYPE_DATE, self::TYPE_DATETIME,
250 self::TYPE_SELECT, self::TYPE_INTEGER, self::TYPE_FLOAT,
251 self::TYPE_LOCATION, self::TYPE_SELECT_MULTI);
262 return in_array((
int)$a_type, self::getValidTypes());
270 abstract public function getType();
280 if(self::isValidType($a_type))
283 self::TYPE_TEXT =>
"Text",
284 self::TYPE_SELECT =>
"Select",
285 self::TYPE_DATE =>
"Date",
286 self::TYPE_DATETIME =>
"DateTime",
287 self::TYPE_FLOAT =>
"Float",
288 self::TYPE_LOCATION =>
"Location",
289 self::TYPE_INTEGER =>
"Integer",
290 self::TYPE_SELECT_MULTI =>
"SelectMulti"
292 return $map[$a_type];
304 return "udf_type_".strtolower(self::getTypeString($this->
getType()));
341 if(!$this->adt instanceof
ilADT)
356 if(!$this->adt instanceof
ilADT)
373 $this->field_id = (int)$a_id;
393 $this->record_id = (int)$a_id;
413 if($a_id_string !== null)
415 $a_id_string = trim($a_id_string);
417 $this->import_id = $a_id_string;
437 $this->position = (int)$a_pos;
457 if($a_title !== null)
459 $a_title = trim($a_title);
461 $this->title = $a_title;
483 $a_desc = trim($a_desc);
485 $this->description = $a_desc;
505 $this->searchable = (bool)$a_status;
525 $this->required = (bool)$a_status;
613 $title->setRequired(
true);
618 $title->setDisabled(
true);
630 $desc->setDisabled(
true);
641 $check->setDisabled(
true);
716 $hidden->setValue(1);
737 $sql =
"SELECT max(position) pos".
738 " FROM adv_mdf_definition".
739 " WHERE record_id = ".$ilDB->quote($this->
getRecordId(),
"integer");
740 $set = $ilDB->query($sql);
741 if($ilDB->numRows($set))
743 $pos = $ilDB->fetchAssoc($set);
744 return (
int)$pos[
"pos"];
758 return 'il_'.IL_INST_ID.
'_adv_md_field_'.$a_field_id;
769 "field_type" => array(
"integer", $this->
getType()),
770 "record_id" => array(
"integer", $this->
getRecordId()),
771 "import_id" => array(
"text", $this->
getImportId()),
772 "title" => array(
"text", $this->
getTitle()),
774 "position" => array(
"integer", $this->
getPosition()),
775 "searchable" => array(
"integer", $this->
isSearchable()),
776 "required" => array(
"integer", $this->
isRequired())
782 $fields[
"field_values"] = array(
"text", serialize($def));
793 protected function import(array $a_data)
805 if($a_data[
"field_values"])
814 protected function read($a_field_id)
818 if(!(
int)$a_field_id)
823 $sql =
"SELECT * FROM adv_mdf_definition".
824 " WHERE field_id = ".$ilDB->quote($a_field_id,
"integer");
825 $set = $ilDB->query($sql);
826 if($ilDB->numRows($set))
828 $row = $ilDB->fetchAssoc($set);
845 $next_id = $ilDB->nextId(
"adv_mdf_definition");
857 $fields[
"field_id"] = array(
"integer", $next_id);
859 $ilDB->insert(
"adv_mdf_definition", $fields);
871 return $this->
save();
874 $ilDB->update(
"adv_mdf_definition",
876 array(
"field_id"=>array(
"integer", $this->
getFieldId())));
882 public function delete()
892 include_once(
"Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
895 $query =
"DELETE FROM adv_mdf_definition".
896 " WHERE field_id = ".$ilDB->quote($this->
getFieldId(),
"integer");
897 $ilDB->manipulate(
$query);
917 'fieldType' => self::getTypeString($this->
getType())));
1044 foreach($a_records as $record)
1046 if($record[
"sub_type"] ==
"-")
1048 $obj_ids[] = $record[
"obj_id"];
1052 $sql =
"SELECT obj_id,type".
1053 " FROM object_data".
1054 " WHERE ".$ilDB->in(
"obj_id", $obj_ids,
"",
"integer").
1055 " AND ".$ilDB->in(
"type", $a_object_types,
"",
"text");
1056 $set = $ilDB->query($sql);
1057 while(
$row = $ilDB->fetchAssoc($set))
1067 include_once(
'Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
1073 $element_id =
"loc";
1080 if(
sizeof($objects))
1083 foreach($objects as $item)
1085 if($item[
"obj_id"] == $a_obj_id &&
1086 $item[
"sub_type"] == $sub_obj_type)
1088 $res[] = $item[
"sub_id"];
1112 include_once(
'Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
1117 if(
sizeof($objects))