http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90553
Revision: 90553 Author: jeroendedauw Date: 2011-06-21 21:47:55 +0000 (Tue, 21 Jun 2011) Log Message: ----------- added handling for record values Modified Paths: -------------- trunk/extensions/SemanticResultFormats/Math/SRF_Math.php Modified: trunk/extensions/SemanticResultFormats/Math/SRF_Math.php =================================================================== --- trunk/extensions/SemanticResultFormats/Math/SRF_Math.php 2011-06-21 21:46:52 UTC (rev 90552) +++ trunk/extensions/SemanticResultFormats/Math/SRF_Math.php 2011-06-21 21:47:55 UTC (rev 90553) @@ -74,7 +74,7 @@ while ( $row = $res->getNext() ) { foreach( $row as /* SMWResultArray */ $resultArray ) { while ( ( $dataValue = efSRFGetNextDV( $resultArray ) ) !== false ) { - $numbers = array_merge( $numbers, $this->getNumbersForDataValue( $dataValue ) ); + self::addNumbersForDataValue( $dataValue, $numbers ); } } } @@ -88,28 +88,53 @@ * @since 1.6 * * @param SMWDataValue $dataValue + * @param array $numbers * * @return array */ - protected function getNumbersForDataValue( SMWDataValue $dataValue ) { - $numbers = array(); - + public static function addNumbersForDataValue( SMWDataValue $dataValue, array &$numbers ) { + // Make use of instanceof instead of getTypeId so that deriving classes will get handled as well. if ( $dataValue instanceof SMWNumberValue ) { // getDataItem was introduced in SMW 1.6, getValueKey was deprecated in the same version. if ( method_exists( $dataValue, 'getDataItem' ) ) { - $numbers[] = $dataValue->getDataItem()->getNumber(); + self::addNumbersForDataItem( $dataValue->getDataItem(), $numbers ); } else { $numbers[] = $dataValue->getValueKey(); } + // Support for records (SMWRecordValue) using code added in SMW 1.6. + } elseif ( $dataValue instanceof SMWRecordValue && method_exists( $dataValue, 'getDataItem' ) ) { + self::addNumbersForDataItem( $dataValue->getDataItem(), $numbers ); // Support for SMWNAryValue, which was removed in SMW 1.6. } elseif ( $dataValue instanceof SMWNAryValue ) { - foreach ( $dataValue->getDVs() as $inner_value ) { - $numbers = array_merge( $numbers, $this->getNumbersForDataValue( $inner_value ) ); + foreach ( $dataValue->getDVs() as $dataValue ) { + self::addNumbersForDataValue( $dataValue, $numbers ); } } - - return $numbers; } + + /** + * Gets a list of all numbers contained in a dataitem. + * + * @since 1.6 + * + * @param SMWDataItem $dataItem + * @param array $numbers + * + * @return array + */ + public static function addNumbersForDataItem( SMWDataItem $dataItem, array &$numbers ) { + switch ( $dataItem->getDIType() ) { + case SMWDataItem::TYPE_NUMBER: /* case SMWDataItem::TYPE_WIKIPAGE: */ + $numbers[] = /* !method_exists( $dataItem, 'getNumber' ) ? $dataItem->getDBkey() : */ $dataItem->getNumber(); + break; + case SMWDataItem::TYPE_CONTAINER: + foreach ( $dataItem->getDataItems() as $di ) { + self::addNumbersForDataItem( $di, $numbers ); + } + break; + default: + } + } /** * (non-PHPdoc) _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs