Beispiel #1
0
 /**
  * This factory method returns a data value object from a given property,
  * value string. It is intended to be used on user input to allow to
  * turn a property and value string into a data value object.
  *
  * @since 1.9
  *
  * @param string $propertyName property string
  * @param string $valueString user value string
  * @param mixed $caption user-defined caption
  * @param SMWDIWikiPage|null $contextPage context for parsing the value string
  *
  * @return DataValue
  */
 public function newPropertyValue($propertyName, $valueString, $caption = false, DIWikiPage $contextPage = null)
 {
     // Enforce upper case for the first character on annotations that are used
     // within the property namespace in order to avoid confusion when
     // $wgCapitalLinks setting is disabled
     if ($contextPage !== null && $contextPage->getNamespace() === SMW_NS_PROPERTY) {
         $propertyName = ucfirst($propertyName);
     }
     $propertyDV = SMWPropertyValue::makeUserProperty($propertyName);
     if (!$propertyDV->isValid()) {
         return $propertyDV;
     }
     if (!$propertyDV->canUse()) {
         return new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw-datavalue-property-restricted-use', $propertyName)->inContentLanguage()->text(), $valueString, $caption);
     }
     $propertyDI = $propertyDV->getDataItem();
     if ($propertyDI instanceof SMWDIError) {
         return $propertyDV;
     }
     if ($propertyDI instanceof DIProperty && !$propertyDI->isInverse()) {
         $dataValue = $this->newPropertyObjectValue($propertyDI, $valueString, $caption, $contextPage);
     } elseif ($propertyDI instanceof DIProperty && $propertyDI->isInverse()) {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw_noinvannot')->inContentLanguage()->text(), $valueString, $caption);
     } else {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw-property-name-invalid', $propertyName)->inContentLanguage()->text(), $valueString, $caption);
     }
     if ($dataValue->isValid() && !$dataValue->canUse()) {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw-datavalue-restricted-use', implode(',', $datavalue->getErrors()))->inContentLanguage()->text(), $valueString, $caption);
     }
     return $dataValue;
 }
 /**
  * This factory method returns a data value object from a given property,
  * value string. It is intended to be used on user input to allow to
  * turn a property and value string into a data value object.
  *
  * @since 1.9
  *
  * @param string $propertyName property string
  * @param string $valueString user value string
  * @param mixed $caption user-defined caption
  * @param SMWDIWikiPage|null $contextPage context for parsing the value string
  *
  * @return DataValue
  */
 public function newDataValueByText($propertyName, $valueString, $caption = false, DIWikiPage $contextPage = null)
 {
     $propertyDV = $this->newPropertyValueByLabel($propertyName, $caption, $contextPage);
     if (!$propertyDV->isValid()) {
         return $propertyDV;
     }
     if (!$propertyDV->canUse()) {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), array('smw-datavalue-property-restricted-use', $propertyName), $valueString, $caption);
         $dataValue->setProperty($propertyDV->getDataItem());
         return $dataValue;
     }
     $propertyDI = $propertyDV->getDataItem();
     if ($propertyDI instanceof SMWDIError) {
         return $propertyDV;
     }
     if ($propertyDI instanceof DIProperty && !$propertyDI->isInverse()) {
         $dataValue = $this->newDataValueByProperty($propertyDI, $valueString, $caption, $contextPage);
         $dataValue->setProperty($propertyDV->getDataItem());
     } elseif ($propertyDI instanceof DIProperty && $propertyDI->isInverse()) {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), array('smw_noinvannot'), $valueString, $caption);
         $dataValue->setProperty($propertyDV->getDataItem());
     } else {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), array('smw-property-name-invalid', $propertyName), $valueString, $caption);
         $dataValue->setProperty($propertyDV->getDataItem());
     }
     if ($dataValue->isValid() && !$dataValue->canUse()) {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), array('smw-datavalue-restricted-use', implode(',', $dataValue->getErrors())), $valueString, $caption);
         $dataValue->setProperty($propertyDV->getDataItem());
     }
     return $dataValue;
 }