本文整理汇总了PHP中SMWDataValueFactory::newDataItemValue方法的典型用法代码示例。如果您正苦于以下问题:PHP SMWDataValueFactory::newDataItemValue方法的具体用法?PHP SMWDataValueFactory::newDataItemValue怎么用?PHP SMWDataValueFactory::newDataItemValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMWDataValueFactory
的用法示例。
在下文中一共展示了SMWDataValueFactory::newDataItemValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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 ? '+' : '';
}
}
示例2: 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]);
}
示例3: 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);
}
示例4: 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();
}
示例5: 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;
}
示例6: getPropertyHTML
/**
* Creates and returns the HTML representatation of the property and it's changes.
*
* @since 0.1
*
* @param SMWDIProperty $property
* @param array $changes
*
* @return string
*/
protected static function getPropertyHTML(SMWDIProperty $property, array $changes)
{
$insertions = array();
$deletions = array();
// Convert the changes into a list of insertions and a list of deletions.
foreach ($changes as $change) {
if (!is_null($change->getOldValue())) {
$deletions[] = SMWDataValueFactory::newDataItemValue($change->getOldValue(), $property)->getShortHTMLText();
}
if (!is_null($change->getNewValue())) {
$insertions[] = SMWDataValueFactory::newDataItemValue($change->getNewValue(), $property)->getShortHTMLText();
}
}
$lines = array();
if (count($insertions) > 0) {
$lines[] = Html::element('span', array(), wfMsg('swl-watchlist-insertions')) . ' ' . implode(', ', $insertions);
}
if (count($deletions) > 0) {
$lines[] = Html::element('span', array(), wfMsg('swl-watchlist-deletions')) . ' ' . implode(', ', $deletions);
}
$html = Html::element('b', array(), $property->getLabel());
$html .= Html::rawElement('div', array('class' => 'swl-prop-div'), implode('<br />', $lines));
return $html;
}
示例7: getResourceElementForWikiPage
/**
* Create an SMWExpElement for some internal resource, given by an
* SMWDIWikiPage object. This is the one place in the code where URIs
* of wiki pages and user-defined properties are determined. A modifier
* can be given to make variants of a URI, typically done for
* auxiliary properties. In this case, the URI is modiied by appending
* "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
* occuring in MW titles).
*
* @param $diWikiPage SMWDIWikiPage or SMWDIProperty
* @param $modifier string, using only Latin letters and numbers
* @return SMWExpResource
*/
public static function getResourceElementForWikiPage(SMWDIWikiPage $diWikiPage, $modifier = '')
{
global $wgContLang;
if ($diWikiPage->getNamespace() == NS_MEDIA) {
// special handling for linking media files directly (object only)
$title = Title::makeTitle($diWikiPage->getNamespace(), $diWikiPage->getDBkey());
$file = wfFindFile($title);
if ($file !== false) {
return new SMWExpResource($file->getFullURL());
}
// else: Medialink to non-existing file :-/ fall through
}
if ($diWikiPage->getSubobjectName() !== '') {
$modifier = $diWikiPage->getSubobjectName();
}
if ($modifier === '') {
$importProperty = new SMWDIProperty('_IMPO');
$importDis = smwfGetStore()->getPropertyValues($diWikiPage, $importProperty);
$importURI = count($importDis) > 0;
} else {
$importURI = false;
}
if ($importURI) {
$importValue = SMWDataValueFactory::newDataItemValue(current($importDis), $importProperty);
$namespace = $importValue->getNS();
$namespaceId = $importValue->getNSID();
$localName = $importValue->getLocalName();
} else {
$localName = '';
if ($diWikiPage->getNamespace() == SMW_NS_PROPERTY) {
$namespace = self::getNamespaceUri('property');
$namespaceId = 'property';
$localName = self::encodeURI(rawurlencode($diWikiPage->getDBkey()));
}
if ($localName === '' || in_array($localName[0], array('-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) {
$namespace = self::getNamespaceUri('wiki');
$namespaceId = 'wiki';
if ($diWikiPage->getNamespace() !== 0) {
$localName = str_replace(' ', '_', $wgContLang->getNSText($diWikiPage->getNamespace())) . ':' . $diWikiPage->getDBkey();
} else {
$localName = $diWikiPage->getDBkey();
}
$localName = self::encodeURI(wfUrlencode($localName));
}
if ($modifier !== '') {
$localName .= '-23' . $modifier;
}
}
return new SMWExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
}
示例8: loadContent
/**
* Load results of the given print request and result subject. This is only
* done when needed.
*/
protected function loadContent()
{
if ($this->mContent !== false) {
return;
}
wfProfileIn('SMWQueryResult::loadContent (SMW)');
switch ($this->mPrintRequest->getMode()) {
case SMWPrintRequest::PRINT_THIS:
// NOTE: The limit is ignored here.
$this->mContent = array($this->mResult);
break;
case SMWPrintRequest::PRINT_CATS:
// Always recompute cache here to ensure output format is respected.
self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'), $this->getRequestOptions(false));
self::$catCacheObj = $this->mResult->getHash();
$limit = $this->mPrintRequest->getParameter('limit');
$this->mContent = $limit === false ? self::$catCache : array_slice(self::$catCache, 0, $limit);
break;
case SMWPrintRequest::PRINT_PROP:
$propertyValue = $this->mPrintRequest->getData();
if ($propertyValue->isValid()) {
$this->mContent = $this->mStore->getPropertyValues($this->mResult, $propertyValue->getDataItem(), $this->getRequestOptions());
} else {
$this->mContent = array();
}
// Print one component of a multi-valued string.
// Known limitation: the printrequest still is of type _rec, so if printers check
// for this then they will not recognize that it returns some more concrete type.
if ($this->mPrintRequest->getTypeID() == '_rec' && $this->mPrintRequest->getParameter('index') !== false) {
$pos = $this->mPrintRequest->getParameter('index') - 1;
$newcontent = array();
foreach ($this->mContent as $diContainer) {
/* SMWRecordValue */
$recordValue = SMWDataValueFactory::newDataItemValue($diContainer, $propertyValue->getDataItem());
$dataItems = $recordValue->getDataItems();
if (array_key_exists($pos, $dataItems) && !is_null($dataItems[$pos])) {
$newcontent[] = $dataItems[$pos];
}
}
$this->mContent = $newcontent;
}
break;
case SMWPrintRequest::PRINT_CCAT:
///NOTE: The limit is ignored here.
if (self::$catCacheObj != $this->mResult->getHash()) {
self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'));
self::$catCacheObj = $this->mResult->getHash();
}
$found = false;
$prkey = $this->mPrintRequest->getData()->getDBkey();
foreach (self::$catCache as $cat) {
if ($cat->getDBkey() == $prkey) {
$found = true;
break;
}
}
$this->mContent = array(new SMWDIBoolean($found));
break;
default:
$this->mContent = array();
// Unknown print request.
}
reset($this->mContent);
wfProfileOut('SMWQueryResult::loadContent (SMW)');
}
示例9: getExactResults
/**
* Returns all results that have exactly the value on the property.
*
* @return array of array of SMWWikiPageValue, SMWDataValue with the first being the entity, and the second the value
*/
private function getExactResults()
{
$options = new SMWRequestOptions();
$options->limit = $this->limit + 1;
$options->offset = $this->offset;
$options->sort = true;
$res = smwfGetStore()->getPropertySubjects($this->property->getDataItem(), $this->value->getDataItem(), $options);
$results = array();
foreach ($res as $result) {
array_push($results, array(SMWDataValueFactory::newDataItemValue($result, null), $this->value));
}
return $results;
}
示例10: formatPropertyItem
/**
* Produce a formatted string representation for showing a property in
* the list of unused properties.
*
* @since 1.8
*
* @param SMWDIProperty $property
* @return string
*/
protected function formatPropertyItem(SMWDIProperty $property)
{
$linker = smwfGetLinker();
$errors = array();
if ($property->isUserDefined()) {
$proplink = $linker->link($property->getDiWikiPage()->getTitle(), $property->getLabel());
$types = smwfGetStore()->getPropertyValues($property->getDiWikiPage(), new SMWDIProperty('_TYPE'));
if (count($types) >= 1) {
$typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE'));
} else {
$typeDataValue = SMWTypesValue::newFromTypeId('_wpg');
$errors[] = wfMessage('smw_propertylackstype', $typeDataValue->getLongHTMLText())->text();
}
$typeString = $typeDataValue->getLongHTMLText($linker);
} else {
$typeid = $property->findPropertyTypeID();
$typeDataValue = SMWTypesValue::newFromTypeId($typeid);
$typeString = $typeDataValue->getLongHTMLText($linker);
$propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null);
$proplink = $propertyDataValue->getShortHtmlText($linker);
}
return wfMessage('smw_unusedproperty_template', $proplink, $typeString)->text() . ' ' . smwfEncodeMessages($errors);
}
示例11: getWikiPageValue
/**
* Return a wiki page value that can be used for displaying this
* property, or null if no such wiki page exists (for predefined
* properties without any label).
* @return SMWWikiPageValue or null
*/
public function getWikiPageValue()
{
if (!isset($this->m_wikipage)) {
$diWikiPage = $this->m_dataitem->getDiWikiPage();
if (!is_null($diWikiPage)) {
$this->m_wikipage = SMWDataValueFactory::newDataItemValue($diWikiPage, null, $this->m_caption);
$this->m_wikipage->setOutputFormat($this->m_outformat);
$this->addError($this->m_wikipage->getErrors());
} else {
// should rarely happen ($value is only changed if the input $value really was a label for a predefined prop)
$this->m_wikipage = null;
}
}
return $this->m_wikipage;
}
示例12: makeOutputText
protected function makeOutputText($type = 0, $linker = null)
{
if (!$this->isValid()) {
return $type == 0 || $type == 1 ? '' : $this->getErrorText();
}
$result = '';
$i = 0;
foreach ($this->getPropertyDataItems() as $propertyDataItem) {
if ($i == 1) {
$result .= $type == 4 ? '; ' : ' (';
} elseif ($i > 1) {
$result .= $type == 4 ? '; ' : ', ';
}
++$i;
$propertyValues = $this->m_dataitem->getSemanticData()->getPropertyValues($propertyDataItem);
// combining this with next line violates PHP strict standards
$dataItem = reset($propertyValues);
if ($dataItem !== false) {
$dataValue = SMWDataValueFactory::newDataItemValue($dataItem, $propertyDataItem);
$result .= $this->makeValueOutputText($type, $dataValue, $linker);
} else {
$result .= '?';
}
}
if ($i > 1 && $type != 4) {
$result .= ')';
}
return $result;
}
示例13: getIcalForItem
/**
* Returns the iCal for a single item.
*
* @since 1.5.2
*
* @param array $row
*
* @return string
*/
protected function getIcalForItem(array $row)
{
$result = '';
$wikipage = $row[0]->getResultSubject();
// get the object
$wikipage = SMWDataValueFactory::newDataItemValue($wikipage, null);
$params = array('summary' => $wikipage->getShortWikiText());
foreach ($row as $field) {
// later we may add more things like a generic
// mechanism to add whatever you want :)
// could include funny things like geo, description etc. though
$req = $field->getPrintRequest();
$label = strtolower($req->getLabel());
switch ($label) {
case 'start':
case 'end':
if ($req->getTypeID() == '_dat') {
$dataValue = $field->getNextDataValue();
if ($dataValue === false) {
unset($params[$label]);
} else {
$params[$label] = $dataValue;
}
}
break;
case 'location':
case 'description':
case 'summary':
$value = $field->getNextDataValue();
if ($value !== false) {
$params[$label] = $value->getShortWikiText();
}
break;
}
}
$title = $wikipage->getTitle();
$article = new Article($title);
$url = $title->getFullURL();
$result .= "BEGIN:VEVENT\r\n";
$result .= "SUMMARY:" . $params['summary'] . "\r\n";
$result .= "URL:{$url}\r\n";
$result .= "UID:{$url}\r\n";
if (array_key_exists('start', $params)) {
$result .= "DTSTART:" . $this->parsedate($params['start']) . "\r\n";
}
if (array_key_exists('end', $params)) {
$result .= "DTEND:" . $this->parsedate($params['end'], true) . "\r\n";
}
if (array_key_exists('location', $params)) {
$result .= "LOCATION:" . $params['location'] . "\r\n";
}
if (array_key_exists('description', $params)) {
$result .= "DESCRIPTION:" . $params['description'] . "\r\n";
}
$t = strtotime(str_replace('T', ' ', $article->getTimestamp()));
$result .= "DTSTAMP:" . date("Ymd", $t) . "T" . date("His", $t) . "\r\n";
$result .= "SEQUENCE:" . $title->getLatestRevID() . "\r\n";
$result .= "END:VEVENT\r\n";
return $result;
}
示例14: getShortList
/**
* Format a list of diWikiPages chunked by letter in a bullet list.
*
* @param $start integer
* @param $end integer
* @param $diWikiPages array of SMWDataItem
* @param $diProperty SMWDIProperty that the wikipages are values of, or null
*
* @return string
*/
public static function getShortList($start, $end, array $diWikiPages, $diProperty)
{
global $wgContLang;
$startDv = SMWDataValueFactory::newDataItemValue($diWikiPages[$start], $diProperty);
$sortkey = smwfGetStore()->getWikiPageSortKey($diWikiPages[$start]);
$startChar = $wgContLang->convert($wgContLang->firstChar($sortkey));
$r = '<h3>' . htmlspecialchars($startChar) . "</h3>\n" . '<ul><li>' . $startDv->getLongHTMLText(smwfGetLinker()) . '</li>';
$prevStartChar = $startChar;
for ($index = $start + 1; $index < $end; $index++) {
$dataValue = SMWDataValueFactory::newDataItemValue($diWikiPages[$index], $diProperty);
$sortkey = smwfGetStore()->getWikiPageSortKey($diWikiPages[$index]);
$startChar = $wgContLang->convert($wgContLang->firstChar($sortkey));
if ($startChar != $prevStartChar) {
$r .= "</ul><h3>" . htmlspecialchars($startChar) . "</h3>\n<ul>";
$prevStartChar = $startChar;
}
$r .= '<li>' . $dataValue->getLongHTMLText(smwfGetLinker()) . '</li>';
}
$r .= '</ul>';
return $r;
}
示例15: getResultText
protected function getResultText(SMWQueryResult $res, $outputmode)
{
/*
* @todo
* labels of requested properties could define default values. Seems not possible at the moment because
* SMWPrintRequest::getLable() always returns the property name even if no specific label is defined.
*/
$perPage_items = array();
//for each page:
while ($row = $res->getNext()) {
$perProperty_items = array();
/**
* first field is always the page title, except, mainlabel is set to '-'
* @todo Is there some other way to check the data value directly for being the
* page title or not? SMWs behavior could change on mainlabel handling...
*/
$isPageTitle = !$this->mMainLabelHack;
//for each property on that page:
foreach ($row as $field) {
// $row is array(), $field of type SMWResultArray
$manyValue_items = array();
$isMissingProperty = false;
$manyValues = $field->getContent();
//If property is not set (has no value) on a page:
if (empty($manyValues)) {
$delivery = $this->deliverMissingProperty($field);
$manyValue_items = $this->fillDeliveryArray($manyValue_items, $delivery);
$isMissingProperty = true;
} else {
//otherwise collect property value (potentially many values):
while ($obj = $field->getNextDataValue()) {
$value_items = array();
$isRecord = false;
// handle page Title:
if ($isPageTitle) {
if (!$this->mShowPageTitles) {
$isPageTitle = false;
continue 2;
//next property
}
$value_items = $this->fillDeliveryArray($value_items, $this->deliverPageTitle($obj, $this->mLinkFirst));
} elseif ($obj instanceof SMWRecordValue) {
$recordItems = $obj->getDataItems();
// walk all single values of the record set:
foreach ($recordItems as $dataItem) {
$recordField = $dataItem !== null ? SMWDataValueFactory::newDataItemValue($dataItem, null) : null;
$value_items = $this->fillDeliveryArray($value_items, $this->deliverRecordField($recordField, $this->mLinkOthers));
}
$isRecord = true;
} else {
$value_items = $this->fillDeliveryArray($value_items, $this->deliverSingleValue($obj, $this->mLinkOthers));
}
$delivery = $this->deliverSingleManyValuesData($value_items, $isRecord, $isPageTitle);
$manyValue_items = $this->fillDeliveryArray($manyValue_items, $delivery);
}
}
// foreach...
$delivery = $this->deliverPropertiesManyValues($manyValue_items, $isMissingProperty, $isPageTitle, $field);
$perProperty_items = $this->fillDeliveryArray($perProperty_items, $delivery);
$isPageTitle = false;
// next one could be record or normal value
}
// foreach...
$delivery = $this->deliverPageProperties($perProperty_items);
$perPage_items = $this->fillDeliveryArray($perPage_items, $delivery);
}
// while...
$output = $this->deliverQueryResultPages($perPage_items);
return $output;
}