Skip to content

Commit

Permalink
Dev: Re-fix issue #09828 : adding subquestion multiple times update m…
Browse files Browse the repository at this point in the history
…ax_subquestions

Dev: Adding attribute only if not exist
Dev: related d09e6d4#diff-4c8b6e0396ccd2f7fad4f57489b63b06L156 and #507
  • Loading branch information
Shnoulle authored and LouisGac committed Aug 28, 2017
1 parent 61a2b94 commit 40df2b9
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,34 @@ private function actionUpdateAnswerOptions($iSurveyID)
array(':qid' => $this->iQuestionID)
);

$answerCount=Answer::model()->countByAttributes(array('qid' => $this->iQuestionID,'language'=>$survey->language));
$oQuestionAttribute = new QuestionAttribute();
$oQuestionAttribute->qid = $this->iQuestionID;
$oQuestionAttribute->attribute = 'max_subquestions';
$oQuestionAttribute->value = $answerCount;
$oQuestionAttribute->save();

}
if ($sAction == "updateansweroptions" && Permission::model()->hasSurveyPermission($iSurveyID, 'surveycontent','update'))

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Aug 28, 2017

Author Collaborator

Seems this readd this line :/ still used ? The original fix are really lighter

{
Yii::app()->loadHelper('database');
$aSurveyLanguages = Survey::model()->findByPk($iSurveyID)->additionalLanguages;
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
array_unshift($aSurveyLanguages,$sBaseLanguage);
$arQuestion = Question::model()->findByAttributes(array('qid'=>$iQuestionID));
$sQuestionType = $arQuestion['type']; // Checked)
$aQuestionTypeList=getQuestionTypeList('','array');
$iScaleCount=$aQuestionTypeList[$sQuestionType]['answerscales'];
/* for already activated survey and rank question type : fix the maxDbAnswer before deleting answers */
/* @todo : add it to upgrage DB system, and see for the lsa */
if($sQuestionType=="R" && Survey::model()->findByPk($iSurveyID)->active=="Y")
{
$oQuestionAttributeMaxSubQuestions = QuestionAttribute::model()->find(
"qid = :qid AND attribute = 'max_subquestions'",
array(':qid' => $iQuestionID)
);
if(!$oQuestionAttributeMaxSubQuestions) {
$answerCount=Answer::model()->countByAttributes(array('qid' => $iQuestionID,'language'=>Survey::model()->findByPk($iSurveyID)->language));
$oQuestionAttributeMaxSubQuestions = new QuestionAttribute();
$oQuestionAttributeMaxSubQuestions->qid = $iQuestionID;
$oQuestionAttributeMaxSubQuestions->attribute = 'max_subquestions';
$oQuestionAttributeMaxSubQuestions->value = $answerCount;
$oQuestionAttributeMaxSubQuestions->save();
}

//First delete all answers
Answer::model()->deleteAllByAttributes(array('qid'=>$this->iQuestionID));
LimeExpressionManager::RevertUpgradeConditionsToRelevance($iSurveyID);
for ($iScaleID=0;$iScaleID<$iScaleCount;$iScaleID++) {
$iMaxCount=(int) Yii::app()->request->getPost('answercount_'.$iScaleID);
for ($iSortOrderID=1;$iSortOrderID<$iMaxCount;$iSortOrderID++) {
$sCode=sanitize_paranoid_string(Yii::app()->request->getPost('code_'.$iSortOrderID.'_'.$iScaleID));
//var_dump($sCode);
$iAssessmentValue=(int) Yii::app()->request->getPost('assessment_'.$iSortOrderID.'_'.$iScaleID);
foreach ($survey->allLanguages as $sLanguage) {
$sAnswerText=Yii::app()->request->getPost('answer_'.$sLanguage.'_'.$iSortOrderID.'_'.$iScaleID);
}

// Fix bug with FCKEditor saving strange BR types
$sAnswerText=$this->oFixCKeditor->fixCKeditor($sAnswerText);
Expand Down

0 comments on commit 40df2b9

Please sign in to comment.