map-value to extract from classification metadata */ protected $classification = []; /** * Set the association between property uri and value to find into classification metadata source * * @param $propertyUri * @param $classificationValue * @throws MetadataExtractionException */ public function setClassificationMapping($propertyUri, $classificationValue) { if (empty($propertyUri) || ! is_string($propertyUri)) { throw new MetadataExtractionException(__('PropertyUri to map has to a valid uri')); } if (empty($classificationValue) || ! is_string($classificationValue)) { throw new MetadataExtractionException(__('Classification value to map has to a string')); } $this->classification[$propertyUri] = $classificationValue; } /** * @see ImsManifestDataExtractor::extract() */ public function extract($manifest) { $values = parent::extract($manifest); $newValues = []; foreach ($values as $resourceIdentifier => $metadataValueCollection) { $i = 0; $classificationMetadataValue = null; /** @var ImsManifestMetadataValue $metadataValue */ foreach ($metadataValueCollection as $metadataValue) { foreach ($this->getClassificationMetadata() as $property => $sourceValue) { if ( $metadataValue->getValue() === '' || $metadataValue->getValue() != $sourceValue || $metadataValue->getPath() !== $this->getSourcePath() ) { continue; } // LOM Classification case. if (isset($metadataValueCollection[$i + 1])) { /** @var MetadataValue $metadata */ $metadata = $metadataValueCollection[$i + 1]; if ($metadata->getPath() === $this->getEntryPath()) { if ($metadata->getValue() !== '') { $newValues[$resourceIdentifier][] = new SimpleMetadataValue( $resourceIdentifier, ['http://ltsc.ieee.org/xsd/LOM#lom', $property], $metadata->getValue() ); } } } } $i++; } } return $newValues; } /** * Get an array to map classification metadata to extract * * @return array * @throws MetadataExtractionException */ protected function getClassificationMetadata() { if (empty($this->classification)) { throw new MetadataExtractionException(__('Classification metadata is required to be extracted.')); } return $this->classification; } /** * Get default source path into DomDocument * * @return array */ protected function getSourcePath() { return [ 'http://ltsc.ieee.org/xsd/LOM#lom', 'http://ltsc.ieee.org/xsd/LOM#classification', 'http://ltsc.ieee.org/xsd/LOM#taxonPath', 'http://ltsc.ieee.org/xsd/LOM#source', 'http://ltsc.ieee.org/xsd/LOM#string' ]; } /** * Get default entry path into DomDocument * * @return array */ protected function getEntryPath() { return [ 'http://ltsc.ieee.org/xsd/LOM#lom', 'http://ltsc.ieee.org/xsd/LOM#classification', 'http://ltsc.ieee.org/xsd/LOM#taxonPath', 'http://ltsc.ieee.org/xsd/LOM#taxon', 'http://ltsc.ieee.org/xsd/LOM#entry', 'http://ltsc.ieee.org/xsd/LOM#string' ]; } }