Skip to content

Commit

Permalink
New feature #05983 : allow different value in Database tha shown in E…
Browse files Browse the repository at this point in the history
…quation question type

Dev: this way : no specific system for Equation getQuestionReplacement
Dev: Answer is in answer art, question in question part.
  • Loading branch information
Shnoulle committed Mar 12, 2015
1 parent 1ba1c74 commit 5485367
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 0 additions & 4 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -1269,10 +1269,6 @@ public static function getQuestionReplacement($aQuestionQanda)
$aReplacement['QUESTION']=$aQuestionQanda[0]['all'] ; // Deprecated : only used in old template (very old)
// Core value : user text
$aReplacement['QUESTION_TEXT'] = $aQuestionQanda[0]['text'];
if ($sType == '*')
{
$aReplacement['QUESTION_TEXT'] = '<div class="em_equation">' .$aReplacement['QUESTION_TEXT']. '</div>';
}
$aReplacement['QUESTIONHELP']=$lemQuestionInfo['info']['help'];// User help
// To be moved in a extra plugin : QUESTIONHELP img adding
$sTemplateDir=Template::model()->getTemplatePath($oSurveyId->template);
Expand Down
9 changes: 9 additions & 0 deletions application/helpers/common_helper.php
Expand Up @@ -2809,6 +2809,15 @@ function questionAttributes($returnByName=false)
"help"=>gT('Enter a header text for the second scale'),
"caption"=>gT('Header for second scale'));

$qattributes["equation"]=array(
"types"=>"*",
'category'=>gT('Logic'),
'sortorder'=>100,
'inputtype'=>'textarea',
"help"=>gT('Final equation to set in database, default to question text.'),
"caption"=>gT('Equation'),
"default"=>"");

$qattributes["equals_num_value"]=array(
"types"=>"K",
'category'=>gT('Input'),
Expand Down
13 changes: 6 additions & 7 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -4038,7 +4038,7 @@ private function setVariableAndTokenMappingsForExpressionManager($surveyid,$forc
'hidden'=>$hidden,
'gid'=>$groupNum,
'mandatory'=>$mandatory,
'eqn'=>(($type == '*') ? $question : ''),
'eqn'=>'',
'help'=>$help,
'qtext'=>$fielddata['question'], // $question,
'code'=>$varName,
Expand Down Expand Up @@ -6565,7 +6565,8 @@ function _ValidateQuestion($questionSeq,$force=false)
elseif ($qInfo['type'] == '*')
{
// Process relevant equations, even if hidden, and write the result to the database
$result = flattenText($LEM->ProcessString($qInfo['eqn'], $qInfo['qid'],NULL,false,1,1,false,false));
$textToParse=(isset($LEM->qattr[$qid]['equation']) && trim($LEM->qattr[$qid]['equation'])!="") ? $LEM->qattr[$qid]['equation'] : $qInfo['qtext'];
$result = flattenText($LEM->ProcessString($textToParse, $qInfo['qid'],NULL,false,1,1,false,false,true));// More numRecursionLevels ?
$sgqa = $LEM->qid2code[$qid]; // there will be only one, since Equation
if($LEM->knownVars[$sgqa]['onlynum'])
{
Expand Down Expand Up @@ -7312,11 +7313,9 @@ static function GetRelevanceAndTailoringJavaScript()
{
$relParts[] = " // Write value from the question into the answer field\n";
$jsResultVar = $LEM->em->GetJsVarFor($arg['jsResultVar']);
// Note, this will destroy embedded HTML in the equation (e.g. if it is a report)
// Should be possible to use jQuery to remove just the LEMtailoring span, but not easy since done (the following doesn't work)
// _tmpval = $('#question801 .em_equation').clone()
// $(_tmpval).find('[id^=LEMtailor]').each(function(){ $(this).replaceWith(function(){ $(this).contents; }); })
$relParts[] = " $('#" . substr($jsResultVar,1,-1) . "').val($.trim(LEMstrip_tags($('#question" . $arg['qid'] . " .em_equation').html())));\n";
// Note, this will destroy embedded HTML in the equation (e.g. if it is a report, can use {QCODE.question} for this purpose)
// This make same than flattenText to be same in JS and in PHP
$relParts[] = " $('#" . substr($jsResultVar,1,-1) . "').val($.trim($('#question" . $arg['qid'] . " .em_equation').text()));\n";
}
$relParts[] = " relChange" . $arg['qid'] . "=true;\n"; // any change to this value should trigger a propagation of changess
$relParts[] = " $('#relevance" . $arg['qid'] . "').val('1');\n";
Expand Down
13 changes: 6 additions & 7 deletions application/helpers/qanda_helper.php
Expand Up @@ -857,7 +857,7 @@ function return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $an

function do_boilerplate($ia)
{
$aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]);

$answer='';

if (trim($aQuestionAttributes['time_limit'])!='')
Expand All @@ -873,16 +873,15 @@ function do_boilerplate($ia)

function do_equation($ia)
{
$aQuestionAttributes= getQuestionAttributeValues($ia[0], $ia[4]);
$sEquation=(trim($aQuestionAttributes['equation'])) ? $aQuestionAttributes['equation'] : $ia[3];
$answer='<input type="hidden" name="'.$ia[1].'" id="java'.$ia[1].'" value="';
if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]))
{
$answer .= htmlspecialchars($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]],ENT_QUOTES);
}
$answer .= htmlspecialchars($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]],ENT_QUOTES);
$answer .= '">';
$answer .="<div class='em_equation hidden' style='display:none;visibility:hidden'>{$sEquation}</div>";
$inputnames[]=$ia[1];
$mandatory=null;

return array($answer, $inputnames, $mandatory);
return array($answer, $inputnames);
}

// ---------------------------------------------------------------
Expand Down

0 comments on commit 5485367

Please sign in to comment.