/** * Convenience method that checks if the value that is used to sort * data of this type is numeric. This only works if the value is set. * * @return boolean */ public function isNumeric() { if ( isset( $this->m_dataitem ) ) { return is_numeric( $this->m_dataitem->getSortKey() ); } else { return false; } }
/** * Create an SWMExpElement that encodes auxiliary data for representing * values of the specified dataitem object in a simplified fashion. * This is done for types of dataitems that are not supported very well * in current systems, or that do not match a standard datatype in RDF. * For example, time points (DITime) are encoded as numbers. The number * can replace the actual time for all query and ordering purposes (the * order in either case is linear and maps to the real number line). * Only data retrieval should better use the real values to avoid that * rounding errors lead to unfaithful recovery of data. Note that the * helper values do not maintain any association with their original * values -- they are a fully redundant alternative representation, not * an additional piece of information for the main values. Even if * decoding is difficult, they must be in one-to-one correspondence to * the original value. * * For dataitems that do not have such a simplification, the method * returns null. * * @note If a helper element is used, then it must be the same as * getDataItemHelperExpElement( $dataItem->getSortKeyDataItem() ). * Query conditions like ">" use sortkeys for values, and helper * elements are always preferred in query answering. * * @param $dataItem SMWDataItem * @return SMWExpElement or null */ public static function getDataItemHelperExpElement(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_TIME) { $lit = new SMWExpLiteral($dataItem->getSortKey(), 'http://www.w3.org/2001/XMLSchema#double', $dataItem); return $lit; } else { return null; } }
/** * Create an SWMExpElement that encodes auxiliary data for representing * values of the specified dataitem object in a simplified fashion. * This is done for types of dataitems that are not supported very well * in current systems, or that do not match a standard datatype in RDF. * For example, time points (DITime) are encoded as numbers. The number * can replace the actual time for all query and ordering purposes (the * order in either case is linear and maps to the real number line). * Only data retrieval should better use the real values to avoid that * rounding errors lead to unfaithful recovery of data. Note that the * helper values do not maintain any association with their original * values -- they are a fully redundant alternative representation, not * an additional piece of information for the main values. Even if * decoding is difficult, they must be in one-to-one correspondence to * the original value. * * For dataitems that do not have such a simplification, the method * returns null. * * @note If a helper element is used, then it must be the same as * getDataItemHelperExpElement( $dataItem->getSortKeyDataItem() ). * Query conditions like ">" use sortkeys for values, and helper * elements are always preferred in query answering. * * @param $dataItem SMWDataItem * @return SMWExpElement or null */ public static function getDataItemHelperExpElement(SMWDataItem $dataItem) { if ($dataItem->getDIType() == SMWDataItem::TYPE_TIME) { return new SMWExpLiteral((string) $dataItem->getSortKey(), 'http://www.w3.org/2001/XMLSchema#double', '', $dataItem); } if ($dataItem->getDIType() == SMWDataItem::TYPE_GEO) { return new SMWExpLiteral((string) $dataItem->getSortKey(), 'http://www.w3.org/2001/XMLSchema#string', '', $dataItem); } return null; }
public function equals(SMWDataItem $di) { if ($di->getDIType() !== SMWDataItem::TYPE_TIME) { return false; } return $di->getSortKey() === $this->getSortKey(); }
/** * Method to return an array of fields=>values for a DataItem. * This array is used to perform all insert operations into the DB. * To optimize return minimum fields having indexes. * * @return array */ public function getInsertValues(SMWDataItem $dataItem) { return array('o_serialized' => $dataItem->getSerialization(), 'o_sortkey' => $dataItem->getSortKey()); }
private function getFirstLetterForCategory(DataItem $dataItem) { $sortKey = $dataItem->getSortKey(); if ($dataItem->getDIType() == DataItem::TYPE_WIKIPAGE) { $sortKey = ApplicationFactory::getInstance()->getStore()->getWikiPageSortKey($dataItem); } return ByLanguageCollationMapper::getInstance()->findFirstLetterForCategory($sortKey); }
/** * Compatibility function for computing the old getDBkeys() array for * the new SMW data items. * * @param $dataItem SMWDataItem * @return array of mixed */ public static function getDBkeysFromDataItem(SMWDataItem $dataItem) { switch ($dataItem->getDIType()) { case SMWDataItem::TYPE_STRING: case SMWDataItem::TYPE_BLOB: return array($dataItem->getString()); case SMWDataItem::TYPE_URI: return array($dataItem->getSerialization()); case SMWDataItem::TYPE_WIKIPAGE: return array($dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getSortKey()); case SMWDataItem::TYPE_NUMBER: return array($dataItem->getSerialization(), floatval($dataItem->getNumber())); case SMWDataItem::TYPE_TIME: $xsdvalue = $dataItem->getYear() . "/" . ($dataItem->getPrecision() >= SMWDITime::PREC_YM ? $dataItem->getMonth() : '') . "/" . ($dataItem->getPrecision() >= SMWDITime::PREC_YMD ? $dataItem->getDay() : '') . "T"; if ($dataItem->getPrecision() == SMWDITime::PREC_YMDT) { $xsdvalue .= sprintf("%02d", $dataItem->getHour()) . ':' . sprintf("%02d", $dataItem->getMinute()) . ':' . sprintf("%02d", $dataItem->getSecond()); } return array($xsdvalue, $dataItem->getSortKey()); case SMWDataItem::TYPE_BOOLEAN: return $dataItem->getBoolean() ? array('1', 1) : array('0', 0); case SMWDataItem::TYPE_CONTAINER: return array(false); case SMWDataItem::TYPE_CONCEPT: return array($dataItem->getConceptQuery(), $dataItem->getDocumentation(), $dataItem->getQueryFeatures(), $dataItem->getSize(), $dataItem->getDepth()); case SMWDataItem::TYPE_PROPERTY: return array($dataItem->getKey()); case SMWDataItem::TYPE_GEO: $coordinateSet = $dataItem->getCoordinateSet(); return array($coordinateSet['lat'], $coordinateSet['lon']); default: return array(false); } }