Skip to content

Commit

Permalink
Fixed issue #18191: Cannot use statCount in specific condition (#3056)
Browse files Browse the repository at this point in the history
* Fixed issue #18191: Cannot use statCount in specific condition
Dev: add a surveyid checker : is set + survey exist + survey is active

* Dev: fix oups …

* Dev: add a getCurrentSurveyid in API

* Dev: oups on return value
  • Loading branch information
Shnoulle committed Apr 19, 2023
1 parent f8cb2b2 commit 7c2db40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions application/core/plugins/statFunctions/config.xml
Expand Up @@ -4,10 +4,10 @@
<name>statFunctions</name>
<type>plugin</type>
<creationDate>2019-09-19</creationDate>
<last_update>2022-04-01</last_update>
<last_update>2022-09-30</last_update>
<author>Denis Chenu</author>
<authorUrl>https://www.limesurvey.org</authorUrl>
<version>0.2.0</version>
<version>0.2.1</version>
<license>GNU General Public License version 2 or later</license>
<description><![CDATA[New function for expression manager to count some statictics data : <ul>
<li>statCountIf(QuestionCode.sgqa, value[, submitted = true][, self = true])</li>
Expand Down
13 changes: 8 additions & 5 deletions application/core/plugins/statFunctions/countFunctions.php
Expand Up @@ -2,7 +2,7 @@

/**
* This file is part of statFunctions plugin
* @version 0.2.0
* @version 0.2.1
*/

namespace statFunctions;
Expand All @@ -14,6 +14,7 @@
use SurveyDynamic;
use CDbCriteria;
use Permission;
use LimeSurvey\PluginManager\LimesurveyApi as LimesurveyApi;

class countFunctions
{
Expand All @@ -27,8 +28,9 @@ class countFunctions
*/
public static function statCountIf($qCode, $comparaison, $submitted = true, $self = true)
{
$surveyId = LimeExpressionManager::getLEMsurveyId();
if (!Survey::model()->findByPk($surveyId)->getIsActive()) {
$api = new LimesurveyApi();
$surveyId = $api->getCurrentSurveyid(true);
if (!$surveyId) {
return 0;
}
$questionCodeHelper = new \statFunctions\questionCodeHelper($surveyId);
Expand Down Expand Up @@ -62,8 +64,9 @@ public static function statCountIf($qCode, $comparaison, $submitted = true, $sel
*/
public static function statCount($qCode, $submitted = true, $self = true)
{
$surveyId = LimeExpressionManager::getLEMsurveyId();
if (!Survey::model()->findByPk($surveyId)->getIsActive()) {
$api = new LimesurveyApi();
$surveyId = $api->getCurrentSurveyid(true);
if (!$surveyId) {
return 0;
}
$questionCodeHelper = new \statFunctions\questionCodeHelper($surveyId);
Expand Down
23 changes: 22 additions & 1 deletion application/libraries/PluginManager/LimesurveyApi.php
Expand Up @@ -233,6 +233,27 @@ public function getResponse($surveyId, $responseId, $bMapQuestionCodes = true)
}
}

/**
* Get the current survey in current oage
* @param boolean $onlyactivated return it only if activated
* @return false|integer
*/
public function getCurrentSurveyid($onlyactivated = false)
{
$surveyId = \LimeExpressionManager::getLEMsurveyId();
if (empty($surveyId)) {
return false;
}
$survey = \Survey::model()->findByPk($surveyId);
if (!$survey) {
return false;
}
if ($onlyactivated && !$survey->getIsActive()) {
return false;
}
return $surveyId;
}

/**
* Get the current Response
* @param integer $surveyId
Expand All @@ -241,7 +262,7 @@ public function getResponse($surveyId, $responseId, $bMapQuestionCodes = true)
public function getCurrentResponses($surveyId = null)
{
if (empty($surveyId)) {
$surveyId = \LimeExpressionManager::getLEMsurveyId();
$surveyId = $this->getCurrentSurveyid();
}
if (empty($surveyId)) {
return;
Expand Down

0 comments on commit 7c2db40

Please sign in to comment.