public function testCorrectInversePrefixForPredefinedProperty()
 {
     $property = new DIProperty('_SOBJ', true);
     $this->assertTrue($property->isInverse());
     $label = $property->getLabel();
     $this->assertEquals('-', $label[0]);
 }
 /**
  * @since 2.4
  *
  * @param DIProperty $property
  * @param array|string $errorMsg
  *
  * @return DIContainer
  */
 public function getContainerFor(DIProperty $property = null, $errorMsg = '')
 {
     if ($property !== null && $property->isInverse()) {
         $property = new DIProperty($property->getKey());
     }
     $errorMsg = is_array($errorMsg) ? implode(' ', $errorMsg) : $errorMsg;
     $subject = new DIWikiPage($this->subject->getDBkey(), $this->subject->getNamespace(), $this->subject->getInterwiki(), '_ERR' . md5(($property !== null ? $property->getKey() : 'UNKNOWN') . $errorMsg));
     // Encode brackets to avoid an annotion is created/included
     return $this->newDiContainer($subject, $property, InTextAnnotationParser::obscureAnnotation($errorMsg));
 }
 private function doMatchProperty(&$subjects, DIProperty $property)
 {
     if ($property->isInverse()) {
         $property = new DIProperty($property->getKey());
     }
     if ($this->propertyHierarchyLookup->hasSubpropertyFor($property)) {
         $this->doMatchSubproperty($subjects, $property);
     }
     $key = str_replace(' ', '_', $property->getKey());
     if (!isset($this->propertyDependencyDetectionBlacklist[$key])) {
         $subjects[] = $property->getDiWikiPage();
     }
 }
Beispiel #4
0
 /**
  * Remove a value for a property identified by its SMWDataItem object.
  * This method removes a property-value specified by the property and
  * dataitem. If there are no more property-values for this property it
  * also removes the property from the mProperties.
  *
  * @note There is no check whether the type of the given data item
  * agrees with the type of the property. Since property types can
  * change, all parts of SMW are prepared to handle mismatched data item
  * types anyway.
  *
  * @param $property DIProperty
  * @param $dataItem SMWDataItem
  *
  * @since 1.8
  */
 public function removePropertyObjectValue(DIProperty $property, SMWDataItem $dataItem)
 {
     //delete associated subSemanticData
     if ($dataItem instanceof SMWDIContainer) {
         $this->removeSubSemanticData($dataItem->getSemanticData());
         $dataItem = $dataItem->getSemanticData()->getSubject();
     }
     if ($property->isInverse()) {
         // inverse properties cannot be used for annotation
         return;
     }
     if (!array_key_exists($property->getKey(), $this->mPropVals) || !array_key_exists($property->getKey(), $this->mProperties)) {
         return;
     }
     if ($this->mNoDuplicates) {
         //this didn't get checked for my tests, but should work
         unset($this->mPropVals[$property->getKey()][$dataItem->getHash()]);
     } else {
         foreach ($this->mPropVals[$property->getKey()] as $index => $di) {
             if ($di->equals($dataItem)) {
                 unset($this->mPropVals[$property->getKey()][$index]);
             }
         }
         $this->mPropVals[$property->getKey()] = array_values($this->mPropVals[$property->getKey()]);
     }
     if ($this->mPropVals[$property->getKey()] === array()) {
         unset($this->mProperties[$property->getKey()]);
         unset($this->mPropVals[$property->getKey()]);
     }
 }
Beispiel #5
0
 /**
  * Create a value for the given property, provided as an SMWDIProperty
  * object. If no value is given, an empty container is created, the
  * value of which can be set later on.
  *
  * @param $property SMWDIProperty property object for which this value is made
  * @param $valueString mixed user value string, or false if unknown
  * @param $caption mixed user-defined caption, or false if none given
  * @param $contextPage SMWDIWikiPage that provides a context for parsing the value string, or null
  *
  * @return DataValue
  */
 public static function newPropertyObjectValue(DIProperty $property, $valueString = false, $caption = false, $contextPage = null)
 {
     $typeId = $property->isInverse() ? '_wpg' : $property->findPropertyTypeID();
     return self::newTypeIdValue($typeId, $valueString, $caption, $property, $contextPage);
 }
 private function doExchangeForWhenInversePropertyIsUsed(DIProperty $property, $objectName, $joinVariable)
 {
     $subjectName = '?' . $joinVariable;
     $nonInverseProperty = $property;
     // Exchange arguments when property is inverse
     // don't check if this really makes sense
     if ($property->isInverse()) {
         $subjectName = $objectName;
         $objectName = '?' . $joinVariable;
         $nonInverseProperty = new DIProperty($property->getKey(), false);
     }
     return array($subjectName, $objectName, $nonInverseProperty);
 }
 private function doMatchProperty(&$subjects, DIProperty $property)
 {
     if ($property->isInverse()) {
         $property = new DIProperty($property->getKey());
     }
     $subject = $property->getCanonicalDiWikiPage();
     if ($this->propertyHierarchyLookup->hasSubpropertyFor($property)) {
         $this->doMatchSubproperty($subjects, $subject, $property);
     }
     // Use the key here do match against pre-defined properties (e.g. _MDAT)
     $key = str_replace(' ', '_', $property->getKey());
     if (!isset($this->propertyDependencyExemptionlist[$key])) {
         $subjects[$subject->getHash()] = $subject;
     }
 }
 /**
  * Get the array of all stored values for some property.
  *
  * @since 1.8
  *
  * @param DIProperty $property
  *
  * @return array of SMWDataItem
  */
 public function getPropertyValues(DIProperty $property)
 {
     if ($property->isInverse()) {
         // we never have any data for inverses
         return array();
     }
     if (array_key_exists($property->getKey(), $this->mStubPropVals)) {
         // Not catching exception here; the
         $this->unstubProperty($property->getKey(), $property);
         $propertyTypeId = $property->findPropertyTypeID();
         $propertyDiId = DataTypeRegistry::getInstance()->getDataItemId($propertyTypeId);
         foreach ($this->mStubPropVals[$property->getKey()] as $dbkeys) {
             try {
                 $diHandler = $this->store->getDataItemHandlerForDIType($propertyDiId);
                 $di = $diHandler->dataItemFromDBKeys($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);
 }
 /**
  * @since 2.5
  *
  * @param array|string $errorMsg
  * @param DIProperty|null $property
  *
  * @return DIContainer|null
  */
 public function getErrorContainerFromMsg($error, DIProperty $property = null)
 {
     if ($property !== null && $property->isInverse()) {
         $property = new DIProperty($property->getKey());
     }
     $error = Message::encode($error);
     $hash = $error;
     if ($property !== null) {
         $hash .= $property->getKey();
     }
     $containerSemanticData = $this->newContainerSemanticData($hash);
     $this->addToContainerSemanticData($containerSemanticData, $property, $error);
     return new DIContainer($containerSemanticData);
 }
 /**
  * Create a value for the given property, provided as an SMWDIProperty
  * object. If no value is given, an empty container is created, the
  * value of which can be set later on.
  *
  * @param $property SMWDIProperty property object for which this value is made
  * @param $valueString mixed user value string, or false if unknown
  * @param $caption mixed user-defined caption, or false if none given
  * @param $contextPage SMWDIWikiPage that provides a context for parsing the value string, or null
  *
  * @return DataValue
  */
 public function newDataValueByProperty(DIProperty $property, $valueString = false, $caption = false, $contextPage = null)
 {
     $typeId = $property->isInverse() ? '_wpg' : $property->findPropertyTypeID();
     return $this->newDataValueByType($typeId, $valueString, $caption, $property, $contextPage);
 }