00001 <?php
00002
00012 class SMGeoCoordsValueDescription extends SMWValueDescription {
00013
00021 public function __construct( SMWDataItem $dataItem, $comparator ) {
00022 parent::__construct( $dataItem, $comparator );
00023 }
00024
00032 public function getQueryString( $asValue = false ) {
00033 if ( $this->m_dataItem !== null ) {
00034 $queryString = SMWDataValueFactory::newDataItemValue( $this->m_dataItem, $this->m_property )->getWikiValue();
00035 return $asValue ? $queryString : "[[$queryString]]";
00036 } else {
00037 return $asValue ? '+' : '';
00038 }
00039 }
00040
00052 public function getSQLCondition( $tableName, array $fieldNames, $dbs ) {
00053 $dataItem = $this->getDataItem();
00054
00055
00056
00057 if ( $dataItem->getDIType() != SMWDataItem::TYPE_GEO ) return false;
00058
00059 $comparator = false;
00060
00061 switch ( $this->getComparator() ) {
00062 case SMW_CMP_EQ: $comparator = '='; break;
00063 case SMW_CMP_LEQ: $comparator = '<='; break;
00064 case SMW_CMP_GEQ: $comparator = '>='; break;
00065 case SMW_CMP_NEQ: $comparator = '!='; break;
00066 }
00067
00068 if ( $comparator ) {
00069 $lat = $dbs->addQuotes( $dataItem->getLatitude() );
00070 $lon = $dbs->addQuotes( $dataItem->getLongitude() );
00071
00072 $conditions = array();
00073
00074 $conditions[] = "{$tableName}.$fieldNames[0] $comparator $lat";
00075 $conditions[] = "{$tableName}.$fieldNames[1] $comparator $lon";
00076
00077 return implode( ' && ', $conditions );
00078 }
00079 else {
00080 return false;
00081 }
00082 }
00083
00084 }