Skip to content

Commit

Permalink
New Feature Generate EM-Syntax-Highlighted Logic File for Surveys
Browse files Browse the repository at this point in the history
Dev Now shows all EM-related Question Attributes (since some can be parsed by EM - e.g. for min/max values)
Dev Now shows all Sub-Questions with their variable names.
Dev Only things now missing are: (a) Sub-Q-level relevance (from array_filter), (b) caching for speed optimization, (c) test Group and Q-level views, (d) Enable call from admin page, (e) Optionally specify which features want to show, (f) Optionally count errors by type (relevance, validation, text) - since survey can operate with text errors
Dev Also need to add other activation validation info - probably just a test that haven't re-used question.title

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev_tms@11638 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
TMSWhite committed Dec 11, 2011
1 parent 30ee13e commit aa330cb
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 15 deletions.
136 changes: 122 additions & 14 deletions classes/eval/LimeExpressionManager.php
Expand Up @@ -1426,6 +1426,8 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
'ansArray'=>$ansArray,
'scale_id'=>$scale_id,
'default'=>$defaultValue,
'rootVarName'=>$fielddata['title'],
'subqtext'=>(isset($fielddata['subquestion']) ? $fielddata['subquestion'] : ''),
);

$this->questionSeq2relevance[$questionSeq] = array(
Expand All @@ -1442,10 +1444,11 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
'mandatory'=>$mandatory,
'eqn'=>(($type == '*') ? $question : ''),
'help'=>$help,
'qtext'=>$question,
'qtext'=>$fielddata['question'], // $question,
'code'=>$varName,
'other'=>$other,
'default'=>$defaultValue,
'rootVarName'=>$fielddata['title'],
);

$this->knownVars[$varName] = $varInfo_Code;
Expand Down Expand Up @@ -1882,9 +1885,15 @@ private function _ProcessSubQRelevance($eqn,$questionNum=NULL,$rowdivid=NULL, $t
$relevanceVars = implode('|',$this->em->GetJSVarsUsed());
$relevanceJS = $this->em->GetJavaScriptEquivalentOfExpression();
$prettyPrintSQEqn='';
if (($this->debugLevel & LEM_PRETTY_PRINT_ALL_SYNTAX) == LEM_PRETTY_PRINT_ALL_SYNTAX) {
if ((($this->debugLevel & LEM_PRETTY_PRINT_ALL_SYNTAX) == LEM_PRETTY_PRINT_ALL_SYNTAX) ||
(($this->debugLevel & LEM_DEBUG_VALIDATION_DETAIL) == LEM_DEBUG_VALIDATION_DETAIL))
{
$prettyPrintSQEqn = $this->em->GetPrettyPrintString();
}
$hasErrors=false;
if ($this->em->HasErrors()) {
$hasErrors = true;
}
// $hasErrors = $this->em->HasErrors();
$this->subQrelInfo[] = array(
'qid' => $questionNum,
Expand All @@ -1898,6 +1907,7 @@ private function _ProcessSubQRelevance($eqn,$questionNum=NULL,$rowdivid=NULL, $t
'type'=>$type,
'qtype'=>$qtype,
'sgqa'=>$sgqa,
'hasErrors'=>$hasErrors,
);
}
return $result;
Expand Down Expand Up @@ -3437,7 +3447,8 @@ function _ValidateQuestion($questionSeq)
$validationJS = $LEM->em->GetJavaScriptEquivalentOfExpression();
}
$prettyPrintValidEqn = $stringToParse;
if (($LEM->debugLevel & LEM_PRETTY_PRINT_ALL_SYNTAX) == LEM_PRETTY_PRINT_ALL_SYNTAX)
if ((($this->debugLevel & LEM_PRETTY_PRINT_ALL_SYNTAX) == LEM_PRETTY_PRINT_ALL_SYNTAX) ||
(($this->debugLevel & LEM_DEBUG_VALIDATION_DETAIL) == LEM_DEBUG_VALIDATION_DETAIL))
{
$prettyPrintValidEqn = $LEM->em->GetPrettyPrintString();
}
Expand All @@ -3446,8 +3457,10 @@ function _ValidateQuestion($questionSeq)
// pretty-print them
$prettyPrintValidTip = $stringToParse;
$validTip = $LEM->ProcessString($stringToParse, $qid,NULL,false,1,1,false,false);
if (($LEM->debugLevel & LEM_PRETTY_PRINT_ALL_SYNTAX) == LEM_PRETTY_PRINT_ALL_SYNTAX) {
$prettyPrintValidTip = $LEM->GetLastPrettyPrintExpression();
if ((($this->debugLevel & LEM_PRETTY_PRINT_ALL_SYNTAX) == LEM_PRETTY_PRINT_ALL_SYNTAX) ||
(($this->debugLevel & LEM_DEBUG_VALIDATION_DETAIL) == LEM_DEBUG_VALIDATION_DETAIL))
{
$prettyPrintValidTip = $LEM->GetLastPrettyPrintExpression();
}
}
else
Expand Down Expand Up @@ -4903,10 +4916,62 @@ static public function ShowSurveyLogicFile($sid, $language=NULL, $gid=NULL, $qid
$default = (is_null($q['info']['default']) ? '' : '<p>(DEFAULT: ' . $q['info']['default'] . ')</p>');

$qtext = (($q['info']['qtext'] != '') ? $q['info']['qtext'] : '&nbsp');
$help = (($q['info']['help'] != '') ? '<p>[HELP: ' . $q['info']['help'] . ']</p>': '');
$prettyValidTip = (($q['prettyValidTip'] == '') ? '' : '<p>(TIP: ' . $q['prettyValidTip'] . ')</p>');
$help = (($q['info']['help'] != '') ? '<hr/>[HELP: ' . $q['info']['help'] . ']': '');
$prettyValidTip = (($q['prettyValidTip'] == '') ? '' : '<hr/>(TIP: ' . $q['prettyValidTip'] . ')');

// display question_attributes that are processed by EM
$attrTable = '';
if (isset($LEM->qattr[$qid]) && count($LEM->qattr[$qid]) > 0) {
$attrTable = "<hr/><table border='1'><tr><th>Attribute</th><th>Value</th></tr>\n";
$count=0;
foreach ($LEM->qattr[$qid] as $key=>$value) {
if (is_null($value) || trim($value) == '') {
continue;
}
switch ($key)
{
case 'exclude_all_others':
case 'exclude_all_others_auto':
case 'hidden':
if ($value == '0') {
$value = NULL; // so can skip this one - just using continue here doesn't work.
}
break;
case 'array_filter':
case 'array_filter_exclude':
case 'code_filter':
break;
case 'equals_num_value':
case 'max_answers':
case 'max_num_value':
case 'max_num_value_n':
case 'max_num_value_sgqa':
case 'min_answers':
case 'min_num_value':
case 'min_num_value_n':
case 'min_num_value_sgqa':
case 'multiflexible_max':
case 'multiflexible_min':
case 'num_value_equals_sgqa':
$value = '{' . $value . '}';
break;
case 'other_replace_text':
case 'show_totals':
break;
}
if (is_null($value)) {
continue; // since continuing from within a switch statement doesn't work
}
++$count;
$attrTable .= "<tr><td>$key</td><td>$value</td></tr>\n";
}
$attrTable .= "</table>\n";
if ($count == 0) {
$attrTable = '';
}
}

$LEM->ProcessString($qtext . $help . $prettyValidTip, $qid,NULL,false,1,1,false,false);
$LEM->ProcessString($qtext . $help . $prettyValidTip . $attrTable, $qid,NULL,false,1,1,false,false);
$qdetails = $LEM->GetLastPrettyPrintExpression();
if ($LEM->em->HasErrors()) {
++$errorCount;
Expand All @@ -4924,17 +4989,58 @@ static public function ShowSurveyLogicFile($sid, $language=NULL, $gid=NULL, $qid
$prettyValidEqn = '';
if ($q['prettyValidEqn'] != '') {
$LEM->em->ProcessBooleanExpression($q['prettyValidEqn'], $gseq, $qseq);
$prettyValidEqn = '<p>(VALIDATION: ' . $LEM->em->GetPrettyPrintString() . ')</p>';
$prettyValidEqn = '<hr/>(VALIDATION: ' . $LEM->em->GetPrettyPrintString() . ')';
if ($LEM->em->HasErrors()) {
++$errorCount;
}
}

$rootVarName = $q['info']['rootVarName'];

// Show all sub-questions
$sgqas = explode('|',$q['sgqa']);
$sqRows='';
$i=0;
foreach ($sgqas as $sgqa)
{
if ($LEM->knownVars[$sgqa]['qcode'] == $rootVarName) {
continue;
}
++$i;
// Have to do full scan of array each time - fix this.
$subQeqn = '&nbsp;';
foreach ($LEM->subQrelInfo as $sq) {
if ($sq['sgqa'] == $sgqa) {
$subQeqn = '{' . $sq['eqn'] . '}'; // $sq['prettyPrintEqn'];
if ($LEM->em->HasErrors()) {
++$errorCount;
}
break;
}
}

// $subqText = $LEM->knownVars[$sgqa]['question'];
$sgqaInfo = $LEM->knownVars[$sgqa];
$subqText = $sgqaInfo['subqtext'];

$sqRows .= "<tr class='LEMsubq'>"
. "<td>SQ-$i</td>"
. "<td>{" . $LEM->knownVars[$sgqa]['qcode'] . "}</td>"
. "<td>$subQeqn</td>"
. "<td>" .$subqText . "</td>"
. "</tr>";
}
$LEM->ProcessString($sqRows, $qid,NULL,false,1,1,false,false);
$sqRows = $LEM->GetLastPrettyPrintExpression();
if ($LEM->em->HasErrors()) {
++$errorCount;
}

// Show answer options for enumerated lists
$answerRows='';
if (isset($LEM->qans[$qid]))
{
$_scale=-1;
$answerRows = '';
foreach ($LEM->qans[$qid] as $ans=>$value)
{
$ansInfo = explode('~',$ans);
Expand All @@ -4947,27 +5053,29 @@ static public function ShowSurveyLogicFile($sid, $language=NULL, $gid=NULL, $qid
}
$answerRows .= "<tr class='LEManswer'>"
. "<td>A[" . $ansInfo[0] . "]-" . $i++ . "</td>"
. "<td>" . $ansInfo[1]. "</td>"
. "<td><b>" . $ansInfo[1]. "</b></td>"
. "<td>[VALUE: " . $valInfo[0] . "]</td>"
. "<td>" . $valInfo[1] . "</td>"
. "</tr>\n";
}
$LEM->ProcessString($answerRows, $qid,NULL,false,1,1,false,false);
$out .= $LEM->GetLastPrettyPrintExpression();
$answerRows = $LEM->GetLastPrettyPrintExpression();
if ($LEM->em->HasErrors()) {
++$errorCount;
}
}
$errclass = ($errorCount > 0) ? "class='LEMerror' title='This question has at least $errorCount error(s)'" : '';

$questionRow = "<tr>"
$questionRow = "<tr class='LEMquestion'>"
. "<td $errclass>Q-" . $q['info']['qseq'] . "</td>"
. "<td><b>" . $mandatory . $q['info']['code'] . "</b><br/>[<a target='_blank' href='$rooturl/admin/admin.php?sid=$sid&gid=$gid&qid=$qid'>QID $qid</a>]<br/>$typedesc [$type]</td>"
. "<td><b>" . $mandatory . $rootVarName . "</b><br/>[<a target='_blank' href='$rooturl/admin/admin.php?sid=$sid&gid=$gid&qid=$qid'>QID $qid</a>]<br/>$typedesc [$type]</td>"
. "<td>" . $relevance . $prettyValidEqn . $default . "</td>"
. "<td>" . $qdetails . "</td>"
. "</tr>\n";

$out .= $questionRow;
$out .= $sqRows;
$out .= $answerRows;

if ($errorCount > 0) {
$allErrors[$gid . '~' . $qid] = $errorCount;
Expand Down
12 changes: 11 additions & 1 deletion classes/eval/test/survey_logic_file.php
Expand Up @@ -81,19 +81,29 @@
<style type="text/css">
tr.LEMgroup td
{
background-color:lightgrey;
}
tr.LEMquestion
{
background-color:#EAF2D3;
}
tr.LEManswer td
{
background-color:lightgrey;
background-color:white;
}
.LEMerror
{
color:red;
font-weight:bold;
}
tr.LEMsubq td
{
background-color:lightyellow;
}
</style>
</head>
<body>
Expand Down

0 comments on commit aa330cb

Please sign in to comment.