Semantic MediaWiki and related extensions
Match distinct numeric property value
{{#ask: [[NumericProperty::1111]]
|?NumericProperty
}}
// Create property instance
$property = new DIProperty( 'NumericProperty' );
$property->setPropertyTypeId( '_num' );
$dataItem = new DINumber( 1111 );
$dataValue = DataValueFactory::getInstance()->newDataValueByItem(
$dataItem,
$property
);
// Create and store the SemanticData object in order to be able to match a value
$subject = new DIWikiPage( 'Foo', NS_MAIN )
$semanticData = new SemanticData( $subject );
$semanticData->addDataValue(
$dataValue
);
ApplicationFactory::getInstance()->getStore()->updateData(
$semanticData
);
// Create a description that represents the condition
$descriptionFactory = new DescriptionFactory();
$description = $descriptionFactory->newSomeProperty(
$property,
$descriptionFactory->newValueDescription( $dataItem )
);
$propertyValue = DataValueFactory::getInstance()->newPropertyValueByLabel(
'NumericProperty'
);
$description->addPrintRequest(
new PrintRequest( PrintRequest::PRINT_PROP, null, $propertyValue )
);
// Create query object
$query = new Query(
$description
);
$query->querymode = Query::MODE_INSTANCES;
// Try to match condition against the store
$queryResult = ApplicationFactory::getInstance()->getStore()->getQueryResult( $query );
// PHPUnit
$this->assertEquals(
1,
$queryResult->getCount()
);

About | General disclaimer | Privacy policy