-
Notifications
You must be signed in to change notification settings - Fork 988
/
countFunctions.php
77 lines (73 loc) · 2.98 KB
/
countFunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* This file is part of statFunctions plugin
*/
namespace statFunctions;
use Yii;
use CHtml;
use LimeExpressionManager;
use Survey;
use SurveyDynamic;
use CDbCriteria;
use Permission;
class countFunctions
{
/**
* Return the count of reponse on current ExpressionScript Engine survey equal to a specific value
* @param string $qCode : code of question, currently must be existing sgqa. Sample Q01.sgqa.
* @param string $comparaison : comparre with value. Can use < or > … see https://www.yiiframework.com/doc/api/1.1/CDbCriteria#compare-detail
* @param boolean $submitted (or not) response
* @return integer|string
*/
public static function statCountIf($qCode, $comparaison, $submitted = true)
{
$surveyId = LimeExpressionManager::getLEMsurveyId();
if (!Survey::model()->findByPk($surveyId)->getIsActive()) {
return 0;
}
$questionCodeHelper = new \statFunctions\questionCodeHelper($surveyId);
$column = $questionCodeHelper->getColumnByQCode($qCode);
if (is_null($column)) {
if (Permission::model()->hasSurveyPermission($surveyId, 'surveycontent')) { // update ???
return sprintf(gT("Invalid question code %s"), CHtml::encode($qCode));
}
return "";
}
$sQuotedColumn=Yii::app()->db->quoteColumnName($column);
$oCriteria = new CDbCriteria;
$oCriteria->condition= "$sQuotedColumn IS NOT NULL";
if ($submitted) {
$oCriteria->addCondition("submitdate IS NOT NULL");
}
$oCriteria->compare($sQuotedColumn, $comparaison);
return intval(SurveyDynamic::model($surveyId)->count($oCriteria));
}
/**
* Return the count of reponse on current ExpressionScript Engine survey equal to a specific value
* @param string $qCode : code of question, currently must be existing sgqa. Sample Q01.sgqa.
* @param boolean $submitted (or not) response
* @return integer|string
*/
public static function statCount($qCode, $submitted = true)
{
$surveyId = LimeExpressionManager::getLEMsurveyId();
if (!Survey::model()->findByPk($surveyId)->getIsActive()) {
return 0;
}
$questionCodeHelper = new \statFunctions\questionCodeHelper($surveyId);
$column = $questionCodeHelper->getColumnByQCode($qCode);
if (is_null($column)) {
if (Permission::model()->hasSurveyPermission($surveyId, 'surveycontent')) { // update ???
return sprintf(gT("Invalid question code %s"), CHtml::encode($qCode));
}
return "";
}
$sQuotedColumn=Yii::app()->db->quoteColumnName($column);
$oCriteria = new CDbCriteria;
$oCriteria->condition= "$sQuotedColumn IS NOT NULL and $sQuotedColumn <> ''";
if ($submitted) {
$oCriteria->addCondition("submitdate IS NOT NULL");
}
return intval(SurveyDynamic::model($surveyId)->count($oCriteria));
}
}