/** * @{inheritdoc} */ public function validateDescription($json) { $object = json_decode($json); // If the object title has the "VALID" keyword, we treat it as valid. // Else, we return some random mumbo jumbo. if (isset($object->general->title) && preg_match('/VALID/', Utils::getLSValue($object->general->title))) { return array('valid' => true); } else { return array('valid' => false, 'message' => "Description is not complete or not compliant.", 'errors' => array('general.title' => 'missing', 'general.description' => 'wrong type', 'general.identifier.entry' => 'malformed', 'education.typicalLearningTime' => 'malformed', 'education.description' => 'missing')); } }
/** * Test the parsing of Vocabulary entries (VC). */ public function testVCParsing() { $this->assertEquals('value fr', Utils::getVCName(['name' => 'raw name', 'ontologyName' => ['fr' => 'value fr', 'de' => 'value de']], ['fr', 'de']), "Fetching the Vocabulary name in the correct order (fr first)."); $this->assertEquals('value de', Utils::getVCName(['name' => 'raw name', 'ontologyName' => ['fr' => 'value fr', 'de' => 'value de']], ['de', 'fr']), "Fetching the Vocabulary name in the correct order (de first)."); $this->assertEquals('value de', Utils::getVCName((object) ['name' => 'raw name', 'ontologyName' => (object) ['fr' => 'value fr', 'de' => 'value de']], ['de', 'fr']), "Fetching the Vocabulary name from a stdClass works as well."); $this->assertEquals('value de', Utils::getVCName(['name' => 'raw name', 'ontologyName' => ['fr' => 'value fr', 'de' => 'value de']], ['en', 'de', 'fr']), "Fetching the Vocabulary name in the correct order (en first, falling back to de)."); $this->assertEquals('value de', Utils::getVCName(['name' => 'raw name', 'ontologyName' => ['fr' => 'value fr', 'de' => 'value de']]), "Not passing a language fallback array uses the default from Utils::getLSValue() (de first)."); $this->assertEquals('raw name', Utils::getVCName(['name' => 'raw name', 'ontologyName' => ['fr' => 'value fr', 'de' => 'value de']], []), "Returning the raw Vocabulary name when no match (no language fallback)."); $this->assertEquals('raw name', Utils::getVCName(['name' => 'raw name', 'ontologyName' => ['fr' => 'value fr', 'de' => 'value de']], ['en', 'it']), "Returning the raw Vocabulary name when no match (fallback doesn't contain LS languages)."); $this->assertEquals('raw name', Utils::getVCName(['name' => 'raw name'], ['en', 'it']), "Returning the raw Vocabulary name when no Ontology data is present."); }
/** * @{inheritdoc} */ public function getField($fieldName, $languageFallback = array('de', 'fr', 'it', 'rm', 'en')) { // We accept fields using a dot-notation to signify a hierarchy. For // example, technical.previewImage.image is a valid parameter. Explode the // field name on '.', and recursively get the desired key. $hierarchy = explode('.', $fieldName); $fieldValue = $this->rawData; while ($fieldValue && count($hierarchy)) { $part = array_shift($hierarchy); $fieldValue = isset($fieldValue[$part]) ? $fieldValue[$part] : FALSE; } // If the value is not an array, return now. if (!is_array($fieldValue)) { return $fieldValue; } else { // It could be a LangString. In that case, we use the language // fallback. If we didn't find a language key, we simply return the // data as-is. return Utils::getLSValue($fieldValue, $languageFallback); } }
/** * {@inheritdoc} */ public function setTreeBasedOnTaxonPath($paths, $purpose = 'discipline') { // Prepare a new root item. $this->root = $this->termFactory('root', 'root'); if (!is_array($purpose)) { $purpose = array($purpose); } // Prepare a "catalog" of entries, based on their identifiers. This // will allow us to easily convert the linear tree representation // (LOM describes branches only, with a single path; if a node has // multiple sub-branches, their will be multiple paths, and we can // link nodes together via their ID). $terms = array('root' => $this->root); foreach ($paths as $path) { // Cast to an array, just in case. $path = (array) $path; $pathPurpose = $path['purpose']['value']; if (in_array($pathPurpose, $purpose)) { foreach ($path['taxonPath'] as $i => $taxonPath) { // Check if we treat this path. It might be a different // source. if (!in_array(Utils::getLSValue($taxonPath['source']), $this->taxonPathSources)) { continue; } // Prepare the parent. For the first item, it is always the // root element. $parent = $terms['root']; $parentId = 'root'; foreach ($taxonPath['taxon'] as $taxon) { // Cast to an array, just in case. $taxon = (array) $taxon; $taxonId = $taxon['id']; // Do we already have this term prepared? if (isset($terms["{$parentId}:{$taxonId}"])) { $term = $terms["{$parentId}:{$taxonId}"]; } else { // Create the new term. $term = $this->termFactory($this->getTermType($taxonId), $taxonId, $this->getTermName($taxonId)); // Store it. $terms["{$parentId}:{$taxonId}"] = $term; } // Did we already add this term to the parent? if (!$parent->hasChildren() || !in_array($term, $parent->getChildren())) { // Add our term to the tree. $parent->addChild($term); } // Our term is now the parent, in preparation for the // next item. $parent = $term; $parentId .= ":{$taxonId}"; } } } } return $this; }