Skip to content

Commit

Permalink
Dev: Fix save for dual scale answer options
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Jun 5, 2018
1 parent d8ae3b7 commit d59525e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
30 changes: 11 additions & 19 deletions application/controllers/admin/questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,22 +505,17 @@ public function _editansweroptions($surveyid, $gid, $qid)

}


// Check that there are answers for every language supported by the survey
for ($i = 0; $i < $scalecount; $i++) {
foreach ($oQuestion->answers as $oAnswer){
foreach ($oSurvey->allLanguages as $language) {
if (!isset($oAnswer->answerL10ns[$language])) {
$baseL10n = $oAnswer->answerL10ns[$oSurvey->language];
$oAnswerL10n = new AnswerL10n();
$oAnswerL10n->attributes = $baseL10n->attributes;
$oAnswerL10n->language = $language;
$oAnswerL10n->answer = "";
$oAnswerL10n->save();
}

foreach ($oQuestion->answers as $oAnswer){
foreach ($oSurvey->allLanguages as $language) {
if (!isset($oAnswer->answerL10ns[$language])) {
$baseL10n = $oAnswer->answerL10ns[$oSurvey->language];
$oAnswerL10n = new AnswerL10n();
$oAnswerL10n->attributes = $baseL10n->attributes;
$oAnswerL10n->language = $language;
$oAnswerL10n->answer = "";
$oAnswerL10n->save();
}

}
}

Expand Down Expand Up @@ -583,9 +578,8 @@ public function _editansweroptions($surveyid, $gid, $qid)
$criteria->params = array(':qid' => $qid, ':scale_id' => $scale_id);
$results[$anslang][$scale_id] = Answer::model()->findAll($criteria);
//$aData['tableId'][$anslang][$scale_id] = 'answers_'.$anslang.'_'.$scale_id;
foreach ($results[$anslang][$scale_id] as &$row) {
$row->code = htmlspecialchars($row->code);
//$row->answerL10ns[$anslang]->answer = htmlspecialchars($row->answerL10ns[$anslang]->answer);
foreach ($results[$anslang][$scale_id] as $row) {
$aData['tableId'][$anslang][$scale_id] = 'answers_'.$anslang.'_'.$scale_id;
}
}
}
Expand All @@ -595,8 +589,6 @@ public function _editansweroptions($surveyid, $gid, $qid)
$aData['formId'] = 'editanswersform';
$aData['formName'] = 'editanswersform';
$aData['pageTitle'] = gT('Edit answer options');
$aData['tableId'] = 'answer-option-table';


$aViewUrls['_subQuestionsAndAnwsersJsVariables'][] = $aData;
$aViewUrls['answerOptions_view'][] = $aData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,4 @@
</div>
<input type='hidden' id='bFullPOST' name='bFullPOST' value='1' />



19 changes: 18 additions & 1 deletion application/views/admin/survey/Question/answerOptions_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@

//echo "<pre>"; var_dump($results); die;

$aData = array(
'surveyid' => $surveyid,
'gid' => $gid,
'qid' => $qid,
'viewType' => $viewType,
'anslangs' => $anslangs,
'scalecount' => $scalecount,
'results' => $results,
'tableId' => $tableId,
'activated' => $activated,
'assessmentvisible' => (empty($assessmentvisible)) ? false : $assessmentvisible,
'base_language' => $base_language,
'has_permissions' => Permission::model()->hasGlobalPermission('superadmin','read') || Permission::model()->hasGlobalPermission('labelsets','create'),
'all_languages' => Survey::model()->findByPk($surveyid)->getAllLanguages()
);

/*
$aData = array(
'anslangs' => $anslangs,
'results' => $results,
Expand All @@ -52,7 +69,7 @@
'has_permissions' => Permission::model()->hasGlobalPermission('superadmin','read') || Permission::model()->hasGlobalPermission('labelsets','create'),
'all_languages' => Survey::model()->findByPk($surveyid)->getAllLanguages()
);

*/

echo App()->twigRenderer->renderAnswerOptions('/admin/survey/Question/answerOptionsEdit_view', $aData); ?>

Expand Down
9 changes: 5 additions & 4 deletions assets/scripts/admin/answers.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,11 @@ function updaterowproperties()
var qID=$('input[name=qid]').val();

$('.answertable tbody').each(function(){
info=$(this).closest('table').attr('id').split("_");
language=info[1];
scale_id=info[2];
var rownumber=1;
var id = $(this).closest('table').attr('id');
var info = id.split("_");
var language = info[1];
var scale_id = info[2];
var rownumber = 1;

$(this).children('tr').each(function(){

Expand Down

0 comments on commit d59525e

Please sign in to comment.