Skip to content

Commit

Permalink
Fixed issue #08308: questions that nothing depends upon trigger the r…
Browse files Browse the repository at this point in the history
…eevaluation of every conditionnal expression in the survey

Dev: added a check for question condition
  • Loading branch information
LouisGac committed Aug 24, 2016
1 parent 33bd01e commit 317b1f2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
11 changes: 10 additions & 1 deletion application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ function run($surveyid,$args)
doFooter();

}

/**
* setJavascriptVar
*
Expand All @@ -1415,12 +1416,20 @@ public function setJavascriptVar($iSurveyId)
$aLSJavascriptVar['bNumRealValue']=(int)(bool)Yii::app()->getConfig('bNumRealValue',0);
$aRadix=getRadixPointData($aSurveyinfo['surveyls_numberformat']);
$aLSJavascriptVar['sLEMradix']=$aRadix['separator'];


$aCfieldnameWithDependences = Condition::model()->getAllCfieldnameWithDependenciesForOneSurvey($iSurveyId);
foreach($aCfieldnameWithDependences as $sCfieldname)
{
$aLSJavascriptVar['aFieldWithDependencies'][] = $sCfieldname;
}

$sLSJavascriptVar="LSvar=".json_encode($aLSJavascriptVar) . ';';
App()->clientScript->registerScript('sLSJavascriptVar',$sLSJavascriptVar,CClientScript::POS_HEAD);
}
// Maybe remove one from index and allow empty $surveyid here.
}

/**
* Construction of replacement array, actually doing it with redata
*
Expand Down
26 changes: 19 additions & 7 deletions application/models/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function primaryKey()
*/
public function relations()
{
$alias = $this->getTableAlias();
$alias = $this->getTableAlias();
return array(
'questions' => array(self::HAS_ONE, 'Question', '',
'on' => "$alias.cqid = questions.qid",
Expand Down Expand Up @@ -95,7 +95,7 @@ public function deleteRecords($condition=FALSE)

/**
* Updates the group ID for all conditions
*
*
* @param integer $iSurveyID
* @param integer $iQuestionID
* @param integer $iOldGroupID
Expand All @@ -118,8 +118,8 @@ public function updateCFieldName($iSurveyID, $iQuestionID, $iOldGroupID, $iNewGr
}
}



public function insertRecords($data, $update=FALSE, $condition=FALSE)
{
$record = new self;
Expand Down Expand Up @@ -149,15 +149,15 @@ public function insertRecords($data, $update=FALSE, $condition=FALSE)
else
return $record->save();
}

function getScenarios($qid)
{

$scenarioquery = "SELECT DISTINCT scenario FROM ".$this->tableName()." WHERE qid=".$qid." ORDER BY scenario";

return Yii::app()->db->createCommand($scenarioquery)->query();
}

function getSomeConditions($fields, $condition, $order, $group){
$record = Yii::app()->db->createCommand()
->select($fields)
Expand All @@ -175,7 +175,7 @@ function getSomeConditions($fields, $condition, $order, $group){

return $record->query();
}

function getConditionsQuestions($distinctrow,$deqrow,$scenariorow,$surveyprintlang)
{
$conquery="SELECT cid, cqid, q.title, q.question, value, q.type, cfieldname "
Expand All @@ -192,6 +192,18 @@ function getConditionsQuestions($distinctrow,$deqrow,$scenariorow,$surveyprintla
->bindParam(":surveyprintlang", $surveyprintlang, PDO::PARAM_STR)
->query();
}

function getAllCfieldnameWithDependenciesForOneSurvey($sid)
{
$Qids = Yii::app()->db->createCommand()
->select('cfieldname')
->from('{{questions}} questions')
->join('{{conditions}} conditions', 'questions.qid=conditions.cqid')
->where('sid=:sid', array(':sid'=>$sid))
->queryRow();

return $Qids;
}
}

?>
11 changes: 7 additions & 4 deletions scripts/survey_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ function checkconditions(value, name, type, evt_type)
{
$('#java'+name).val(value);
}
if($.isFunction(window.ExprMgr_process_relevance_and_tailoring ))

$isRelevant = $.inArray(name, LSvar.aFieldWithDependencies);

if($.isFunction(window.ExprMgr_process_relevance_and_tailoring ) && $isRelevant!=-1)
ExprMgr_process_relevance_and_tailoring(evt_type,name,type);
}

Expand Down Expand Up @@ -599,13 +602,13 @@ function doToolTipTable()
}
});
}
//Hide the Answer and the helper field in an
//Hide the Answer and the helper field in an
$(document).ready(
function(){
$('.question-container').each(function(){
if($(this).find('div.answer-container').find('input').length == 1)
{
if($(this).find('div.answer-container').find('input[type=hidden]').length >0
if($(this).find('div.answer-container').find('input[type=hidden]').length >0
&& $(this).find('div.answer-container').find('select').length < 1)
{
$(this).find('div.answer-container').css({display: 'none'});
Expand All @@ -617,4 +620,4 @@ $(document).ready(
}
});
}
);
);

2 comments on commit 317b1f2

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok with condition in DB, but what with relevance EM equation directly ?

@LouisGac
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see: only the conditions set with the condition manager have entries in the DB....

Please sign in to comment.