Skip to content

Commit

Permalink
Fixed issue #12113: Unable to fix Invalid Sub questions in multilingu…
Browse files Browse the repository at this point in the history
…al survey

Dev: add a model function, currently call it when edit sub questions
  • Loading branch information
Shnoulle committed Feb 6, 2017
1 parent 028c18f commit 67a1e1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
9 changes: 2 additions & 7 deletions application/controllers/admin/questions.php
Expand Up @@ -764,7 +764,6 @@ public function _editsubquestion($surveyid, $gid, $qid)
if (empty($qrow))
{
switchMSSQLIdentityInsert('questions', true);

$question = new Question;
$question->qid = $row->qid;
$question->sid = $surveyid;
Expand All @@ -784,12 +783,8 @@ public function _editsubquestion($surveyid, $gid, $qid)
}

array_unshift($anslangs, $baselang);

// Delete the subquestions in languages not supported by the survey
$criteria = new CDbCriteria;
$criteria->addColumnCondition(array('parent_qid' => $qid));
$criteria->addNotInCondition('language', $anslangs);
Question::model()->deleteAll($criteria);
/* Fix subquestions */
$oQuestion->fixSubQuestions();

// Check sort order for subquestions
$qresult = Question::model()->findByAttributes(array('qid' => $qid, 'language' => $baselang));
Expand Down
31 changes: 30 additions & 1 deletion application/models/Question.php
Expand Up @@ -944,7 +944,6 @@ protected function beforeSave()
if (parent::beforeSave())
{
$surveyIsActive = Survey::model()->findByPk($this->sid)->active !== 'N';

if ($surveyIsActive && $this->getIsNewRecord())
{
return false;
Expand Down Expand Up @@ -989,4 +988,34 @@ public static function getNumberOfQuestions($surveyid)
." AND parent_qid=0")->read();
}

/**
* Fix sub question of a parent question
* Must be call after base language subquestion is set
* @todo : move other fix here ?
* @return void
*/
public function fixSubQuestions(){
if($this->parent_qid){
return;
}
$oSurvey=Survey::model()->findByPk($this->sid);

/* Delete sub question in all other language */
$criteria = new CDbCriteria;
$criteria->compare('parent_qid',$this->qid);
$criteria->addNotInCondition('language', $oSurvey->getAllLanguages());
Question::model()->deleteAll($criteria);// Must log count of deleted ?
/* Delete invalid subquestions (not in primary language */
$validSubQuestion = Question::model()->findAll(array(
'select'=>'qid',
'condition'=>'parent_qid=:parent_qid AND language=:language',
'params'=>array('parent_qid' => $this->qid,'language' => $oSurvey->language)
));
$criteria = new CDbCriteria;
$criteria->compare('parent_qid',$this->qid);
$criteria->addNotInCondition('qid', CHtml::listData($validSubQuestion,'qid','qid'));
Question::model()->deleteAll($criteria);// Must log count of deleted ?
}

}

0 comments on commit 67a1e1e

Please sign in to comment.