本文整理汇总了PHP中SMWDataValueFactory类的典型用法代码示例。如果您正苦于以下问题:PHP SMWDataValueFactory类的具体用法?PHP SMWDataValueFactory怎么用?PHP SMWDataValueFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SMWDataValueFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setTypeAndPossibleValues
function setTypeAndPossibleValues()
{
$proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty);
if ($proptitle === null) {
return;
}
$store = smwfGetStore();
// this returns an array of objects
$allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value");
$label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format");
$propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty);
$this->mPropertyType = $propValue->findPropertyTypeID();
foreach ($allowed_values as $allowed_value) {
// HTML-unencode each value
$this->mPossibleValues[] = html_entity_decode($allowed_value);
if (count($label_formats) > 0) {
$label_format = $label_formats[0];
$prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType);
$label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value);
$label_value->setOutputFormat($label_format);
$this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue());
}
}
// HACK - if there were any possible values, set the property
// type to be 'enumeration', regardless of what the actual type is
if (count($this->mPossibleValues) > 0) {
$this->mPropertyType = 'enumeration';
}
}
示例2: getIncomingProperties
/**
* Gets the set of all properties that point to this page, anywhere
* in the wiki.
*/
static function getIncomingProperties($title)
{
$store = smwfGetStore();
// SMW 1.6+
if (class_exists('SMWDataItem')) {
$value = SMWDIWikiPage::newFromTitle($title);
} else {
$title_text = SFUtils::titleString($title);
$value = SMWDataValueFactory::newTypeIDValue('_wpg', $title_text);
}
$properties = $store->getInProperties($value);
$propertyNames = array();
foreach ($properties as $property) {
// SMW 1.6+
if ($property instanceof SMWDIProperty) {
$property_name = $property->getKey();
} else {
$property_name = $property->getWikiValue();
}
if (!empty($property_name)) {
$propertyNames[] = $property_name;
}
}
return $propertyNames;
}
示例3: getTypeProperties
protected function getTypeProperties($typeLabel)
{
global $wgRequest, $smwgTypePagingLimit;
if ($smwgTypePagingLimit <= 0) {
return '';
}
// not too useful, but we comply to this request
$from = $wgRequest->getVal('from');
$until = $wgRequest->getVal('until');
$typeValue = SMWDataValueFactory::newTypeIDValue('__typ', $typeLabel);
$store = smwfGetStore();
$options = SMWPageLister::getRequestOptions($smwgTypePagingLimit, $from, $until);
$diWikiPages = $store->getPropertySubjects(new SMWDIProperty('_TYPE'), $typeValue->getDataItem(), $options);
if (!$options->ascending) {
$diWikiPages = array_reverse($diWikiPages);
}
$result = '';
if (count($diWikiPages) > 0) {
$pageLister = new SMWPageLister($diWikiPages, null, $smwgTypePagingLimit, $from, $until);
$title = $this->getTitleFor('Types', $typeLabel);
$title->setFragment('#SMWResults');
// Make navigation point to the result list.
$navigation = $pageLister->getNavigationLinks($title);
$resultNumber = min($smwgTypePagingLimit, count($diWikiPages));
$typeName = $typeValue->getLongWikiText();
$result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMsg('smw_type_header', $typeName) . "</h2>\n<p>" . wfMsgExt('smw_typearticlecount', array('parsemag'), $resultNumber) . "</p>\n" . $navigation . $pageLister->formatList() . $navigation . "\n</div>";
}
return $result;
}
示例4: newFromSerialization
/**
* Creates and returns a new SWLPropertyChange instance from a serialization.
*
* @param string|null $oldValue
* @param string|null $newValue
*
* @return SWLPropertyChange
*/
public static function newFromSerialization(SMWDIProperty $property, $oldValue, $newValue)
{
$diType = SMWDataValueFactory::getDataItemId($property->findPropertyTypeID());
//var_dump($property);
//if($diType!=7) {throw new Exception();exit;}
return new self(is_null($oldValue) ? null : SMWDataItem::newFromSerialization($diType, $oldValue), is_null($newValue) ? null : SMWDataItem::newFromSerialization($diType, $newValue));
}
示例5: getPropertyValues
/**
* Get the array of all stored values for some property.
*
* @param $property SMWDIProperty
* @return array of SMWDataItem
*/
public function getPropertyValues(SMWDIProperty $property)
{
if ($property->isInverse()) {
// we never have any data for inverses
return array();
}
if (array_key_exists($property->getKey(), $this->mStubPropVals)) {
$this->unstubProperty($property->getKey(), $property);
$propertyTypeId = $property->findPropertyTypeID();
$propertyDiId = SMWDataValueFactory::getDataItemId($propertyTypeId);
foreach ($this->mStubPropVals[$property->getKey()] as $dbkeys) {
try {
if ($propertyDiId == SMWDataItem::TYPE_CONTAINER) {
$diSubWikiPage = SMWCompatibilityHelpers::dataItemFromDBKeys('_wpg', $dbkeys);
$semanticData = new SMWContainerSemanticData($diSubWikiPage);
$semanticData->copyDataFrom(smwfGetStore()->getSemanticData($diSubWikiPage));
$di = new SMWDIContainer($semanticData);
} else {
$di = SMWCompatibilityHelpers::dataItemFromDBKeys($propertyTypeId, $dbkeys);
}
if ($this->mNoDuplicates) {
$this->mPropVals[$property->getKey()][$di->getHash()] = $di;
} else {
$this->mPropVals[$property->getKey()][] = $di;
}
} catch (SMWDataItemException $e) {
// ignore data
}
}
unset($this->mStubPropVals[$property->getKey()]);
}
return parent::getPropertyValues($property);
}
示例6: getQueryString
/**
* @see SMWDescription:getQueryString
*
* @since 0.6
*
* @param Boolean $asValue
*/
public function getQueryString( $asValue = false ) {
if ( $this->getDataItem() !== null ) {
$queryString = SMWDataValueFactory::newDataItemValue( $this->getDataItem(), $this->m_property )->getWikiValue();
return $asValue ? $queryString : "[[$queryString]]";
} else {
return $asValue ? '+' : '';
}
}
示例7: newFromSerialization
/**
* Creates and returns a new SWLPropertyChange instance from a serialization.
*
* @param string|null $oldValue
* @param string|null $newValue
*
* @return SWLPropertyChange
*/
public static function newFromSerialization( SMWDIProperty $property, $oldValue, $newValue ) {
$diType = SMWDataValueFactory::getDataItemId( $property->findPropertyTypeID() );
return new self(
is_null( $oldValue ) ? null : SMWDataItem::newFromSerialization( $diType, $oldValue ),
is_null( $newValue ) ? null : SMWDataItem::newFromSerialization( $diType, $newValue )
);
}
示例8: formatResult
/**
* @param $skin
* @param array $result First item is SMWDIProperty, second item is int
*
* @return string
*/
function formatResult($skin, $result)
{
$linker = smwfGetLinker();
if ($result[0]->isUserDefined()) {
$proplink = $linker->makeLinkObj($result[0]->getDiWikiPage()->getTitle(), htmlspecialchars($result[0]->getLabel()), 'action=view');
} else {
$proplink = SMWDataValueFactory::newDataItemValue($result[0], new SMWDIProperty('_TYPE'))->getLongHTMLText($linker);
}
return wfMsgExt('smw_wantedproperty_template', array('parsemag'), $proplink, $result[1]);
}
示例9: addPropertyAndValue
public function addPropertyAndValue( $propName, $value ) {
// SMW 1.6+
if ( class_exists( 'SMWDIProperty' ) ) {
$property = SMWDIProperty::newFromUserLabel( $propName );
} else {
$property = SMWPropertyValue::makeUserProperty( $propName );
}
$dataValue = SMWDataValueFactory::newPropertyObjectValue( $property, $value );
if ( $dataValue->isValid() ) {
$this->mPropertyValuePairs[] = array( $property, $dataValue );
} // else - show an error message?
}
示例10: addPropertyDiValueToSemanticData
protected static function addPropertyDiValueToSemanticData($propertyDi, $valueString, $semanticData)
{
if (!$propertyDi->isInverse()) {
$valueDv = SMWDataValueFactory::newPropertyObjectValue($propertyDi, $valueString, false, $semanticData->getSubject());
$semanticData->addPropertyObjectValue($propertyDi, $valueDv->getDataItem());
// Take note of the error for storage (do this here and not in storage, thus avoiding duplicates).
if (!$valueDv->isValid()) {
$semanticData->addPropertyObjectValue(new SMWDIProperty('_ERRP'), $propertyDi->getDiWikiPage());
self::$m_errors = array_merge(self::$m_errors, $valueDv->getErrors());
}
} else {
self::$m_errors[] = wfMessage('smw_noinvannot')->inContentLanguage()->text();
}
}
示例11: formatResult
function formatResult($skin, $result)
{
$linker = smwfGetLinker();
$proplink = $linker->link($result->getDiWikiPage()->getTitle(), $result->getLabel());
$types = smwfGetStore()->getPropertyValues($result->getDiWikiPage(), new SMWDIProperty('_TYPE'));
$errors = array();
if (count($types) >= 1) {
$typestring = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE'))->getLongHTMLText($linker);
} else {
$type = SMWTypesValue::newFromTypeId('_wpg');
$typestring = $type->getLongHTMLText($linker);
$errors[] = wfMsg('smw_propertylackstype', $type->getLongHTMLText());
}
return wfMsg('smw_unusedproperty_template', $proplink, $typestring) . ' ' . smwfEncodeMessages($errors);
}
示例12: writeOrDeleteDataToWiki
/**
* Write (or delte, if $delete is set to true) the data in the object
* variables, to the wiki page corresponding to this page handler
* @param boolean $delete
*/
public function writeOrDeleteDataToWiki( $delete = false ) {
if ( $delete ) {
if ( $this->checkWikiPageExists() ) {
$this->initSMWWriter( $delete = true );
} else {
return;
}
} else {
$this->ensureWikiPageExists();
$this->initSMWWriter();
}
$properties = $this->m_properties;
foreach ( $properties as $cur_prop ) {
$propertystring = $cur_prop['p'];
// TODO: Remove old code:
// $property = SMWPropertyValue::makeUserProperty( $propertystring );
$property_di = SMWDIProperty::newFromUserLabel($propertystring);
$valuestring = RDFIOUtils::sanitizeSMWValue( $cur_prop['v'] );
$value = SMWDataValueFactory::newPropertyObjectValue( $property_di, $valuestring );
$propertyErrorText = $property->getErrorText();
$propertyHasError = ( $propertyErrorText != '' );
if ( $propertyHasError ) {
$this->addError( "<p>In RDFIOPageHandler::writeOrDeleteDataToWiki(): " . $property->getErrorText() . "</p>" );
}
$valueErrorText = $value->getErrorText();
$valueHasError = ( $valueErrorText != '' );
if ( $valueHasError ) {
$this->addError( "<p>Error creating property value object in RDFIOPageHandler::writeOrDeleteDataToWiki():</p><p>" . $value->getErrorText() . "</p>" );
}
if ( $delete ) {
$this->m_smwwriter_remove->addPropertyObjectValue( $property, $value );
$editmessage = "Deleting properties. Last property delete: " . $propertystring . " : " . $valuestring;
} else {
$this->m_smwwriter_add->addPropertyObjectValue( $property, $value );
$editmessage = "Importing properties. Last property added: " . $propertystring . " : " . $valuestring;
}
}
$this->m_smwwriter->update( $this->m_smwwriter_remove, $this->m_smwwriter_add, $editmessage );
$smwWriterError = $this->m_smwwriter->getError();
$smwWriterHasError = ( $smwWriterError != '' );
if ( $smwWriterHasError ) {
$this->addError( "<p>SMWWriter Error: " . $smwWriterError . "</p>" );
}
}
示例13: storeQueryMetadata
public function storeQueryMetadata($title, $query)
{
global $wgParser;
// initialize a new semdata object and append it to parser output if this was not yet done.
// the semdata object will then be stored to the db by smw at the end of the parse process
if (!isset($wgParser->getOutput()->mSMWData)) {
$wgParser->getOutput()->mSMWData = new SMWSemanticData(SMWWikiPageValue::makePageFromTitle($title));
}
$semanticData = $wgParser->getOutput()->mSMWData;
$propertyValue = SMWPropertyValue::makeProperty('___QRC_UQC');
$dataValue = SMWDataValueFactory::newTypeIDValue('_qcm');
$dataValue->setQueryId($this->getQueryId($query));
$dataValue->setQueryString($query->getQueryString());
if ($query->getLimit()) {
$dataValue->setQueryLimit($query->getLimit());
}
if ($query->getOffset()) {
$dataValue->setQueryOffset($query->getOffset());
}
if ($query instanceof SMWSPARQLQuery) {
$prProperties = $this->getPrintRequestsProperties($query->getExtraPrintouts());
$dataValue->setExtraPropertyPrintouts(implode(';', array_keys($prProperties)));
$dataValue->setExtraCategoryPrintouts($this->isCategoryRequestedInPrintRequests($query->getExtraPrintouts()));
$dataValue->setIsSPQRQLQuery(true);
} else {
$dataValue->setIsSPQRQLQuery(false);
}
$properties = array();
$categories = array();
if ($query instanceof SMWSPARQLQuery) {
list($properties, $categories) = $this->getSPARQLQueryParts($query);
} else {
if ($query instanceof SMWQuery) {
list($properties, $categories) = $this->getQueryParts($query->getDescription());
}
}
foreach ($properties as $p => $dontCare) {
$dataValue->addPropertyDependency($p);
}
foreach ($categories as $c => $dontCare) {
$dataValue->addCategoryDependency($c);
}
$semanticData->addPropertyObjectValue($propertyValue, $dataValue);
$wgParser->getOutput()->mSMWData = $semanticData;
}
示例14: getResultText
/**
* (non-PHPdoc)
* @see SMWResultPrinter::getResultText()
*/
protected function getResultText(SMWQueryResult $res, $outputmode)
{
$dataItems = $this->getSortKeys($res);
if (empty($dataItems)) {
return $this->params['default'];
}
$sortKeys = array_keys($dataItems);
switch ($this->mFormat) {
case 'latest':
$result = max($sortKeys);
break;
case 'earliest':
$result = min($sortKeys);
break;
}
$dataValue = SMWDataValueFactory::newDataItemValue($dataItems[$result], null);
return $dataValue->getLongHTMLText();
}
示例15: smwfGetStore
/**
*
* Load all semantic properties of a page as a hash
* @param String $pagename
* @param Integer $namespace
* @param Boolean $normalizeTitle
* @return an associative array with the property name as key and property value as value.
*/
public static function &loadSemanticProperties($pagename, $namespace = NS_MAIN, $normalizeTitle = true)
{
//-----normalize title
$data = null;
if ($normalizeTitle) {
$title = MWUtil::normalizePageTitle($pagename, false);
$di = SMWDIWikiPage::newFromTitle($title);
$data = smwfGetStore()->getSemanticData($di);
} else {
$di = new SMWDIWikiPage($pagename, $namespace, '');
$data = smwfGetStore()->getSemanticData($di);
}
$valuehash = array();
$diProperties = $data->getProperties();
foreach ($diProperties as $diProperty) {
$dvProperty = SMWDataValueFactory::newDataItemValue($diProperty, null);
$name = null;
if ($dvProperty->isVisible()) {
$name = $diProperty->getLabel();
} elseif ($diProperty->getKey() == '_INST') {
$name = 'Categories';
} else {
continue;
// skip this line
}
if (!$name) {
continue;
}
$values = $data->getPropertyValues($diProperty);
$vs = array();
foreach ($values as $di) {
$dv = SMWDataValueFactory::newDataItemValue($di, $diProperty);
$vs[] = $dv->getWikiValue();
}
if (count($vs) == 1) {
$valuehash[$name] = $vs[0];
} else {
$valuehash[$name] = $vs;
}
}
#error_log(print_r($valuehash, true));
return $valuehash;
}