Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php |
— | — | @@ -173,7 +173,7 @@ |
174 | 174 | $numdv = SMWDataValueFactory::newTypeIDValue('_num'); // used for parsing the factors |
175 | 175 | foreach ($factors as $dv) { |
176 | 176 | $numdv->setUserValue($dv->getWikiValue()); |
177 | | - if (!$numdv->isValid() || ($numdv->getNumericValue() === 0)) { |
| 177 | + if (!$numdv->isValid() || ($numdv->getValueKey() === 0)) { |
178 | 178 | continue; // ignore problematic conversions |
179 | 179 | } |
180 | 180 | $unit_aliases = preg_split('/\s*,\s*/u', $numdv->getUnit()); |
— | — | @@ -182,11 +182,11 @@ |
183 | 183 | $unit = $this->normalizeUnit($unit); |
184 | 184 | if ($first) { |
185 | 185 | $unitid = $unit; |
186 | | - if ( $numdv->getNumericValue() == 1 ) { // add main unit to front of array (displyed first) |
| 186 | + if ( $numdv->getValueKey() == 1 ) { // add main unit to front of array (displyed first) |
187 | 187 | $this->m_mainunit = $unit; |
188 | | - $this->m_unitfactors = array( $unit => $numdv->getNumericValue() ) + $this->m_unitfactors; |
| 188 | + $this->m_unitfactors = array( $unit => $numdv->getValueKey() ) + $this->m_unitfactors; |
189 | 189 | } else { // non-main units are not ordered -- they might come out in any way the DB likes (can be modified via display units) |
190 | | - $this->m_unitfactors[$unit] = $numdv->getNumericValue(); |
| 190 | + $this->m_unitfactors[$unit] = $numdv->getValueKey(); |
191 | 191 | } |
192 | 192 | $first = false; |
193 | 193 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -506,21 +506,6 @@ |
507 | 507 | abstract public function getWikiValue(); |
508 | 508 | |
509 | 509 | /** |
510 | | - * Return the numeric representation of the value that can be |
511 | | - * used for ordering values of this datatype. The given number |
512 | | - * can be approximate and need not completely reflect the contents |
513 | | - * of a data value. It merely is used for comparing two such |
514 | | - * values. NULL is returned if no such number is provided, but |
515 | | - * it is recommended to use isNumeric() to check for this case. |
516 | | - * @note Storage implementations can assume numerical values to |
517 | | - * be completely determined from the given datavalue (i.e. from the |
518 | | - * vector returned by getDBkeys(). |
519 | | - */ |
520 | | - public function getNumericValue() { |
521 | | - return null; |
522 | | - } |
523 | | - |
524 | | - /** |
525 | 510 | * Return a short string that unambiguously specify the type of this value. |
526 | 511 | * This value will globally be used to identify the type of a value (in spite |
527 | 512 | * of the class it actually belongs to, which can still implement various types). |
— | — | @@ -568,15 +553,34 @@ |
569 | 554 | } |
570 | 555 | |
571 | 556 | /** |
572 | | - * Return TRUE if values of the given type generally have a numeric version, |
573 | | - * i.e. if getNumericValue returns a meaningful numeric sortkey. |
574 | | - * Possibly overwritten by subclasses. |
| 557 | + * Convenience method that checks if the value that is used to sort data of |
| 558 | + * this type is numeric. |
575 | 559 | */ |
576 | 560 | public function isNumeric() { |
577 | | - return false; |
| 561 | + $sig = $this->getSignature(); |
| 562 | + $validx = $this->getValueIndex(); |
| 563 | + if ( ($validx >= 0) && ($validx < strlen($sig)) ) { |
| 564 | + return ( ( $sig{$validx} == 'n' ) || ( $sig{$validx} == 'f' ) ); |
| 565 | + } else { |
| 566 | + return false; |
| 567 | + } |
578 | 568 | } |
579 | 569 | |
580 | 570 | /** |
| 571 | + * Convenience method that returns the DB key that holds the value that is |
| 572 | + * to be used for sorting data of this kind. If this datatype does not |
| 573 | + * support sorting, then null is returned here. |
| 574 | + */ |
| 575 | + public function getValueKey() { |
| 576 | + $dbkeys = $this->getDBkeys(); |
| 577 | + if ( array_key_exists($this->getValueIndex(), $dbkeys) ) { |
| 578 | + return $dbkeys[$this->getValueIndex()]; |
| 579 | + } else { |
| 580 | + return null; |
| 581 | + } |
| 582 | + } |
| 583 | + |
| 584 | + /** |
581 | 585 | * Return TRUE if a value was defined and understood by the given type, |
582 | 586 | * and false if parsing errors occured or no value was given. |
583 | 587 | */ |
— | — | @@ -691,6 +695,16 @@ |
692 | 696 | return ''; // empty unit |
693 | 697 | } |
694 | 698 | |
| 699 | + /** |
| 700 | + * Alias for getValueKey(). If you use this function and test if its result |
| 701 | + * is null, then use isNumeric() instead to check this. If this is done, |
| 702 | + * getValueKey() can be used instead. |
| 703 | + * @deprecated This function will vanish before SMW 1.6. |
| 704 | + */ |
| 705 | + public function getNumericValue() { |
| 706 | + return $this->getValueKey(); |
| 707 | + } |
| 708 | + |
695 | 709 | } |
696 | 710 | |
697 | 711 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php |
— | — | @@ -361,7 +361,7 @@ |
362 | 362 | $excluded_dates = explode(';', $value); |
363 | 363 | foreach ($excluded_dates as $date_str) { |
364 | 364 | $date = SMWDataValueFactory::newTypeIDValue('_dat', $date_str); |
365 | | - $excluded_dates_jd[] = $date->getNumericValue(); |
| 365 | + $excluded_dates_jd[] = $date->getValueKey(); |
366 | 366 | } |
367 | 367 | } |
368 | 368 | } |
— | — | @@ -376,11 +376,11 @@ |
377 | 377 | if (is_null($period) || $period < 1 || $period > 500) |
378 | 378 | $period = 1; |
379 | 379 | // get the Julian day value for both the start and end date |
380 | | - $start_date_jd = $start_date->getNumericValue(); |
| 380 | + $start_date_jd = $start_date->getValueKey(); |
381 | 381 | if (! is_null($end_date)) |
382 | | - $end_date_jd = $end_date->getNumericValue(); |
| 382 | + $end_date_jd = $end_date->getValueKey(); |
383 | 383 | $cur_date = $start_date; |
384 | | - $cur_date_jd = $start_date->getNumericValue(); |
| 384 | + $cur_date_jd = $start_date->getValueKey(); |
385 | 385 | $i = 0; |
386 | 386 | $reached_end_date = false; |
387 | 387 | do { |
— | — | @@ -408,7 +408,7 @@ |
409 | 409 | } |
410 | 410 | $date_str = "$cur_year-$cur_month-$cur_day $cur_time"; |
411 | 411 | $cur_date = SMWDataValueFactory::newTypeIDValue('_dat', $date_str); |
412 | | - $cur_date_jd = $cur_date->getNumericValue(); |
| 412 | + $cur_date_jd = $cur_date->getValueKey(); |
413 | 413 | } else { // $unit == 'day' or 'week' |
414 | 414 | // assume 'day' if it's none of the above |
415 | 415 | $cur_date_jd += ($unit === 'week') ? 7 * $period : $period; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php |
— | — | @@ -244,7 +244,7 @@ |
245 | 245 | if ($angles[$i] !== false) { |
246 | 246 | $numvalue->setUserValue($angles[$i]); |
247 | 247 | if ($numvalue->isValid() && ($numvalue->getUnit() == '')) { |
248 | | - $res += $numvalue->getNumericValue() / $factor; |
| 248 | + $res += $numvalue->getValueKey() / $factor; |
249 | 249 | } else { |
250 | 250 | $this->addError(wfMsgForContent('smw_nofloat', $angles[$i])); |
251 | 251 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php |
— | — | @@ -79,7 +79,7 @@ |
80 | 80 | $values[] = '"'.$value->getXSDValue().'"'; |
81 | 81 | break; |
82 | 82 | case '_num': |
83 | | - $values[] = $value->getNumericValue($outputmode,$this->getLinker(0)); |
| 83 | + $values[] = $value->getValueKey(); |
84 | 84 | break; |
85 | 85 | case '_dat': |
86 | 86 | $values[] = "\"".$value->getYear()."-".str_pad($value->getMonth(),2,'0',STR_PAD_LEFT)."-".str_pad($value->getDay(),2,'0',STR_PAD_LEFT)." ".$value->getTimeString()."\""; |
— | — | @@ -99,7 +99,7 @@ |
100 | 100 | $count++; |
101 | 101 | } |
102 | 102 | $valuestack[] = '"uri" : "'.$wgServer.$wgScriptPath.'/index.php?title='.$prefixedtext.'"'; |
103 | | - |
| 103 | + |
104 | 104 | //try to determine type/category |
105 | 105 | $catlist = array(); |
106 | 106 | $dbr = &wfGetDB(DB_SLAVE); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php |
— | — | @@ -52,8 +52,8 @@ |
53 | 53 | $first = true; |
54 | 54 | while ( ($object = $field->getNextObject()) !== false ) { |
55 | 55 | if ($first) { |
56 | | - if ($object->isNumeric()) { // use numeric sortkey |
57 | | - $result .= '<span class="smwsortkey">' . $object->getNumericValue() . '</span>'; |
| 56 | + if ($object->isNumeric()) { // additional hidden sortkey for numeric entries |
| 57 | + $result .= '<span class="smwsortkey">' . $object->getValueKey() . '</span>'; |
58 | 58 | } |
59 | 59 | $first = false; |
60 | 60 | } else { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php |
— | — | @@ -163,7 +163,7 @@ |
164 | 164 | public function getDBkeys() { |
165 | 165 | $this->unstub(); |
166 | 166 | $this->convertToMainUnit(); |
167 | | - return array($this->m_value, intval($this->m_value), $this->m_unit); |
| 167 | + return array($this->m_value, floatval($this->m_value), $this->m_unit); |
168 | 168 | } |
169 | 169 | |
170 | 170 | public function getSignature() { |
— | — | @@ -183,12 +183,6 @@ |
184 | 184 | return $this->m_wikivalue; |
185 | 185 | } |
186 | 186 | |
187 | | - public function getNumericValue() { |
188 | | - $this->unstub(); |
189 | | - $this->convertToMainUnit(); |
190 | | - return $this->m_value; |
191 | | - } |
192 | | - |
193 | 187 | public function getUnit() { |
194 | 188 | $values = $this->getDBkeys(); |
195 | 189 | return $values[2]; |
— | — | @@ -214,10 +208,6 @@ |
215 | 209 | return array((string)$this->m_value, (string)round($this->m_value), $this->m_unit); |
216 | 210 | } |
217 | 211 | |
218 | | - public function isNumeric() { |
219 | | - return true; |
220 | | - } |
221 | | - |
222 | 212 | public function getExportData() { |
223 | 213 | $this->unstub(); |
224 | 214 | if ($this->isValid()) { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php |
— | — | @@ -121,15 +121,6 @@ |
122 | 122 | return $this->m_stdcaption; |
123 | 123 | } |
124 | 124 | |
125 | | - public function getNumericValue() { |
126 | | - $this->unstub(); |
127 | | - return $this->m_value?'1':'0'; |
128 | | - } |
129 | | - |
130 | | - public function isNumeric() { |
131 | | - return true; |
132 | | - } |
133 | | - |
134 | 125 | public function getExportData() { |
135 | 126 | if ($this->isValid()) { |
136 | 127 | $xsdvalue = $this->m_value?'true':'false'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php |
— | — | @@ -378,12 +378,6 @@ |
379 | 379 | return 0; |
380 | 380 | } |
381 | 381 | |
382 | | - public function getNumericValue() { |
383 | | - $this->unstub(); |
384 | | - $this->createJD(); |
385 | | - return $this->m_jd; |
386 | | - } |
387 | | - |
388 | 382 | public function getWikiValue() { |
389 | 383 | $this->unstub(); |
390 | 384 | return $this->m_wikivalue; |
— | — | @@ -398,10 +392,6 @@ |
399 | 393 | } |
400 | 394 | } |
401 | 395 | |
402 | | - public function isNumeric() { |
403 | | - return true; |
404 | | - } |
405 | | - |
406 | 396 | public function getExportData() { |
407 | 397 | if ($this->isValid()) { |
408 | 398 | $lit = new SMWExpLiteral($this->getXMLSchemaDate(), $this, 'http://www.w3.org/2001/XMLSchema#dateTime'); |