Commit 40b4f279 authored by Denis Chenu's avatar Denis Chenu

[fix] Question attribute 'equation' is not used

[fix] Unable to use it in 2.6 with 'urlFormat' => 'get',
parent 0fc8e4b8
......@@ -20,7 +20,7 @@
$(function() {
if(typeof recomputeVar!='undefined'){
addUpdateResponse();
addUpdateResponse();
}
});
......@@ -29,17 +29,11 @@ function addUpdateResponse()
var docUrl=document.URL;
var jsonUrl=recomputeVar.jsonurl;
var aUrl=docUrl.split('/');
var surveyid=aUrl[aUrl.indexOf("surveyid")+1];
if(aUrl.indexOf("admin")>0){
var controller=aUrl[aUrl.indexOf("admin")+1];
}else{
var controller=aUrl[aUrl.indexOf("?r=admin")+1];
}
var surveyid=recomputeVar.surveyId;
var responseId=recomputeVar.responseId;
if($('table.detailbrowsetable').length>0)// Browse one response
if(responseId && $('table.detailbrowsetable').length>0)// Browse one response
{
// Find the response id
var responseId=aUrl[aUrl.indexOf("id")+1];
// OR var responseId= aUrl.pop();
$('.menubar').eq(1).find('.menubar-main').find(".menubar-left:last").append("<a class='btn btn-small updateanswer' data-responseid='"+responseId+"'><i class='icon-refresh'></i>Update This Answer</a>");
$('.updateanswer').click(function(){
......@@ -83,7 +77,7 @@ function addUpdateResponse()
});
});
}
if(controller=='responses'){
if(surveyid){
$('.menubar').eq(0).find('.menubar-main').find(".menubar-left:last").append("<a class='btn btn-small updateanswers'><i class='icon-refresh'></i>Update all submitted answers</a>");
$(".updateanswers").click(function(){
var jsonurl=$(this).attr('rel');
......
......@@ -62,9 +62,13 @@
public function afterPluginLoad()
{
if(strpos(Yii::app()->request->getRequestUri(),'admin/responses')){// Hack to register only on browse response
$surveyid = Yii::app()->request->getparam('surveyid');
$responseid = Yii::app()->request->getparam('id');
$aRecomputeVar=array(
'jsonurl'=>$this->api->createUrl('plugins/direct', array('plugin' => 'recomputeExpression', 'function' => 'recompute'))
);
'jsonurl'=>$this->api->createUrl('plugins/direct', array('plugin' => 'recomputeExpression', 'function' => 'recompute')),
'surveyId'=>$surveyid,
'responseId'=>$responseid,
);
Yii::app()->getClientScript()->registerScript('aRecomputeVar','recomputeVar='.json_encode($aRecomputeVar),CClientScript::POS_BEGIN);
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('publicurl')."plugins/recomputeExpression/js/recompute.js");
}
......@@ -146,7 +150,7 @@
{
$iResponseId=$oResponse->id;
$aOldAnswers=$oResponse->attributes; // Not needed but keep it
if(isset($oResponse->token) && $oResponse->token)
$sToken=$oResponse->token;
// Fill $_SESSION['survey_'.$iSurveyId]
......@@ -231,7 +235,12 @@
{
//($string, $questionNum=NULL, $replacementFields=array(), $debug=false, $numRecursionLevels=1, $whichPrettyPrintIteration=1, $noReplacements=false, $timeit=true, $staticReplacement=false)
$oldVal=$oResponse->$column;
$newVal=$oResponse->$column=LimeExpressionManager::ProcessString($aFieldMap[$column]['question'], null, array(), false, 1, 0, false, false, true);
$equation = $aFieldMap[$column]['question'];
$equationAttribute = QuestionAttribute::model()->find("qid = :qid and attribute = :attribute",array(":qid"=>$aFieldMap[$column]['qid'],":attribute"=>'equation'));
if(!empty($equationAttribute) && !empty($equationAttribute->value)) {
$equation = $equationAttribute->value;
}
$newVal=$oResponse->$column=LimeExpressionManager::ProcessString($equation, null, array(), false, 1, 0, false, false, true);
if($oldVal!=$newVal && ($oldVal && $newVal))
{
$updatedValues['old'][$sColumnName]=$oldVal;
......@@ -285,4 +294,4 @@
die();
}
}
?>
\ No newline at end of file
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment