Skip to content

Commit

Permalink
Dev: #09828 : rename maxDBanswers to max_subquestions (naming convent…
Browse files Browse the repository at this point in the history
…ions : #507 (comment))

Dev: in fact , this attribute allow to generate the number of subquestion.
Dev: number of subquestion => max answer, but still number of subquestion
  • Loading branch information
Shnoulle committed Jun 16, 2016
1 parent 5038dbe commit 73017cf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions application/controllers/admin/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ function index($sa = null)
if($sQuestionType=="R" && Survey::model()->findByPk($iSurveyID)->active=="Y")
{
$oQuestionAttributeMaxDBanswers = QuestionAttribute::model()->find(
"qid = :qid AND attribute = 'maxDBanswers'",
"qid = :qid AND attribute = 'max_subquestions'",
array(':qid' => $iQuestionID)
);
if (empty($oQuestionAttribute))
{
$answerCount=Answer::model()->countByAttributes(array('qid' => $iQuestionID,'language'=>Survey::model()->findByPk($iSurveyID)->language));
$oQuestionAttribute = new QuestionAttribute();
$oQuestionAttribute->qid = $iQuestionID;
$oQuestionAttribute->attribute = 'maxDBanswers';
$oQuestionAttribute->attribute = 'max_subquestions';
$oQuestionAttribute->value = $answerCount;
$oQuestionAttribute->save();
}
Expand Down
6 changes: 3 additions & 3 deletions application/helpers/admin/activate_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,23 @@ function activateSurvey($iSurveyID, $simulate = false)

/**
* See bug #09828: Ranking question : update allowed can broke Survey DB
* If maxDBanswers is not set or is invalid : set it to actual answers numbers
* If max_subquestions is not set or is invalid : set it to actual answers numbers
*/

$nrOfAnswers = Answer::model()->countByAttributes(
array('qid' => $arow['qid'],'language'=>Survey::model()->findByPk($iSurveyID)->language)
);

$oQuestionAttribute = QuestionAttribute::model()->find(
"qid = :qid AND attribute = 'maxDBanswers'",
"qid = :qid AND attribute = 'max_subquestions'",
array(':qid' => $arow['qid'])
);

if (empty($oQuestionAttribute))
{
$oQuestionAttribute = new QuestionAttribute();
$oQuestionAttribute->qid = $arow['qid'];
$oQuestionAttribute->attribute = 'maxDBanswers';
$oQuestionAttribute->attribute = 'max_subquestions';
$oQuestionAttribute->value = $nrOfAnswers;
$oQuestionAttribute->save();
}
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
{
// Sub question by answer number OR attribute
$answersCount = intval(Answer::model()->countByAttributes(array('qid' => $arow['qid'], 'language' => $sLanguage)));
$maxDbAnswer=QuestionAttribute::model()->find("qid = :qid AND attribute = 'maxDBanswers'",array(':qid' => $arow['qid']));
$maxDbAnswer=QuestionAttribute::model()->find("qid = :qid AND attribute = 'max_subquestions'",array(':qid' => $arow['qid']));
$columnsCount=(!$maxDbAnswer || intval($maxDbAnswer->value)<1) ? $answersCount : intval($maxDbAnswer->value);
for ($i=1; $i<=$columnsCount; $i++)
{
Expand Down Expand Up @@ -3126,7 +3126,7 @@ function questionAttributes($returnByName=false)
// "caption"=>gT('Max value from SGQA'));

/* Ranking specific : max DB answer */
$qattributes["maxDBanswers"]=array(
$qattributes["max_subquestions"]=array(
"types"=>"R",
'readonly_when_active'=>true,
'category'=>gT('Logic'),
Expand Down
12 changes: 6 additions & 6 deletions application/helpers/expressions/em_manager_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2145,21 +2145,21 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
{
$max_answers='';
}
/* Specific for ranking : fix only the alert : test if needed (maxDBanswers < count(answers) )*/
if($type=='R' && (isset($qattr['maxDBanswers']) && intval($qattr['maxDBanswers'])>0))
/* Specific for ranking : fix only the alert : test if needed (max_subquestions < count(answers) )*/
if($type=='R' && (isset($qattr['max_subquestions']) && intval($qattr['max_subquestions'])>0))
{
$maxDBanswer=intval($qattr['maxDBanswers']);
$max_subquestions=intval($qattr['max_subquestions']);
// We don't have another answer count in EM ?
$answerCount=Answer::model()->count("qid=:qid and language=:language",array(":qid"=>$questionNum,'language'=>$_SESSION['LEMlang']));
if($maxDBanswer < $answerCount)
if($max_subquestions < $answerCount)
{
if($max_answers!='')
{
$max_answers='min('.$max_answers.','.$maxDBanswer.')';
$max_answers='min('.$max_answers.','.$max_subquestions.')';
}
else
{
$max_answers=intval($qattr['maxDBanswers']);
$max_answers=intval($qattr['max_subquestions']);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions application/helpers/qanda_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1861,12 +1861,12 @@ function do_ranking($ia)

$ansresult = Yii::app()->db->createCommand($ansquery)->query()->readAll();
$anscount = count($ansresult);
$maxDbAnswer = intval($aQuestionAttributes['maxDBanswers']) > 0 ? intval($aQuestionAttributes['maxDBanswers']) : $anscount;
$max_subquestions = intval($aQuestionAttributes['max_subquestions']) > 0 ? intval($aQuestionAttributes['max_subquestions']) : $anscount;
if (trim($aQuestionAttributes["max_answers"])!='')
{
if($maxDbAnswer < $anscount)
if($max_subquestions < $anscount)
{
$max_answers = "min(".trim($aQuestionAttributes["max_answers"]).",".$maxDbAnswer.")";
$max_answers = "min(".trim($aQuestionAttributes["max_answers"]).",".$max_subquestions.")";
}
else
{
Expand All @@ -1875,16 +1875,16 @@ function do_ranking($ia)
}
else
{
$max_answers = $maxDbAnswer;
$max_answers = $max_subquestions;
}
// Get the max number of line needed
if(ctype_digit($max_answers) && intval($max_answers)<$maxDbAnswer)
if(ctype_digit($max_answers) && intval($max_answers)<$max_subquestions)
{
$iMaxLine = $max_answers;
}
else
{
$iMaxLine = $maxDbAnswer;
$iMaxLine = $max_subquestions;
}
if (trim($aQuestionAttributes["min_answers"])!='')
{
Expand Down

0 comments on commit 73017cf

Please sign in to comment.