本文整理汇总了PHP中SMW\SemanticData::getProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP SemanticData::getProperties方法的具体用法?PHP SemanticData::getProperties怎么用?PHP SemanticData::getProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SMW\SemanticData
的用法示例。
在下文中一共展示了SemanticData::getProperties方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddAnnotationOnMockShortUrl
public function testAddAnnotationOnMockShortUrl()
{
$title = Title::newFromText(__METHOD__);
$semanticData = new SemanticData(DIWikiPage::newFromTitle($title));
$instance = $this->getMock('\\SESP\\Annotator\\ShortUrlAnnotator', array('hasShortUrlUtils', 'getShortUrl'), array($semanticData));
$instance->expects($this->once())->method('hasShortUrlUtils')->will($this->returnValue(true));
$instance->expects($this->once())->method('getShortUrl')->with($this->equalTo($title))->will($this->returnValue('example.org'));
$instance->setShortUrlPrefix('foo');
$instance->addAnnotation();
$this->assertArrayHasKey(PropertyRegistry::getInstance()->getPropertyId('_SHORTURL'), $semanticData->getProperties());
}
示例2: createFromSemanticData
/**
* @since 2.4
*
* @param SemanticData $semanticData
*
* @return string
*/
public static function createFromSemanticData(SemanticData $semanticData)
{
$hash = array();
$hash[] = $semanticData->getSubject()->getSerialization();
foreach ($semanticData->getProperties() as $property) {
$hash[] = $property->getKey();
foreach ($semanticData->getPropertyValues($property) as $di) {
$hash[] = $di->getSerialization();
}
}
foreach ($semanticData->getSubSemanticData() as $data) {
$hash[] = $data->getHash();
}
sort($hash);
return md5(implode('#', $hash));
}
示例3: removeDataFrom
/**
* Removes data from the given SMWSemanticData.
* If the subject of the data that is to be removed is not equal to the
* subject of this SMWSemanticData, it will just be ignored (nothing to
* remove). Likewise, removing data that is not present does not change
* anything.
*
* @since 1.8
*
* @param SemanticData $semanticData
*/
public function removeDataFrom(SemanticData $semanticData)
{
if (!$this->mSubject->equals($semanticData->getSubject())) {
return;
}
foreach ($semanticData->getProperties() as $property) {
$values = $semanticData->getPropertyValues($property);
foreach ($values as $dataItem) {
$this->removePropertyObjectValue($property, $dataItem);
}
}
foreach ($semanticData->getSubSemanticData() as $semData) {
$this->removeSubSemanticData($semData);
}
}
示例4: displayData
/**
* Creates the HTML table displaying the data of one subject.
*
* @param[in] $data SMWSemanticData The data to be displayed
* @param[in] $left bool Should properties be displayed on the left side?
* @param[in] $incoming bool Is this an incoming? Or an outgoing?
*
* @return string A string containing the HTML with the factbox
*/
private function displayData(SemanticData $data, $left = true, $incoming = false)
{
// Some of the CSS classes are different for the left or the right side.
// In this case, there is an "i" after the "smwb-". This is set here.
$ccsPrefix = $left ? 'smwb-' : 'smwb-i';
$html = "<table class=\"{$ccsPrefix}factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";
$diProperties = $data->getProperties();
$noresult = true;
foreach ($diProperties as $key => $diProperty) {
$dvProperty = DataValueFactory::getInstance()->newDataValueByItem($diProperty, null);
if ($dvProperty->isVisible()) {
$dvProperty->setCaption($this->getPropertyLabel($dvProperty, $incoming));
$proptext = $dvProperty->getShortHTMLText(smwfGetLinker()) . "\n";
} elseif ($diProperty->getKey() == '_INST') {
$proptext = smwfGetLinker()->specialLink('Categories');
} elseif ($diProperty->getKey() == '_REDI') {
$proptext = smwfGetLinker()->specialLink('Listredirects', 'isredirect');
} else {
continue;
// skip this line
}
$head = '<th>' . $proptext . "</th>\n";
$body = "<td>\n";
$values = $data->getPropertyValues($diProperty);
if ($incoming && count($values) >= $this->incomingValuesCount) {
$moreIncoming = true;
array_pop($values);
} else {
$moreIncoming = false;
}
$first = true;
foreach ($values as $di) {
if ($first) {
$first = false;
} else {
$body .= ', ';
}
if ($incoming) {
$dv = DataValueFactory::getInstance()->newDataValueByItem($di, null);
} else {
$dv = DataValueFactory::getInstance()->newDataValueByItem($di, $diProperty);
}
// For a redirect, disable the DisplayTitle to show the original (aka source) page
if ($diProperty->getKey() == '_REDI') {
$dv->setOption('smwgDVFeatures', $dv->getOptionBy('smwgDVFeatures') & ~SMW_DV_WPV_DTITLE);
}
$body .= "<span class=\"{$ccsPrefix}value\">" . $this->displayValue($dvProperty, $dv, $incoming) . "</span>\n";
}
// Added in 2.3
// link to the remaining incoming pages
if ($moreIncoming && \Hooks::run('SMW::Browse::BeforeIncomingPropertyValuesFurtherLinkCreate', array($diProperty, $this->subject->getDataItem(), &$body))) {
$body .= \Html::element('a', array('href' => \SpecialPage::getSafeTitleFor('SearchByProperty')->getLocalURL(array('property' => $dvProperty->getWikiValue(), 'value' => $this->subject->getWikiValue()))), wfMessage('smw_browse_more')->text());
}
$body .= "</td>\n";
// display row
$html .= "<tr class=\"{$ccsPrefix}propvalue\">\n" . ($left ? $head . $body : $body . $head) . "</tr>\n";
$noresult = false;
}
// end foreach properties
if ($noresult) {
$html .= "<tr class=\"smwb-propvalue\"><th>   </th><td><em>" . wfMessage($incoming ? 'smw_browse_no_incoming' : 'smw_browse_no_outgoing')->escaped() . "</em></td></tr>\n";
}
$html .= "</table>\n";
return $html;
}
示例5: assertThatPropertiesAreSet
/**
* Assertion array should follow:
* 'propertyCount' => int
* 'propertyLabels' => array() or 'propertyKeys' => array()
* 'propertyValues' => array()
*
* @since 1.9.1
*
* @param array $expected
* @param SemanticData $semanticData
*/
public function assertThatPropertiesAreSet(array $expected, SemanticData $semanticData, $message = '')
{
$runPropertiesAreSetAssert = false;
$properties = $semanticData->getProperties();
if (isset($expected['strict-mode-valuematch'])) {
$this->setStrictModeForValueMatch($expected['strict-mode-valuematch']);
}
if (isset($expected['propertyCount'])) {
$this->assertThatSemanticDataHasPropertyCountOf($expected['propertyCount'], $semanticData, $message);
}
foreach ($properties as $property) {
$this->assertInstanceOf('\\SMW\\DIProperty', $property);
if (isset($expected['properties'])) {
$this->assertContainsProperty($expected['properties'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['property'])) {
$this->assertPropertyIsSameAs($expected['property'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['propertyKeys'])) {
$this->assertContainsPropertyKeys($expected['propertyKeys'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['propertyLabels'])) {
$this->assertContainsPropertyLabels($expected['propertyLabels'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['propertyValues'])) {
$this->assertThatPropertyValuesAreSet($expected, $property, $semanticData->getPropertyValues($property));
$runPropertiesAreSetAssert = true;
}
}
// Final ceck for values distributed over different properties
if (isset($expected['propertyValues']) && !$this->strictModeForValueMatch) {
$this->assertEmpty($expected['propertyValues'], "Unmatched values in {$message} for " . $this->formatAsString($expected['propertyValues']));
}
// Issue #124 needs to be resolved first
// $this->assertTrue( $runPropertiesAreSetAssert, __METHOD__ );
return $runPropertiesAreSetAssert;
}
示例6: getTableContent
/**
* Renders table content for a given SMWSemanticData object
*
* @since 1.9
*
* @param SMWSemanticData $semanticData
*/
protected function getTableContent(SemanticData $semanticData)
{
Profiler::In(__METHOD__);
// Do exclude some tags from processing otherwise the display
// can become distorted due to unresolved/open tags (see Bug 23185)
$excluded = array('table', 'tr', 'th', 'td', 'dl', 'dd', 'ul', 'li', 'ol', 'b', 'sup', 'sub');
$attributes = array();
foreach ($semanticData->getProperties() as $propertyDi) {
$propertyDv = $this->dataValueFactory->newDataItemValue($propertyDi, null);
if (!$propertyDi->isShown()) {
// showing this is not desired, hide
continue;
} elseif ($propertyDi->isUserDefined()) {
// User defined property (@note the preg_replace is a slight
// hack to ensure that the left column does not get too narrow)
$propertyDv->setCaption(preg_replace('/[ ]/u', ' ', $propertyDv->getWikiValue(), 2));
$attributes['property'] = array('class' => 'smwpropname');
$attributes['values'] = array('class' => 'smwprops');
} elseif ($propertyDv->isVisible()) {
// Predefined property
$attributes['property'] = array('class' => 'smwspecname');
$attributes['values'] = array('class' => 'smwspecs');
} else {
// predefined, internal property
// @codeCoverageIgnoreStart
continue;
// @codeCoverageIgnoreEnd
}
$valuesHtml = array();
foreach ($semanticData->getPropertyValues($propertyDi) as $dataItem) {
$dataValue = $this->dataValueFactory->newDataItemValue($dataItem, $propertyDi);
$dataValue->setServiceLinksRenderState(false);
if ($dataValue->isValid()) {
$valuesHtml[] = Sanitizer::removeHTMLtags($dataValue->getLongWikiText(true), null, array(), array(), $excluded) . $dataValue->getInfolinkText(SMW_OUTPUT_WIKI);
}
}
// Invoke table content
$this->tableBuilder->addCell($propertyDv->getShortWikiText(true), $attributes['property']);
$this->tableBuilder->addCell($this->messageBuilder->listToCommaSeparatedText($valuesHtml), $attributes['values']);
$this->tableBuilder->addRow();
}
Profiler::Out(__METHOD__);
}
示例7: setSemanticDataStateToParserOutputProperty
/**
* @since 2.1
*/
public function setSemanticDataStateToParserOutputProperty()
{
$this->parserOutput->setTimestamp(wfTimestampNow());
$this->parserOutput->setProperty('smw-semanticdata-status', $this->semanticData->getProperties() !== array());
}
示例8: assertThatPropertiesAreSet
/**
* Assertion array should follow:
* 'propertyCount' => int
* 'propertyLabels' => array() or 'propertyKeys' => array()
* 'propertyValues' => array()
*
* @since 1.9.1
*
* @param array $expected
* @param SemanticData $semanticData
*/
public function assertThatPropertiesAreSet(array $expected, SemanticData $semanticData)
{
$runPropertiesAreSetAssert = false;
$properties = $semanticData->getProperties();
if (isset($expected['propertyCount'])) {
$this->assertThatSemanticDataHasPropertyCountOf($expected['propertyCount'], $semanticData);
}
foreach ($properties as $property) {
$this->assertInstanceOf('\\SMW\\DIProperty', $property);
if (isset($expected['properties'])) {
$this->assertContainsProperty($expected['properties'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['property'])) {
$this->assertPropertyIsSameAs($expected['property'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['propertyKeys'])) {
$this->assertContainsPropertyKeys($expected['propertyKeys'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['propertyLabels'])) {
$this->assertContainsPropertyLabels($expected['propertyLabels'], $property);
$runPropertiesAreSetAssert = true;
}
if (isset($expected['propertyValues'])) {
$this->assertThatPropertyValuesAreSet($expected, $property, $semanticData->getPropertyValues($property));
$runPropertiesAreSetAssert = true;
}
}
// Issue #124 needs to be resolved first
// $this->assertTrue( $runPropertiesAreSetAssert, __METHOD__ );
return $runPropertiesAreSetAssert;
}
示例9: mapToInsertValueFormat
/**
* Create an array of rows to insert into property tables in order to
* store the given SMWSemanticData. The given $sid (subject page id) is
* used directly and must belong to the subject of the data container.
* Sortkeys are ignored since they are not stored in a property table
* but in the ID table.
*
* The returned array uses property table names as keys and arrays of
* table rows as values. Each table row is an array mapping column
* names to values.
*
* @note Property tables that do not use ids as subjects are ignored.
* This just excludes redirects that are handled differently anyway;
* it would not make a difference to include them here.
*
* @since 1.8
*
* @param integer $sid
* @param SemanticData $semanticData
*
* @return array
*/
private function mapToInsertValueFormat($sid, SemanticData $semanticData)
{
$updates = array();
$subject = $semanticData->getSubject();
$propertyTables = $this->store->getPropertyTables();
foreach ($semanticData->getProperties() as $property) {
$tableId = $this->store->findPropertyTableID($property);
// not stored in a property table, e.g., sortkeys
if ($tableId === null) {
continue;
}
// "Notice: Undefined index"
if (!isset($propertyTables[$tableId])) {
throw new RuntimeException("Unable to find a property table for " . $property->getKey());
}
$propertyTable = $propertyTables[$tableId];
// not using subject ids, e.g., redirects
if (!$propertyTable->usesIdSubject()) {
continue;
}
$insertValues = array('s_id' => $sid);
if (!$propertyTable->isFixedPropertyTable()) {
$insertValues['p_id'] = $this->store->getObjectIds()->makeSMWPropertyID($property);
}
foreach ($semanticData->getPropertyValues($property) as $dataItem) {
if ($dataItem instanceof DIError) {
// ignore error values
continue;
}
if (!array_key_exists($propertyTable->getName(), $updates)) {
$updates[$propertyTable->getName()] = array();
}
$dataItemValues = $this->store->getDataItemHandlerForDIType($dataItem->getDIType())->getInsertValues($dataItem);
// Ensure that the sortkey is a string
if (isset($dataItemValues['o_sortkey'])) {
$dataItemValues['o_sortkey'] = (string) $dataItemValues['o_sortkey'];
}
// Make sure to build a unique set without duplicates which could happen
// if an annotation is made to a property that has a redirect pointing
// to the same p_id
$insertValues = array_merge($insertValues, $dataItemValues);
$insertValuesHash = md5(implode('#', $insertValues));
$updates[$propertyTable->getName()][$insertValuesHash] = $insertValues;
}
}
// Special handling of Concepts
if ($subject->getNamespace() === SMW_NS_CONCEPT && $subject->getSubobjectName() == '') {
$this->fetchConceptTableInserts($sid, $updates);
}
return $updates;
}