Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/58689
Change subject: (Bug 47123) Aggregate numbers based on the mainlabel indication
......................................................................
(Bug 47123) Aggregate numbers based on the mainlabel indication
For a detailed description see bug 47123.
Change-Id: I93296527981efd8c31cb7e2ba95ca688f00ddb4a
---
M includes/queryprinters/SMW_QP_Aggregatable.php
1 file changed, 10 insertions(+), 4 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/89/58689/1
diff --git a/includes/queryprinters/SMW_QP_Aggregatable.php
b/includes/queryprinters/SMW_QP_Aggregatable.php
index edbca8e..c06e84f 100644
--- a/includes/queryprinters/SMW_QP_Aggregatable.php
+++ b/includes/queryprinters/SMW_QP_Aggregatable.php
@@ -160,13 +160,16 @@
$values = array();
// print all result rows
- while ( $row = $res->getNext() ) {
- $dataValue = $row[0]->getNextDataValue();
+ while ( $subject = $res->getNext() ) {
+ $dataValue = $subject[0]->getNextDataValue();
if ( $dataValue !== false ) {
$name = $dataValue->getShortWikiText();
- foreach ( $row as $field ) {
+ foreach ( $subject as $field ) {
+ // Key depends on the mainlabel if it
is subject or property label
+ $name = $this->params['mainlabel'] ===
'-' ? $field->getPrintRequest()->getLabel() : $name;
+
while ( ( /* SMWDataItem */ $dataItem =
$field->getNextDataItem() ) !== false ) {
$this->addNumbersForDataItem(
$dataItem, $values, $name );
}
@@ -189,7 +192,10 @@
protected function addNumbersForDataItem( SMWDataItem $dataItem, array
&$values, $name ) {
switch ( $dataItem->getDIType() ) {
case SMWDataItem::TYPE_NUMBER:
- $values[$name] = $dataItem->getNumber();
+ // Collect values that use the same array key
(depends on the
+ // mainlabel which is either subject or
property)
+ $value = $dataItem->getNumber();
+ $values[$name] = isset( $values[$name] ) ?
$values[$name] + $value : $value ;
break;
case SMWDataItem::TYPE_CONTAINER:
foreach ( $dataItem->getDataItems() as $di ) {
--
To view, visit https://gerrit.wikimedia.org/r/58689
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I93296527981efd8c31cb7e2ba95ca688f00ddb4a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits