/** * @since 2.4 * * @param DIProperty $property */ public function fetchConversionData(DIProperty $property) { $this->unitIds = array(); $this->unitFactors = array(); $this->mainUnit = false; $this->prefixalUnitPreference = array(); $this->errors = array(); $factors = $this->cachedPropertyValuesPrefetcher->getPropertyValues($property->getDiWikiPage(), new DIProperty('_CONV')); $this->numberValue->setContextPage($property->getDiWikiPage()); if ($factors === null || $factors === array()) { // no custom type return $this->errors[] = 'smw_nounitsdeclared'; } $number = ''; $unit = ''; foreach ($factors as $di) { // ignore corrupted data and bogus inputs if (!$di instanceof DIBlob || $this->numberValue->parseNumberValue($di->getString(), $number, $unit, $asPrefix) != 0 || $number == 0) { continue; } $this->matchUnitAliases($number, $asPrefix, preg_split('/\\s*,\\s*/u', $unit)); } // No unit with factor 1? Make empty string the main unit. if ($this->mainUnit === false) { $this->mainUnit = ''; } // Always add an extra empty unit; not as a synonym for the main unit // but as a new unit with ID '' so if users do not give any unit, the // conversion tooltip will still display the main unit for clarity // (the empty unit is never displayed; we filter it when making // conversion values) $this->unitFactors = array('' => 1) + $this->unitFactors; $this->unitIds[''] = ''; }
public function testGetPropertyValuesFromCache() { $container = $this->getMockBuilder('\\Onoi\\BlobStore\\Container')->disableOriginalConstructor()->getMock(); $container->expects($this->atLeastOnce())->method('has')->will($this->returnValue(true)); $container->expects($this->once())->method('get')->with($this->stringContains('Bar:123'))->will($this->returnValue(1001)); $this->blobStore->expects($this->atLeastOnce())->method('read')->will($this->returnValue($container)); $instance = new CachedPropertyValuesPrefetcher($this->store, $this->blobStore); $this->assertEquals(1001, $instance->getPropertyValues(DIWikiPage::newFromText('Foo#123'), new DIProperty('Bar'))); }
private function findPreferredPropertyLabel($property, $languageCode) { $text = ''; $preferredProperty = new DIProperty('_PPLB'); $dataItems = $this->cachedPropertyValuesPrefetcher->getPropertyValues($property->getCanonicalDiWikiPage(), $preferredProperty); if (($dataValue = $this->findTextValueByLanguage($dataItems, $preferredProperty, $languageCode)) !== null) { $text = $dataValue->getShortWikiText(); } return $text; }