5 include_once(
"./Services/Component/classes/class.ilPlugin.php");
28 return "AdvancedMetaData";
33 return "AdvancedMDClaiming";
43 require_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDPermissionHelper.php";
61 abstract public function checkPermission($a_user_id, $a_context_type, $a_context_id, $a_action_id, $a_action_sub_id);
78 $set = $ilDB->query(
"SELECT record_id FROM adv_md_record".
79 " WHERE record_id = ".$ilDB->quote($a_record_id,
"integer"));
80 return (
bool)$ilDB->numRows($set);
92 public static function createDBRecord($a_title, $a_description, $a_active, array $a_obj_types)
96 $record_id = $ilDB->nextId(
"adv_md_record");
99 "record_id" => array(
"integer", $record_id),
100 "import_id" => array(
"text",
'il_'.IL_INST_ID.
'_adv_md_record_'.$record_id),
101 "title" => array(
"text", trim($a_title)),
102 "description" => array(
"text", trim($a_description)),
103 "active" => array(
"integer", (
int)$a_active)
105 $ilDB->insert(
"adv_md_record", $fields);
119 protected static function isValidObjType($a_obj_type, $a_is_substitution =
false)
122 $valid = array(
"crs",
"cat");
124 if(!$a_is_substitution)
129 return in_array($a_obj_type,
$valid);
142 foreach($a_obj_types as $type)
146 $type = strtolower(trim($type));
151 $type = strtolower(trim($type[0]));
152 $subtype = strtolower(trim($type[1]));
155 if(self::isValidObjType($type))
158 "record_id" => array(
"integer", $a_record_id),
159 "obj_type" => array(
"text", $type),
160 "sub_type" => array(
"text", $subtype)
162 $ilDB->insert(
"adv_md_record_objs", $fields);
177 public static function updateDBRecord($a_record_id, $a_title, $a_description, $a_active, array $a_obj_types)
181 if(self::hasDBRecord($a_record_id))
184 "title" => array(
"text", trim($a_title)),
185 "description" => array(
"text", trim($a_description)),
186 "active" => array(
"integer", (
int)$a_active)
188 $ilDB->update(
"adv_md_record", $fields,
189 array(
"record_id" => array(
"integer", $a_record_id)));
191 $ilDB->manipulate(
"DELETE FROM adv_md_record_objs".
192 " WHERE record_id = ".$ilDB->quote($a_record_id,
"integer"));
212 if(self::hasDBRecord($a_record_id))
214 $ilDB->manipulate(
"DELETE FROM adv_md_record".
215 " WHERE record_id = ".$ilDB->quote($a_record_id,
"integer"));
232 $set = $ilDB->query(
"SELECT field_id FROM adv_mdf_definition".
233 " WHERE field_id = ".$ilDB->quote($a_field_id,
"integer"));
234 return (
bool)$ilDB->numRows($set);
249 $sql =
"SELECT max(position) pos".
250 " FROM adv_mdf_definition".
251 " WHERE record_id = ".$ilDB->quote($a_record_id,
"integer");
252 $set = $ilDB->query($sql);
253 if($ilDB->numRows($set))
255 $pos = $ilDB->fetchAssoc($set);
256 return (
int)$pos[
"pos"];
273 public static function createDBField($a_record_id, $a_type, $a_title, $a_description = null, $a_searchable =
false, array $a_definition = null)
277 if(!self::hasDBRecord($a_record_id))
282 $field_id = $ilDB->nextId(
"adv_mdf_definition");
285 $a_type = (int)$a_type;
286 if($a_type < 1 || $a_type > 7)
294 "record_id" => array(
"integer", $a_record_id),
295 "field_id" => array(
"integer", $field_id),
296 "import_id" => array(
"text",
"il_".IL_INST_ID.
"_adv_md_field_".$field_id),
297 "field_type" => array(
"integer", $a_type),
298 "position" => array(
"integer", $pos),
299 "title" => array(
"text", trim($a_title)),
300 "description" => array(
"text", trim($a_description)),
301 "searchable" => array(
"integer", (
int)$a_searchable)
305 $fields[
"field_values"] = array(
"text", serialize($a_definition));
307 $ilDB->insert(
"adv_mdf_definition", $fields);
322 public static function updateDBField($a_field_id, $a_title, $a_description = null, $a_searchable =
false, array $a_definition = null)
326 if(self::hasDBField($a_field_id))
329 "field_id" => array(
"integer", $a_field_id),
330 "title" => array(
"text", trim($a_title)),
331 "description" => array(
"text", trim($a_description)),
332 "searchable" => array(
"integer", (
int)$a_searchable)
336 $fields[
"field_values"] = array(
"text", serialize($a_definition));
338 $ilDB->update(
"adv_mdf_definition", $fields,
339 array(
"field_id" => array(
"integer", $a_field_id)));
356 if(self::hasDBField($a_field_id))
358 $ilDB->manipulate(
"DELETE FROM adv_mdf_definition".
359 " WHERE field_id = ".$ilDB->quote($a_field_id,
"integer"));
377 $set = $ilDB->query(
"SELECT * FROM adv_md_substitutions".
378 " WHERE obj_type = ".$ilDB->quote($a_obj_type,
"text"));
379 if($ilDB->numRows($set))
381 $res = $ilDB->fetchAssoc($set);
382 $res[
"hide_description"] = array(
"integer", (
bool)
$res[
"hide_description"]);
383 $res[
"hide_field_names"] = array(
"integer", (
bool)$res[
"hide_field_names"]);
385 if($a_include_field_data)
387 $res[
"substitution"] = array(
"text", (array)unserialize($res[
"substitution"]));
391 unset($res[
"substitution"]);
393 unset($res[
"obj_type"]);
411 if(self::isValidObjType($a_obj_type,
true))
419 $fields = array(
"obj_type" => array(
"text", $a_obj_type));
422 $fields[
"hide_description"] = array(
"integer", !(
bool)$a_show_description);
423 $fields[
"hide_field_names"] = array(
"integer", !(
bool)$a_show_field_names);
427 $ilDB->insert(
"adv_md_substitutions", $fields);
431 $ilDB->update(
"adv_md_substitutions", $fields,
432 array(
"obj_type" => array(
"text", $a_obj_type)));
449 if(self::isValidObjType($a_obj_type,
true))
452 $fields = $fields[
"substitution"][1];
453 foreach($fields as $field)
455 if($field[
"field_id"] == $a_field_id)
477 if(self::isValidObjType($a_obj_type,
true))
487 $fields = $fields[
"substitution"][1];
491 foreach($fields as $idx => $field)
493 if($field[
"field_id"] == $a_field_id)
495 $fields[$idx][
"bold"] = (bool)$a_bold;
496 $fields[$idx][
"newline"] = (bool)$a_newline;
504 "field_id" => $a_field_id
505 ,
"bold" => (
bool)$a_bold
506 ,
"newline" => (
bool)$a_newline
510 $fields = array(
"substitution"=>array(
"text", serialize($fields)));
511 $ilDB->update(
"adv_md_substitutions", $fields,
512 array(
"obj_type" => array(
"text", $a_obj_type)));
528 if(self::isValidObjType($a_obj_type,
true))
537 $fields = $fields[
"substitution"][1];
541 foreach($fields as $idx => $field)
543 if($field[
"field_id"] == $a_field_id)
545 unset($fields[$idx]);
552 $fields = array(
"substitution"=>array(
"text", serialize($fields)));
553 $ilDB->update(
"adv_md_substitutions", $fields,
554 array(
"obj_type" => array(
"text", $a_obj_type)));