public function testGetType() { $valueType = 'test-value_type'; $serviceLocator = $this->getServiceManager(); $value = $this->getMock('Omeka\\Entity\\Value'); $value->expects($this->once())->method('getType')->will($this->returnValue($valueType)); $valueRep = new ValueRepresentation($value, $serviceLocator); $this->assertEquals($valueType, $valueRep->type()); }
/** * Get all value representations of this resource. * * <code> * array( * {term} => array( * 'property' => {PropertyRepresentation}, * 'alternate_label' => {label}, * 'alternate_comment' => {comment}, * 'values' => array( * {ValueRepresentation}, * {ValueRepresentation}, * ), * ), * ) * </code> * * @return array */ public function values() { if (isset($this->values)) { return $this->values; } // Set the default template info. $templateInfo = ['dcterms:title' => [], 'dcterms:description' => []]; $template = $this->resourceTemplate(); if ($template) { // Set the custom template info. $templateInfo = []; foreach ($template->resourceTemplateProperties() as $templateProperty) { $term = $templateProperty->property()->term(); $templateInfo[$term] = ['alternate_label' => $templateProperty->alternateLabel(), 'alternate_comment' => $templateProperty->alternateComment()]; } } // Get this resource's values. $values = []; foreach ($this->resource->getValues() as $valueEntity) { $value = new ValueRepresentation($valueEntity, $this->getServiceLocator()); if ('resource' === $value->type() && null === $value->valueResource()) { // Skip this resource value if the resource is not available // (most likely becuase it is private). continue; } $term = $value->property()->term(); if (!isset($values[$term]['property'])) { $values[$term]['property'] = $value->property(); $values[$term]['alternate_label'] = null; $values[$term]['alternate_comment'] = null; } $values[$term]['values'][] = $value; } // Order this resource's values according to the template order. $sortedValues = []; foreach ($values as $term => $valueInfo) { foreach ($templateInfo as $templateTerm => $templateAlternates) { if (array_key_exists($templateTerm, $values)) { $sortedValues[$templateTerm] = array_merge($values[$templateTerm], $templateAlternates); } } } $this->values = $sortedValues + $values; return $this->values; }