Commit 634da4b4 authored by Chenu Denis's avatar Chenu Denis

[feature] Allow to force total lines to 0

[feature] Allow to set NA and Not set value
parent a691ae17
......@@ -8,7 +8,7 @@
<author>Denis Chenu</author>
<authorUrl>https://extensions.sondages.pro/</authorUrl>
<supportUrl>https://support.sondages.pro/</supportUrl>
<version>0.14.0-beta</version>
<version>0.14.1</version>
<license>GNU General Public License v3.0</license>
<description><![CDATA[Filtered and compiled export system.]]></description>
</metadata>
......
......@@ -5,7 +5,7 @@
* @author Denis Chenu <[email protected]>
* @copyright 2020 Denis Chenu <http://www.sondages.pro>
* @license AGPL v3
* @version 1.4.0-beta
* @version 1.4.1
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
......@@ -73,7 +73,12 @@ class filteredExport
* alltotal => boolean : add a whole total line
*
**/
public $options = array();
public $options = array(
'alltotal' => false,
'totalforced' => false,
'NATextValue' => '',
'NotsetTextValue' => '',
);
/* var boolean */
public $throwError = false;
......@@ -280,7 +285,8 @@ class filteredExport
$totalCount = 0;
$totalWeight = 0;
$totalWeightAlt = 0;
$optionsAllTotal = !empty($this->options['alltotal']);
$optionsAllTotal = !$this->options['alltotal'];
$optionsAllTotal = true;
if($optionsAllTotal) {
$aAllData = array();
$totalAllCount = 0;
......@@ -382,19 +388,46 @@ class filteredExport
}
}
}
if(!empty($aCurrentData)) {
if (!empty($aCurrentData)) {
$aCurrentData = $this->updateDataForExport($aCurrentData,$aOperations,$totalCount, $totalWeight, $totalWeightAlt);
$this->addExportData($aCurrentData);
}
if($optionsAllTotal && !empty($aAllData)) {
if(isset($aAllData['data'.$this->questionCompileBy])) {
$aAllData['data'.$this->questionCompileBy] = gT("Total");
if ($optionsAllTotal) {
if(!empty($aAllData)) {
if(isset($aAllData['data'.$this->questionCompileBy])) {
$aAllData['data'.$this->questionCompileBy] = gT("Total");
}
if(isset($aAllData['data'.$this->questionCompile])) {
$aAllData['data'.$this->questionCompile] = gT("Total");
}
$aAllData = $this->updateDataForExport($aAllData,$aOperations,$totalAllCount, $totalAllWeight, $totalAllWeightAlt);
$this->addExportData($aAllData);
}
if(isset($aAllData['data'.$this->questionCompile])) {
$aAllData['data'.$this->questionCompile] = gT("Total");
if(empty($aAllData)) {
// construct false data
foreach($aOperations as $aOperation) {
switch ($aOperation['op']) {
case 'data':
$aAllData[$aOperation['id']] = $this->options['NATextValue'];
break;
case 'sum':
case 'weighted':
case 'weightedalt':
$aAllData[$aOperation['id']] = 0;
break;
default:
$aAllData[$aOperation['id']] = '';
}
}
if(isset($aAllData['data'.$this->questionCompileBy])) {
$aAllData['data'.$this->questionCompileBy] = gT("Total");
}
if(isset($aAllData['data'.$this->questionCompile])) {
$aAllData['data'.$this->questionCompile] = gT("Total");
}
$aAllData = $this->updateDataForExport($aAllData,$aOperations,0, 0, 0);
$this->addExportData($aAllData);
}
$aAllData = $this->updateDataForExport($aAllData,$aOperations,$totalAllCount, $totalAllWeight, $totalAllWeightAlt);
$this->addExportData($aAllData);
}
return $this->endExport();
}
......@@ -574,21 +607,21 @@ class filteredExport
if($count > 0 ) {
$aData[$aOperation['id']] = $aData[$aOperation['id']] / $count;
} else {
$aData[$aOperation['id']] = "";
$aData[$aOperation['id']] = 'NATextValue';
}
break;
case 'weighted':
if($weight > 0 ) {
$aData[$aOperation['id']] = $aData[$aOperation['id']] / $weight;
} else {
$aData[$aOperation['id']] = "";
$aData[$aOperation['id']] = 'NATextValue';
}
break;
case 'weightedalt':
if($weightAlt > 0 ) {
$aData[$aOperation['id']] = $aData[$aOperation['id']] / $weightAlt;
} else {
$aData[$aOperation['id']] = "";
$aData[$aOperation['id']] = 'NATextValue';
}
break;
case 'data':
......
......@@ -4,7 +4,7 @@
* @copyright 2020 Denis Chenu <http://www.sondages.pro>
* @copyright 2020 OECD (Organisation for Economic Co-operation and Development ) <www.oecd.org>
* @license GPL
* @version 0.14.0
* @version 0.14.1
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment