r47141 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47140‎ | r47141 | r47142 >
Date:15:38, 11 February 2009
Author:yaron
Status:deferred
Tags:
Comment:
Added handling for multiple-value relations and multiple properties per page
Modified paths:
  • /trunk/extensions/SemanticResultFormats/Math/SRF_Math.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/Math/SRF_Math.php
@@ -30,12 +30,28 @@
3131
3232 while ( $row = $res->getNext() ) {
3333 $last_col = array_pop($row);
34 - $number_value = array_pop($last_col->getContent());
35 - // if the property isn't of type Number, just ignore
36 - // this row
37 - if ( $number_value instanceof SMWNumberValue ) {
 34+ foreach ( $last_col->getContent() as $value ) {
 35+ // handle each value only if it's of type Number or NAry
 36+ if ( $value instanceof SMWNumberValue ) {
 37+ $num = $value->getNumericValue();
 38+ } elseif ( $value instanceof SMWNAryValue ) {
 39+ $inner_values = $value->getDVs();
 40+ // find the first inner value that's of
 41+ // type Number, and use that; if none
 42+ // are found, ignore this row
 43+ $num = null;
 44+ foreach ( $inner_values as $inner_value ) {
 45+ if ( $inner_value instanceof SMWNumberValue ) {
 46+ $num = $inner_value->getNumericValue();
 47+ break;
 48+ }
 49+ }
 50+ if ( is_null( $num ) )
 51+ continue;
 52+ } else {
 53+ continue;
 54+ }
3855 $count++;
39 - $num = $number_value->getNumericValue();
4056 if ($this->mFormat == 'sum' || $this->mFormat == 'average') {
4157 $sum += $num;
4258 } elseif ($this->mFormat == 'min') {

Status & tagging log