private function parseInfoPage() { include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php'; include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php'; include_once 'Services/ADT/classes/class.ilADTFactory.php'; foreach (ilAdvancedMDValues::getInstancesForObjectId($this->obj_id, $this->obj_type) as $record_id => $a_values) { // this correctly binds group and definitions $a_values->read(); $this->info->addSection(ilAdvancedMDRecord::_lookupTitle($record_id)); $defs = $a_values->getDefinitions(); foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) { if (!$element->isNull()) { $this->info->addProperty($defs[$element_id]->getTitle(), ilADTFactory::getInstance()->getPresentationBridgeForInstance($element)->getHTML()); } } } }
/** * Add Advanced Meta Data Information to the Info Screen * * @param ilInfoScreenGUI $info */ protected function parseInfoScreen(ilInfoScreenGUI $info) { include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php'; include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php'; include_once 'Services/ADT/classes/class.ilADTFactory.php'; $type = $this->object->getOrgUnitType(); if (!$type) { return; } $assigned_record_ids = $type->getAssignedAdvancedMDRecordIds(); foreach (ilAdvancedMDValues::getInstancesForObjectId($this->object->getId(), 'orgu') as $record_id => $a_values) { // Skip record ids not assigned to the type if (!in_array($record_id, $assigned_record_ids)) { continue; } // Note that we have to do this because with the instances above the sub-type and sub-id are missing... $a_values = new ilAdvancedMDValues($record_id, $this->object->getId(), 'orgu_type', $this->object->getOrgUnitTypeId()); // this correctly binds group and definitions $a_values->read(); $info->addSection(ilAdvancedMDRecord::_lookupTitle($record_id)); $defs = $a_values->getDefinitions(); foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) { if (!$element->isNull()) { $info->addProperty($defs[$element_id]->getTitle(), ilADTFactory::getInstance()->getPresentationBridgeForInstance($element)->getHTML()); } } } }
/** * Get the assigned AMD Values. * If a record_id is given, returns an array with all Elements (instances of ilADT objects) belonging to this record. * If no record_id is given, returns an associative array with record-IDs as keys and ilADT objects as values * * @param int $a_record_id * * @return array */ public function getAdvancedMDValues($a_record_id = 0) { if (!$this->getOrgUnitTypeId()) { return array(); } // Serve from cache? if (is_array($this->amd_data)) { if ($a_record_id) { return isset($this->amd_data[$a_record_id]) ? $this->amd_data[$a_record_id] : array(); } else { return $this->amd_data; } } /** @var ilAdvancedMDValues $amd_values */ foreach (ilAdvancedMDValues::getInstancesForObjectId($this->getId(), 'orgu') as $record_id => $amd_values) { $amd_values = new ilAdvancedMDValues($record_id, $this->getId(), 'orgu_type', $this->getOrgUnitTypeId()); $amd_values->read(); $this->amd_data[$record_id] = $amd_values->getADTGroup()->getElements(); } if ($a_record_id) { return isset($this->amd_data[$a_record_id]) ? $this->amd_data[$a_record_id] : array(); } else { return $this->amd_data; } }
/** * Get advanced metadata values for object id * * @param int $a_obj_id * @return array */ public static function getAdvancedMDValuesForObjId($a_obj_id) { $res = array(); include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php'; // getting all records foreach (ilAdvancedMDValues::getInstancesForObjectId($a_obj_id) as $a_values) { // this correctly binds group and definitions $a_values->read(); // getting elements for record $defs = $a_values->getDefinitions(); foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) { if (!$element->isNull()) { // :TODO: using this for a "flat" presentation $res[$element_id] = $defs[$element_id]->getValueForXML($element); } else { // :TODO: is this needed? $res[$element_id] = null; } } } return $res; }
/** * Add advanced metadata to json (export) * * @param object $a_json * @param ilECSSetting $a_server * @param array $a_definition * @param int $a_mapping_mode */ protected function importMetadataFromJson($a_json, ilECSSetting $a_server, array $a_definition, $a_mapping_mode) { global $ilLog; $ilLog->write("importing metadata from json: " . print_r($a_json, true)); include_once './Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php'; include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php'; include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php'; $mappings = ilECSDataMappingSettings::getInstanceByServerId($a_server->getServerId()); $values_records = ilAdvancedMDValues::getInstancesForObjectId($this->getId(), $this->getType()); foreach ($values_records as $values_record) { // this correctly binds group and definitions $values_record->read(); } $do_save = false; foreach ($a_definition as $id => $type) { if (is_array($type)) { $target = $type[1]; $type = $type[0]; } else { $target = $id; } $timePlace = null; if ($field = $mappings->getMappingByECSName($a_mapping_mode, $id)) { // find element in records $adv_md_def = null; foreach ($values_records as $values_record) { $adv_md_defs = $values_record->getDefinitions(); if (isset($adv_md_defs[$field])) { $adv_md_def = $adv_md_defs[$field]; break; } } if (!$adv_md_def) { continue; } $raw_value = $a_json->{$target}; if ($type == ilECSUtils::TYPE_TIMEPLACE) { if (!is_object($timePlace)) { include_once './Services/WebServices/ECS/classes/class.ilECSTimePlace.php'; if (is_object($raw_value)) { $timePlace = new ilECSTimePlace(); $timePlace->loadFromJSON($raw_value); } else { $timePlace = new ilECSTimePlace(); } } $raw_value = $timePlace; } if ($adv_md_def->importFromECS($type, $raw_value, $id)) { $do_save = true; } } } if ($do_save) { foreach ($values_records as $values_record) { $additional = array(); foreach ($values_record->getADTGroup()->getElements() as $element_id => $element) { if (!$element->isNull()) { $additional[$element_id] = array("disabled" => array("integer", 1)); } } $values_record->write($additional); } } }
/** * Start element handler * * @access public * @param resource $a_xml_parser xml parser * @param string $a_name element name * @param array $a_attribs element attributes array * */ public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs) { switch ($a_name) { case 'AdvancedMetaData': $this->values_records = ilAdvancedMDValues::getInstancesForObjectId($this->obj_id); foreach ($this->values_records as $values_record) { // init ADTGroup before definitions to bind definitions to group $values_record->getADTGroup(); foreach ($values_record->getDefinitions() as $def) { $this->values[$def->getImportId()] = $def; } } break; case 'Value': $this->initValue($a_attribs['id']); break; } }