Skip to content

Commit

Permalink
Dev Added count() function to EM to count number of answered (non-nul…
Browse files Browse the repository at this point in the history
…l) questions.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11272 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
TMSWhite committed Oct 26, 2011
1 parent 9eb92df commit 00ad073
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -131,6 +131,7 @@ function __construct()
'ceil' => array('ceil', 'Math.ceil', 'Round fractions up', 'number ceil(number)', 'http://www.php.net/manual/en/function.ceil.php', 1),
'checkdate' => array('checkdate', 'checkdate', 'Returns true(1) if it is a valid date in gregorian calendar', 'bool checkdate(month,day,year)', 'http://www.php.net/manual/en/function.checkdate.php', 3),
'cos' => array('cos', 'Math.cos', 'Cosine', 'number cos(number)', 'http://www.php.net/manual/en/function.cos.php', 1),
'count' => array('exprmgr_count', 'LEMcount', 'Count the number of answered questions in the list', 'number count(arg1, arg2, ... argN)', '', -1),
'date' => array('date', 'date', 'Format a local date/time', 'string date(format [, timestamp=time()])', 'http://www.php.net/manual/en/function.date.php', 1,2),
'exp' => array('exp', 'Math.exp', 'Calculates the exponent of e', 'number exp(number)', 'http://www.php.net/manual/en/function.exp.php', 1),
'floor' => array('floor', 'Math.floor', 'Round fractions down', 'number floor(number)', 'http://www.php.net/manual/en/function.floor.php', 1),
Expand Down Expand Up @@ -2336,6 +2337,9 @@ static function UnitTestEvaluator()
10~ceil(9.1)
9~floor(9.9)
15~sum(one,two,three,four,five)
5~count(one,two,three,four,five)
0~a='',b='',c=0
1~count(a,b,c)
5~intval(5.7)
1~is_float(pi())
0~is_float(5)
Expand Down Expand Up @@ -2634,6 +2638,23 @@ function cmpErrorTokens($a, $b)
return ($a[1][1] < $b[1][1]) ? -1 : 1;
}

/**
* Count the number of answered questions (non-empty)
* @param <type> $args
* @return int
*/
function exprmgr_count($args)
{
$j=0; // keep track of how many non-null values seen
foreach ($args as $arg)
{
if ($arg != '') {
++$j;
}
}
return $j;
}

/**
* If $test is true, return $ok, else return $error
* @param <type> $test
Expand Down
13 changes: 13 additions & 0 deletions scripts/admin/expressions/em_javascript.js
Expand Up @@ -2,6 +2,19 @@
* @author Thomas M. White
*/

function LEMcount()
{
// takes variable number of arguments
var result=0;
for (i=0;i<arguments.length;++i) {
var arg = arguments[i];
if (arg !== '') {
++result;
}
}
return result;
}

function LEMpi()
{
return Math.PI;
Expand Down

0 comments on commit 00ad073

Please sign in to comment.