4 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php";
41 public function __construct($a_record_id, $a_obj_id, $a_sub_type =
"-", $a_sub_id = 0)
43 $this->record_id = (int) $a_record_id;
44 $this->obj_id = (int) $a_obj_id;
45 $this->sub_type = $a_sub_type ? $a_sub_type :
"-";
46 $this->sub_id = (int) $a_sub_id;
66 foreach ($refs as $ref_id) {
69 $records = $orderings->sortRecords($records, $a_obj_id);
71 foreach ($records as $record) {
72 $id = $record->getRecordId();
74 if (!isset(
$res[$id])) {
75 $res[$id] =
new self($id, $a_obj_id, $a_sub_type, $a_sub_id);
91 $this->obj_id = (int) $a_obj_id;
92 $this->sub_type = $a_sub_type ? $a_sub_type :
"-";
93 $this->sub_id = (int) $a_sub_id;
96 $this->active_record = null;
106 if (!is_array($this->defs)) {
119 if (!$this->adt_group instanceof
ilADTGroup) {
133 include_once
"Services/ADT/classes/class.ilADTFactory.php";
139 "obj_id" => array(
"integer", $this->obj_id),
140 "sub_type" => array(
"text", $this->sub_type),
141 "sub_id" => array(
"integer", $this->sub_id)
143 $adt_group_db->setPrimary($primary);
144 $adt_group_db->setTable(
"adv_md_values");
147 foreach ($adt_group_db->getElements() as $element) {
148 if ($element->getADT()->getType() ==
"MultiEnum") {
149 $element->setFakeSingle(
true);
153 $this->active_record =
$factory->getActiveRecordByTypeInstance($adt_group_db);
154 $this->active_record->setElementIdColumn(
"field_id",
"integer");
168 include_once
"Services/ADT/classes/class.ilADTFactory.php";
189 return in_array($a_element_id, $this->
disabled);
207 foreach ($tmp as $element_id =>
$data) {
208 if (
$data[
"disabled"]) {
220 public function write(array $a_additional_data = null)
237 array(
"field_id" => array(
"integer", $a_field_id)),
252 array(
"obj_id" => array(
"integer", $a_obj_id))
271 $ilDB = $DIC[
'ilDB'];
277 array(
"obj_id" => array(
"integer", $a_obj_ids))
283 self::$preload_obj_records = array();
286 $query =
"SELECT amro.*" .
287 " FROM adv_md_record_objs amro" .
288 " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)" .
289 " WHERE active = " .
$ilDB->quote(1,
"integer");
291 while ($row =
$ilDB->fetchAssoc($set)) {
292 self::$preload_obj_records[$row[
"obj_type"]][] = array($row[
"record_id"], $row[
"optional"]);
300 if (isset(self::$preload_obj_records[$a_type])) {
301 foreach (self::$preload_obj_records[$a_type] as $item) {
307 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
309 if ($record->getRecordId() == $item[0]) {
340 public static function _cloneValues($a_source_id, $a_target_id, $a_sub_type = null, $a_source_sub_id = null, $a_target_sub_id = null, $use_stored_record_map =
false)
344 $ilLog = $DIC[
'ilLog'];
349 include_once
"Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php";
350 $new_records = $fields_map = array();
353 if ($record->getParentObject() == $a_source_id && !$use_stored_record_map) {
355 if ($a_source_id != $a_target_id) {
356 $new_records[$record->getRecordId()] = $record->_clone($tmp, $a_target_id);
358 $new_records[$record->getRecordId()] = $record->getRecordId();
360 $fields_map[$record->getRecordId()] = $tmp;
363 if (!$use_stored_record_map) {
364 self::$stored_record_map = $new_records;
365 self::$stored_fields_map = $fields_map;
367 $new_records = self::$stored_record_map;
368 $fields_map = self::$stored_fields_map;
376 $target_sel = array();
379 if (array_key_exists($record_id, $new_records)) {
380 $record_id = $new_records[
$record_id]->getRecordId();
389 $source_primary = array(
"obj_id" => array(
"integer", $a_source_id));
390 $target_primary = array(
"obj_id" => array(
"integer", $a_target_id));
396 $source_primary[
"sub_type"] = array(
"text", $a_sub_type);
397 $source_primary[
"sub_id"] = array(
"integer", $a_source_sub_id);
398 $target_primary[
"sub_type"] = array(
"text", $a_sub_type);
399 $target_primary[
"sub_id"] = array(
"integer", $a_target_sub_id);
406 "obj_id" =>
"integer",
407 "sub_type" =>
"text",
408 "sub_id" =>
"integer",
409 "field_id" =>
"integer" 413 array(
"disabled" =>
"integer")
419 foreach ($fields_map as $source_record_id => $fields) {
421 if (array_key_exists($source_record_id, $new_records)) {
422 foreach ($fields as $source_field_id => $target_field_id) {
424 $del_target_primary = $target_primary;
425 $del_target_primary[
"field_id"] = array(
"integer", $source_field_id);
429 $fix_source_primary = $source_primary;
430 $fix_source_primary[
"field_id"] = array(
"integer", $source_field_id);
431 $fix_target_primary = $target_primary;
432 $fix_target_primary[
"field_id"] = array(
"integer", $target_field_id);
436 "obj_id" =>
"integer",
437 "sub_type" =>
"text",
438 "sub_id" =>
"integer",
439 "field_id" =>
"integer" 443 array(
"disabled" =>
"integer")
450 $ilLog->write(__METHOD__ .
': No advanced meta data found.');
452 $ilLog->write(__METHOD__ .
': Start cloning advanced meta data.');
467 self::preloadByObjIds(array($a_obj_id));
470 foreach ($values_records as $values_record) {
471 $defs = $values_record->getDefinitions();
472 foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) {
473 $def =
$defs[$element_id];
476 if (!$element->isNull()) {
477 $value = $def->getValueForXML($element);
482 array(
'id' => $def->getImportId()),
488 $a_xml_writer->
xmlEndTag(
'AdvancedMetaData');
502 public static function queryForRecords($adv_rec_obj_ref_id, $adv_rec_obj_type, $adv_rec_obj_subtype, $a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter = null)
506 if (!is_array($a_obj_id)) {
507 $a_obj_id = array($a_obj_id);
510 $sub_obj_ids = array();
511 foreach ($a_records as $rec) {
512 $sub_obj_ids[] = $rec[$a_obj_subid_key];
520 "obj_id" => array(
"integer", $a_obj_id),
521 "sub_type" => array(
"text", $a_subtype),
522 "sub_id" => array(
"integer", $sub_obj_ids)
526 $record_groups = array();
528 foreach ($a_records as $rec) {
529 $obj_id = (int) $rec[$a_obj_id_key];
530 $sub_id = $rec[$a_obj_subid_key];
540 $record_groups[
$record_id]->setTable(
"adv_md_values");
545 "obj_id" => array(
"integer",
$obj_id),
546 "sub_type" => array(
"text", $a_subtype),
547 "sub_id" => array(
"integer",
$sub_id)
550 foreach ($record_groups[$record_id]->getElements() as $element) {
551 if ($element->getADT()->getType() ==
"MultiEnum") {
552 $element->setFakeSingle(
true);
564 if ($a_amet_filter) {
565 foreach ($a_amet_filter as $field_id => $element) {
567 if (!$element->isInCondition(
$adt_group->getElement($field_id))) {
574 foreach (
$adt_group->getElements() as $element_id => $element) {
575 if (!$element->isNull()) {
578 $rec[
"md_" . $element_id] = $pb->getSortable();
579 $rec[
"md_" . $element_id .
"_presentation"] = $pb;
581 $rec[
"md_" . $element_id] = null;
getType()
Get type (from class/instance)
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
ADT Active Record by type helper class.
static _getRecords()
Get records.
static initActiveRecordByType()
Init active record by type.
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, $a_obj_id)
Get xml of object values.
static _deleteByFieldId($a_field_id, ilADT $a_adt)
Delete values by field_id.
static getInstance()
Get singleton.
static preloadByPrimary($a_table, array $a_primary)
Read values by (partial) primary key.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static cloneByPrimary($a_table, array $a_primary_def, array $a_source_primary, array $a_target_primary, array $a_additional=null)
Clone values by (partial) primary key.
static _getAllReferences($a_id)
get all reference ids of object
xmlEndTag($tag)
Writes an endtag.
static _deleteByObjId($a_obj_id)
Delete by objekt id.
static _getSelectedRecordsByObject($a_obj_type, $a_ref_id, $a_sub_type="")
Get selected records by object.
setActiveRecordPrimary($a_obj_id, $a_sub_type="-", $a_sub_id=0)
Set the primary values for active record.
static findByObjectId($a_obj_id)
Find all entries for object (regardless of sub-type/sub-id)
foreach($_POST as $key=> $value) $res
getActiveRecord()
Init ADT DB Bridge (aka active record helper class)
static deleteByPrimary($a_table, array $a_primary, $a_type=null)
Delete values by (partial) primary key.
__construct($a_record_id, $a_obj_id, $a_sub_type="-", $a_sub_id=0)
Constructor.
static readByPrimary($a_table, array $a_primary, $a_type=null)
Read directly.
getADTGroup()
Init ADT group for current record.
disabled()
Example showing how to plug a disabled checkbox into a form.
static _lookupType($a_id, $a_reference=false)
lookup object type
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
isDisabled($a_element_id)
Is element disabled?
static _cloneValues($a_source_id, $a_target_id, $a_sub_type=null, $a_source_sub_id=null, $a_target_sub_id=null, $use_stored_record_map=false)
Clone Advanced Meta Data.
write(array $a_additional_data=null)
Write record values.
static $stored_fields_map
static preloadedRead($a_type, $a_obj_id)
static $stored_record_map
static $preload_obj_records
static getInstancesByRecordId($a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
static queryForRecords($adv_rec_obj_ref_id, $adv_rec_obj_type, $adv_rec_obj_subtype, $a_obj_id, $a_subtype, $a_records, $a_obj_id_key, $a_obj_subid_key, array $a_amet_filter=null)
Query data for given object records.
getDefinitions()
Get record field definitions.