View Issue Details

This bug affects 2 person(s).
 16
IDProjectCategoryView StatusLast Update
19471Feature requestsPluginspublic2024-05-08 08:56
Reporterjbarrouillet Assigned To 
PrioritynoneSeverityfeature 
Status newResolutionopen 
Summary19471: Feature Proposal For StatCount Plugin
Description

Hi,
I think it should be nice to upgrade StatCount Plugin with a SUM fonction on NUMERIC FIELD.

Example :
I need to make a survey to collect pledge of financial donation to a association.
I want to indicate, on a question texte, wich sum was collecte on the previous answers. To obtain this information, i need to make a SUM, on the previous answers, on a the numérical field "amount promised".

I'm looking on GetStatInSurvey but this plugin is not tested on V6 and Denis Chenu told me that StatCount is more powerfull.

Thanks for your interest on my request.

Additional Information

it's really the sum of all previous responses in the survey.
Exactly like all the function count of StatCount, but, with SUM on a numérical question type.

An other example :
There is a manifestation with 40 places. We can subscribe 1 time with a name and a number of people wich will come. This field is called "Number of people". I need to make a SUM on this field to compare 40 with the numbers of people wich will come. If it's over 40, i can't send the inscription.

Thank you

TagsNo tags attached.
Bug heat16
Story point estimate0
Users affected %0

Users monitoring this issue

Activities

jbarrouillet

jbarrouillet

2024-04-30 15:55

reporter   ~80050

Hi,

In the @denis chenu's plugin GetStatInSurvey, add this code in GetstatInSurvey.php:

On line 221

case 'sumnum':
switch ($oQuestion->type) {
case "5":
case "L":
case "!":
case "O":
case "N":
case "*":
case "S":
return $this->getSumNumeric($this->iSurveyId."X".$oQuestion->gid."X".$oQuestion->qid, $sValue);
default:
return $this->_logUsage("{$sMatch} : Invalid question type : {$oQuestion->type} in {$this->sDebugWhere}");
}
break;

And, add this private function in GetstatInSurvey.php too:

/**
 * Get the sum for a numeric question type
 * @param : $sCode : question title
 */
private function getSumNumeric($sColumn,$sType="sumnum")
{
    $aSumNumeric=array(); // Go to cache ?
    if(isset($aSumNumeric[$sColumn]))
        return $aSumNumeric[$sColumn];
    $sQuotedColumn=Yii::app()->db->quoteColumnName($sColumn);
    $iTotal=$this->getCountNumeric($sColumn);
    $oCriteria = new CDbCriteria;
    $oCriteria->select="SUM({$sQuotedColumn})";
    $oCriteria->condition="submitdate IS NOT NULL";
    $oCriteria->addCondition("concat('',{$sQuotedColumn} * 1) = {$sQuotedColumn}");
    $iSum = Yii::app()->db->getCommandBuilder()->createFindCommand(SurveyDynamic::model($this->iSurveyId)->getTableSchema(),$oCriteria)->queryScalar();

    if($iSum > 0){
        $aSumNumeric[$sColumn]=round($iSum);
    } else {
        $aSumNumeric[$sColumn]="";
    }
    return $aSumNumeric[$sColumn];
}   

It work on a V6.5.4 limesurveyVersion

DenisChenu

DenisChenu

2024-04-30 15:59

developer   ~80051

ping @tibor.pacalat

OK for a Pull Request ?

tibor.pacalat

tibor.pacalat

2024-04-30 16:05

administrator   ~80054

@DenisChenu not sure what you mean

DenisChenu

DenisChenu

2024-05-01 10:31

developer   ~80057

@tibor.pacalat : Did LimeSurvey GMBH are OK to have such feature in core plugin ? If yes : @jbarrouillet can prepare the Pull Request and i can review on github.

https://github.com/LimeSurvey/LimeSurvey/blob/master/CONTRIBUTING.md#submitting-changes

tibor.pacalat

tibor.pacalat

2024-05-02 10:11

administrator   ~80061

@DenisChenu yeah we can include this in core plugins, but it needs to have unit tests etc.

DenisChenu

DenisChenu

2024-05-02 10:12

developer   ~80062

@jbarrouillet : can you create a PR please ? I add the unit test on it after.

jbarrouillet

jbarrouillet

2024-05-02 11:15

reporter   ~80063

Hi @DenisChenu, yes i can, but i'm a newbe and i don't know what is a PR and how to create it.

jbarrouillet

jbarrouillet

2024-05-07 11:45

reporter   ~80081

@DenisChenu. PR --> Pull Request OK, I understand and i saw this option in gitub.com/Limesurvey project. I'm trying to move forward on this and be more efficient. :-)

DenisChenu

DenisChenu

2024-05-07 11:59

developer   ~80082

Sorry … unclear here :)

See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request

Issue History

Date Modified Username Field Change
2024-03-12 16:29 jbarrouillet New Issue
2024-03-12 16:29 jbarrouillet Issue Monitored: jbarrouillet
2024-03-12 16:29 jbarrouillet Bug heat 0 => 2
2024-03-12 17:50 DenisChenu Issue Monitored: DenisChenu
2024-03-12 17:50 DenisChenu Bug heat 2 => 4
2024-03-12 17:50 DenisChenu Bug heat 4 => 10
2024-04-30 15:55 jbarrouillet Note Added: 80050
2024-04-30 15:55 jbarrouillet Bug heat 10 => 12
2024-04-30 15:59 DenisChenu Note Added: 80051
2024-04-30 15:59 DenisChenu Bug heat 12 => 14
2024-04-30 16:05 tibor.pacalat Note Added: 80054
2024-04-30 16:05 tibor.pacalat Bug heat 14 => 16
2024-05-01 10:31 DenisChenu Note Added: 80057
2024-05-02 10:11 tibor.pacalat Note Added: 80061
2024-05-02 10:12 DenisChenu Note Added: 80062
2024-05-02 11:15 jbarrouillet Note Added: 80063
2024-05-07 11:45 jbarrouillet Note Added: 80081
2024-05-07 11:59 DenisChenu Note Added: 80082
2024-05-08 08:56 deforefoot Bug heat 16 => 18
2024-05-08 10:38 DenisChenu Bug heat 18 => 16