19 declare(strict_types=1);
42 public function __construct($a_record_id, $a_obj_id, $a_sub_type =
"-", $a_sub_id = 0)
44 $this->record_id = (
int) $a_record_id;
45 $this->obj_id = (
int) $a_obj_id;
46 $this->sub_type = $a_sub_type ?:
"-";
47 $this->sub_id = (
int) $a_sub_id;
52 ?
string $a_obj_type =
null,
53 string $a_sub_type =
"-",
67 $records = $orderings->sortRecords($records, $a_obj_id);
69 foreach ($records as $record) {
70 $id = $record->getRecordId();
73 $res[
$id] =
new self(
$id, $a_obj_id, $a_sub_type, $a_sub_id);
82 $this->obj_id = $a_obj_id;
83 $this->sub_type = $a_sub_type ?:
"-";
84 $this->sub_id = $a_sub_id;
87 $this->active_record =
null;
96 if (!is_array($this->defs)) {
104 if (!$this->adt_group instanceof
ilADTGroup) {
118 $adt_group_db = $factory->getDBBridgeForInstance($this->
getADTGroup());
121 "obj_id" => array(
"integer", $this->obj_id),
122 "sub_type" => array(
"text", $this->sub_type),
123 "sub_id" => array(
"integer", $this->sub_id)
125 $adt_group_db->setPrimary($primary);
126 $adt_group_db->setTable(
"adv_md_values");
129 foreach ($adt_group_db->getElements() as $element) {
130 if ($element->getADT()->getType() ==
"MultiEnum") {
131 $element->setFakeSingle(
true);
135 $this->active_record = $factory->getActiveRecordByTypeInstance($adt_group_db);
136 $this->active_record->setElementIdColumn(
"field_id",
"integer");
161 return in_array($a_element_id, $this->
disabled);
175 foreach ($tmp as $element_id =>
$data) {
176 if (
$data[
"disabled"]) {
186 public function write(?array $a_additional_data =
null): void
202 array(
"field_id" => array(
"integer", $a_field_id)),
215 array(
"obj_id" => array(
"integer", $a_obj_id))
227 $ilDB = $DIC[
'ilDB'];
233 array(
"obj_id" => array(
"integer", $a_obj_ids))
238 self::$preload_obj_records = array();
241 $query =
"SELECT amro.*" .
242 " FROM adv_md_record_objs amro" .
243 " JOIN adv_md_record amr ON (amr.record_id = amro.record_id)" .
244 " WHERE active = " .
$ilDB->quote(1,
"integer");
245 $set =
$ilDB->query($query);
246 while ($row =
$ilDB->fetchAssoc($set)) {
247 self::$preload_obj_records[(string) $row[
"obj_type"]][] = array((
int) $row[
"record_id"],
248 (
int) $row[
"optional"]
257 if (isset(self::$preload_obj_records[$a_type])) {
258 foreach (self::$preload_obj_records[$a_type] as $item) {
259 $record_id = $item[0];
270 if ($record->getRecordId() == $item[0]) {
294 ?
string $a_sub_type =
null,
295 ?
int $a_source_sub_id =
null,
296 ?
int $a_target_sub_id =
null 300 $ilLog = $DIC[
'ilLog'];
305 $new_records = $fields_map = array();
309 $parent_mapping =
null;
310 if (!is_null($a_source_sub_id) && $copy_id > 0) {
311 $parent_mapping = self::getParentMapping($copy_id, (
string) $a_target_id);
312 if (!is_null($parent_mapping)) {
313 $new_records = $parent_mapping[
"records"];
314 $fields_map = $parent_mapping[
"fields"];
318 $record_mapping = [];
320 if ($record->getParentObject() == $a_source_id && is_null($parent_mapping)) {
323 if (!is_null($a_source_sub_id) && $copy_id > 0) {
324 throw new ilException(
"ilAdvancedMDValues::_cloneValues must be called for parent object first.");
328 if ($a_source_id != $a_target_id) {
329 $new_records[$record->getRecordId()] = $record->_clone($tmp, $a_target_id);
330 $record_mapping[$record->getRecordId()] = $new_records[$record->getRecordId()]->getRecordId();
332 $new_records[$record->getRecordId()] = $record->getRecordId();
334 $fields_map[$record->getRecordId()] = $tmp;
339 if ($copy_id > 0 && is_null($a_source_sub_id)) {
341 $cp_options->appendMapping(
342 $a_target_id .
'_adv_rec',
345 $cp_options->appendMapping(
346 $a_target_id .
'_adv_rec_fields',
356 $target_sel = array();
357 foreach ($source_sel as $record_id) {
359 if (array_key_exists($record_id, $new_records)) {
360 $record_id = $new_records[
$record_id]->getRecordId();
369 $source_primary = array(
"obj_id" => array(
"integer", $a_source_id));
370 $target_primary = array(
"obj_id" => array(
"integer", $a_target_id));
376 $source_primary[
"sub_type"] = array(
"text", $a_sub_type);
377 $source_primary[
"sub_id"] = array(
"integer", $a_source_sub_id);
378 $target_primary[
"sub_type"] = array(
"text", $a_sub_type);
379 $target_primary[
"sub_id"] = array(
"integer", $a_target_sub_id);
386 "obj_id" =>
"integer",
387 "sub_type" =>
"text",
388 "sub_id" =>
"integer",
389 "field_id" =>
"integer" 393 array(
"disabled" =>
"integer")
398 foreach ($fields_map as $source_record_id => $fields) {
400 if (array_key_exists($source_record_id, $new_records)) {
401 foreach ($fields as $source_field_id => $target_field_id) {
403 $del_target_primary = $target_primary;
404 $del_target_primary[
"field_id"] = array(
"integer", $source_field_id);
408 $fix_source_primary = $source_primary;
409 $fix_source_primary[
"field_id"] = array(
"integer", $source_field_id);
410 $fix_target_primary = $target_primary;
411 $fix_target_primary[
"field_id"] = array(
"integer", $target_field_id);
415 "obj_id" =>
"integer",
416 "sub_type" =>
"text",
417 "sub_id" =>
"integer",
418 "field_id" =>
"integer" 422 array(
"disabled" =>
"integer")
429 $ilLog->write(__METHOD__ .
': No advanced meta data found.');
431 $ilLog->write(__METHOD__ .
': Start cloning advanced meta data.');
438 $mappings = $cp_options->getMappings();
439 $key1 = $target .
'_adv_rec';
440 $key2 = $target .
'_adv_rec_fields';
441 if (is_array($mappings) && isset($mappings[$key1])) {
443 "records" => $mappings[$key1],
444 "fields" => $mappings[$key2] ?? []
459 self::preloadByObjIds(array($a_obj_id));
462 foreach ($values_records as $values_record) {
463 $defs = $values_record->getDefinitions();
464 foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) {
465 $def = $defs[$element_id];
468 if (!$element->isNull()) {
469 $value = $def->getValueForXML($element);
474 array(
'id' => $def->getImportId()),
479 $a_xml_writer->
xmlEndTag(
'AdvancedMetaData');
486 int $adv_rec_obj_ref_id,
487 string $adv_rec_obj_type,
488 string $adv_rec_obj_subtype,
492 string $a_obj_id_key,
493 string $a_obj_subid_key,
494 ?array $a_amet_filter =
null 498 $sub_obj_ids = array();
499 foreach ($a_records as $rec) {
500 $sub_obj_ids[] = $rec[$a_obj_subid_key];
508 "obj_id" => array(
"integer", $a_obj_id),
509 "sub_type" => array(
"text", $a_subtype),
510 "sub_id" => array(
"integer", $sub_obj_ids)
514 $record_groups = array();
516 foreach ($a_records as $rec) {
517 $obj_id = (
int) ($rec[$a_obj_id_key] ?? 0);
518 $sub_id = $rec[$a_obj_subid_key];
526 $record_id = $adv_record->getRecordId();
528 if (!isset($record_groups[$record_id])) {
532 $record_groups[
$record_id]->setTable(
"adv_md_values");
537 "obj_id" => array(
"integer", $obj_id),
538 "sub_type" => array(
"text", $a_subtype),
539 "sub_id" => array(
"integer", $sub_id)
542 foreach ($record_groups[$record_id]->getElements() as $element) {
543 if ($element->getADT()->getType() ==
"MultiEnum") {
544 $element->setFakeSingle(
true);
551 $active_record->
read();
553 $adt_group = $record_groups[
$record_id]->getADT();
555 if ($a_amet_filter) {
556 foreach ($a_amet_filter as $field_id => $element) {
557 if ($adt_group->
hasElement((
string) $field_id)) {
558 if (!$element->isInCondition($adt_group->
getElement((
string) $field_id))) {
565 foreach ($adt_group->
getElements() as $element_id => $element) {
566 if (!$element->isNull()) {
569 $rec[
"md_" . $element_id] = $pb->getSortable();
570 $rec[
"md_" . $element_id .
"_presentation"] = $pb;
572 $rec[
"md_" . $element_id] =
null;
getType()
Get type (from class/instance)
static getInstancesForObjectId(int $a_obj_id, ?string $a_obj_type=null, string $a_sub_type="-", int $a_sub_id=0)
static readByPrimary(string $a_table, array $a_primary, ?string $a_type=null)
Read directly.
static _deleteByFieldId(int $a_field_id, ilADT $a_adt)
Delete values by field_id.
setElementIdColumn(string $a_name, string $a_type)
hasElement(string $a_name)
ADT Active Record by type helper class This class expects a valid primary for all actions! ...
static _getRecords()
Get records public.
static initActiveRecordByType()
Init active record by type.
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
static _getAllReferences(int $id)
get all reference ids for object ID
static preloadByPrimary(string $a_table, array $a_primary)
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
static _getSelectedRecordsByObject(string $a_obj_type, int $a_id, string $a_sub_type="", bool $is_ref_id=true)
static preloadedRead(string $a_type, int $a_obj_id)
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
xmlEndTag(string $tag)
Writes an endtag.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static deleteByPrimary(string $a_table, array $a_primary, ?string $a_type=null)
setActiveRecordPrimary(int $a_obj_id, string $a_sub_type="-", int $a_sub_id=0)
static getObjRecSelection(int $a_obj_id, string $a_sub_type="")
Get repository object record selection.
ilADTActiveRecordByType $active_record
static queryForRecords(int $adv_rec_obj_ref_id, string $adv_rec_obj_type, string $adv_rec_obj_subtype, array $a_obj_id, string $a_subtype, array $a_records, string $a_obj_id_key, string $a_obj_subid_key, ?array $a_amet_filter=null)
static findByObjectId(int $a_obj_id)
Find all entries for object (regardless of sub-type/sub-id)
getActiveRecord()
Init ADT DB Bridge (aka active record helper class)
__construct($a_record_id, $a_obj_id, $a_sub_type="-", $a_sub_id=0)
static _deleteByObjId(int $a_obj_id)
Delete by objekt id.
read(bool $a_return_additional_data=false)
Read record.
static array $preload_obj_records
write(?array $a_additional_data=null)
Write record values.
isDisabled(string $a_element_id)
static saveObjRecSelection(int $a_obj_id, string $a_sub_type="", ?array $a_records=null, bool $a_delete_before=true)
Save repository object record selection.
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, int $a_obj_id)
Get xml of object values.
static _cloneValues(int $copy_id, int $a_source_id, int $a_target_id, ?string $a_sub_type=null, ?int $a_source_sub_id=null, ?int $a_target_sub_id=null)
Clone Advanced Meta Data.
static getParentMapping(int $copy_id, string $target)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
static _getInstance(int $a_copy_id)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
static cloneByPrimary(string $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 _lookupType(int $id, bool $reference=false)
getElement(string $a_name)
getDefinitions()
Get record field definitions.