/**
  * Get the serialization for the provided data item.
  *
  * @since 1.7
  *
  * @param SMWDataItem $dataItem
  *
  * @return mixed
  */
 public static function getSerialization(DataItem $dataItem, $printRequest = null)
 {
     $result = array();
     switch ($dataItem->getDIType()) {
         case DataItem::TYPE_WIKIPAGE:
             $title = $dataItem->getTitle();
             $result = array('fulltext' => $title->getFullText(), 'fullurl' => $title->getFullUrl(), 'namespace' => $title->getNamespace(), 'exists' => $title->isKnown());
             break;
         case DataItem::TYPE_NUMBER:
             // dataitems and datavalues
             // Quantity is a datavalue type that belongs to dataitem
             // type number which means in order to identify the correct
             // unit, we have re-factor the corresponding datavalue otherwise
             // we will not be able to determine the unit
             // (unit is part of the datavalue object)
             if ($printRequest !== null && $printRequest->getTypeID() === '_qty') {
                 $diProperty = $printRequest->getData()->getDataItem();
                 $dataValue = DataValueFactory::getInstance()->newDataItemValue($dataItem, $diProperty);
                 $result = array('value' => $dataValue->getNumber(), 'unit' => $dataValue->getUnit());
             } else {
                 $result = $dataItem->getNumber();
             }
             break;
         case DataItem::TYPE_GEO:
             $result = $dataItem->getCoordinateSet();
             break;
         case DataItem::TYPE_TIME:
             $result = $dataItem->getMwTimestamp();
             break;
         default:
             $result = $dataItem->getSerialization();
             break;
     }
     return $result;
 }
 /**
  * Get the serialization for the provided data item.
  *
  * @since 1.7
  *
  * @param SMWDataItem $dataItem
  *
  * @return mixed
  */
 public static function getSerialization(SMWDataItem $dataItem)
 {
     switch ($dataItem->getDIType()) {
         case SMWDataItem::TYPE_WIKIPAGE:
             $title = $dataItem->getTitle();
             $result = array('fulltext' => $title->getFullText(), 'fullurl' => $title->getFullUrl());
             break;
         case SMWDataItem::TYPE_NUMBER:
             $result = $dataItem->getNumber();
             break;
         case SMWDataItem::TYPE_GEO:
             $result = $dataItem->getCoordinateSet();
             break;
         case SMWDataItem::TYPE_TIME:
             $result = $dataItem->getMwTimestamp();
             break;
         default:
             $result = $dataItem->getSerialization();
             break;
     }
     return $result;
 }
 /**
  * @since 2.3
  *
  * @param DataItem|null $dataItem
  *
  * @return string|null
  */
 public function tryToFindRedirectVariableForDataItem(DataItem $dataItem = null)
 {
     if (!$dataItem instanceof DIWikiPage || !$this->canUseQFeature(SMW_SPARQL_QF_REDI)) {
         return null;
     }
     // Maybe there is a better way to verify the "isRedirect" state other
     // than by using the Title object
     if ($dataItem->getTitle() === null || !$dataItem->getTitle()->isRedirect()) {
         return null;
     }
     $redirectExpElement = Exporter::getInstance()->getResourceElementForWikiPage($dataItem);
     $valueName = TurtleSerializer::getTurtleNameForExpElement($redirectExpElement);
     // Add unknow redirect target/variable for value
     if (!isset($this->redirectByVariableReplacementMap[$valueName])) {
         $namespaces[$redirectExpElement->getNamespaceId()] = $redirectExpElement->getNamespace();
         $redirectByVariable = '?' . $this->getNextVariable('r');
         $this->redirectByVariableReplacementMap[$valueName] = array($redirectByVariable, $namespaces);
     }
     // Reuse an existing variable for the value to allow to be used more than
     // once when referring to the same property/value redirect
     list($redirectByVariable, $namespaces) = $this->redirectByVariableReplacementMap[$valueName];
     return $redirectByVariable;
 }