/**
  * Check if property is range restricted and, if so, whether the current value is allowed.
  * Creates an error if the value is illegal.
  */
 protected function checkAllowedValues()
 {
     if (!is_null($this->m_property)) {
         $propertyDiWikiPage = $this->m_property->getDiWikiPage();
     }
     if (is_null($this->m_property) || is_null($propertyDiWikiPage) || !isset($this->m_dataitem)) {
         return;
         // no property known, or no data to check
     }
     $allowedvalues = \SMW\StoreFactory::getStore()->getPropertyValues($propertyDiWikiPage, new SMWDIProperty('_PVAL'));
     if (count($allowedvalues) == 0) {
         return;
     }
     $hash = $this->m_dataitem->getHash();
     $testdv = DataValueFactory::getInstance()->newTypeIDValue($this->getTypeID());
     $accept = false;
     $valuestring = '';
     foreach ($allowedvalues as $di) {
         if ($di instanceof SMWDIBlob) {
             $testdv->setUserValue($di->getString());
             if ($hash === $testdv->getDataItem()->getHash()) {
                 $accept = true;
                 break;
             } else {
                 if ($valuestring !== '') {
                     $valuestring .= ', ';
                 }
                 $valuestring .= $di->getString();
             }
         }
     }
     if (!$accept) {
         $this->addError(wfMessage('smw_notinenum', $this->getWikiValue(), $valuestring)->inContentLanguage()->text());
     }
 }
 /**
  * Return a string that identifies the value of the object, and that can
  * be used to compare different value objects.
  * Possibly overwritten by subclasses (e.g. to ensure that returned
  * value is normalized first)
  *
  * @return string
  */
 public function getHash()
 {
     return $this->isValid() ? $this->m_dataitem->getHash() : implode("\t", $this->mErrors);
 }
Beispiel #3
0
 /**
  * Store a value for a property identified by its SMWDataItem object.
  *
  * @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 SMWDIProperty
  * @param $dataItem SMWDataItem
  */
 public function addPropertyObjectValue(SMWDIProperty $property, SMWDataItem $dataItem)
 {
     if ($property->isInverse()) {
         // inverse properties cannot be used for annotation
         return;
     }
     if (!array_key_exists($property->getKey(), $this->mPropVals)) {
         $this->mPropVals[$property->getKey()] = array();
         $this->mProperties[$property->getKey()] = $property;
     }
     if ($this->mNoDuplicates) {
         $this->mPropVals[$property->getKey()][$dataItem->getHash()] = $dataItem;
     } else {
         $this->mPropVals[$property->getKey()][] = $dataItem;
     }
     if (!$property->isUserDefined()) {
         if ($property->isShown()) {
             $this->mHasVisibleSpecs = true;
             $this->mHasVisibleProps = true;
         }
     } else {
         $this->mHasVisibleProps = true;
     }
 }
 /**
  * @since  2.4
  *
  * @param DataItem $dataItem
  * @param DIProperty|null $property
  */
 public function addToEntityList(DataItem $dataItem, DIProperty $property = null)
 {
     $queryID = $this->getQueryId();
     if (!isset($this->entityList[$queryID])) {
         $this->entityList[$queryID] = array();
     }
     if ($dataItem instanceof DIWikiPage) {
         $this->entityList[$queryID][$dataItem->getHash()] = $dataItem;
     }
 }