Skip to content

Commit

Permalink
Fixed issue #06078: invalid LimeExpressionManager->ngT() calls
Browse files Browse the repository at this point in the history
Dev Since min/max number of answers and min/max values can be dynamic, used EM to act as dynamic version of ngT()
Dev EM will detect cases where the messages are static, and generate static content for them (rather than the nested if() statements)
Dev Fixed printablesurvey so that only uses static tips - showing the pretty-print version with the nested if() statements does not make sense on printable survey
Dev added sample survey to test the dynamic plurals generation.
  • Loading branch information
TMSWhite committed May 10, 2012
1 parent 3f53458 commit 51589bd
Show file tree
Hide file tree
Showing 3 changed files with 2,323 additions and 54 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/printablesurvey.php
Expand Up @@ -647,7 +647,7 @@ function index($surveyid, $lang = null)
,'QUESTION_MANDATORY' => '' // translated 'mandatory' identifier
,'QUESTION_ID' => $deqrow['qid'] // id to be added to wrapping question div
,'QUESTION_CLASS' => getQuestionClass( $deqrow['type']) // classes to be added to wrapping question div
,'QUESTION_TYPE_HELP' => $qinfo['prettyValidTip'] // '' // instructions on how to complete the question
,'QUESTION_TYPE_HELP' => $qinfo['validTip'] // '' // instructions on how to complete the question // prettyValidTip is too verbose; assuming printable surveys will use static values
,'QUESTION_MAN_MESSAGE' => '' // (not sure if this is used) mandatory error
,'QUESTION_VALID_MESSAGE' => '' // (not sure if this is used) validation error
,'QUESTION_FILE_VALID_MESSAGE' => ''// (not sure if this is used) file validation error
Expand Down
127 changes: 74 additions & 53 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -1531,76 +1531,97 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
// Put these in the order you with them to appear in messages.
$qtips=array();

// min/max answers
// min/max answers
if ($min_answers!='' || $max_answers!='')
{
if ($min_answers!='' && $max_answers!='')
{
$qtips['num_answers']=sprintf($this->ngT("Please select between %s and %s answer.","Please select between %s and %s answers.",$max_answers),'{fixnum('.$min_answers.')}','{fixnum('.$max_answers.')}');
}
else if ($min_answers!='')
{
$qtips['num_answers']=sprintf($this->ngT("Please select at least %s answer.","Please select at least %s answers.",$min_answers),'{fixnum('.$min_answers.')}');

}
else if ($max_answers!='')
{
$qtips['num_answers']=sprintf($this->ngT("Please select at most %s answer.","Please select at most %s answers.",$max_answers),'{fixnum('.$max_answers.')}');
}
$_minA = (($min_answers == '') ? "''" : $min_answers);
$_maxA = (($max_answers == '') ? "''" : $max_answers );
$qtips['num_answers']=
"{if((is_empty($_minA) && is_empty($_maxA)),".
"'',".
"if(is_empty($_maxA),".
"if(($_minA)==1,".
"'".$this->gT("Please select at least one answer")."',".
"sprintf('".$this->gT("Please select at least %s answers")."',fixnum($_minA))".
"),".
"if(is_empty($_minA),".
"if(($_maxA)==1,".
"'".$this->gT("Please select at most one answer")."',".
"sprintf('".$this->gT("Please select at most %s answers")."',fixnum($_maxA))".
"),".
"if(($_minA)==($_maxA),".
"if(($_minA)==1,".
"'".$this->gT("Please select one answer")."',".
"sprintf('".$this->gT("Please select %s answers")."',fixnum($_minA))".
"),".
"sprintf('".$this->gT("Please select between %s and %s answers")."',fixnum($_minA),fixnum($_maxA))".
")".
")".
")".
")}";
}

// min/max value for each numeric entry
if ($min_num_value_n!='' || $max_num_value_n!='')
{
if ($min_num_value_n!='' && $max_num_value_n!='')
{
$qtips['value_range']=sprintf($this->gT("Each answer must be between %s and %s."),'{fixnum('.$min_num_value_n.')}','{fixnum('.$max_num_value_n.')}');
}
else if ($min_num_value_n!='')
{
$qtips['value_range']=sprintf($this->gT("Each answer must be at least %s."),'{fixnum('.$min_num_value_n.')}');

}
else if ($max_num_value_n!='')
{
$qtips['value_range']=sprintf($this->gT("Each answer must be at most %s."),'{fixnum('.$max_num_value_n.')}');
}
$_minV = (($min_num_value_n == '') ? "''" : $min_num_value_n);
$_maxV = (($max_num_value_n == '') ? "''" : $max_num_value_n);
$qtips['value_range']=
"{if((is_empty($_minV) && is_empty($_maxV)),".
"'',".
"if(is_empty($_maxV),".
"sprintf('".$this->gT("Each answer must be at least %s")."',fixnum($_minV)),".
"if(is_empty($_minV),".
"sprintf('".$this->gT("Each answer must be at most %s")."',fixnum($_maxV)),".
"if(($_minV)==($_maxV),".
"sprintf('".$this->gT("Each answer must be %s")."',fixnum($_minV)),".
"sprintf('".$this->gT("Each answer must be between %s and %s")."',fixnum($_minV),fixnum($_maxV))".
")".
")".
")".
")}";
}

// min/max value for each numeric entry - for multi-flexible question type
if ($multiflexible_min!='' || $multiflexible_max!='')
{
if ($multiflexible_min!='' && $multiflexible_max!='')
{
$qtips['value_range']=sprintf($this->gT("Each answer must be between %s and %s."),'{fixnum('.$multiflexible_min.')}','{fixnum('.$multiflexible_max.')}');
}
else if ($multiflexible_min!='')
{
$qtips['value_range']=sprintf($this->gT("Each answer must be at least %s."),'{fixnum('.$multiflexible_min.')}');

}
else if ($multiflexible_max!='')
{
$qtips['value_range']=sprintf($this->gT("Each answer must be at most %s."),'{fixnum('.$multiflexible_max.')}');
}
$_minV = (($multiflexible_min == '') ? "''" : $multiflexible_min);
$_maxV = (($multiflexible_max == '') ? "''" : $multiflexible_max);
$qtips['value_range']=
"{if((is_empty($_minV) && is_empty($_maxV)),".
"'',".
"if(is_empty($_maxV),".
"sprintf('".$this->gT("Each answer must be at least %s")."',fixnum($_minV)),".
"if(is_empty($_minV),".
"sprintf('".$this->gT("Each answer must be at most %s")."',fixnum($_maxV)),".
"if(($_minV)==($_maxV),".
"sprintf('".$this->gT("Each answer must be %s")."',fixnum($_minV)),".
"sprintf('".$this->gT("Each answer must be between %s and %s")."',fixnum($_minV),fixnum($_maxV))".
")".
")".
")".
")}";
}

// min/max sum value
if ($min_num_value!='' || $max_num_value!='')
{
if ($min_num_value!='' && $max_num_value!='')
{
$qtips['sum_range']=sprintf($this->gT("The sum must be between %s and %s"),'{fixnum('.$min_num_value.')}','{fixnum('.$max_num_value.')}');
}
else if ($min_num_value!='')
{
$qtips['sum_range']=sprintf($this->gT("The sum must be at least %s."),'{fixnum('.$min_num_value.')}');

}
else if ($max_num_value!='')
{
$qtips['sum_range']=sprintf($this->gT("The sum must be at most %s."),'{fixnum('.$max_num_value.')}');
}
$_minV = (($min_num_value == '') ? "''" : $min_num_value);
$_maxV = (($max_num_value == '') ? "''" : $max_num_value);
$qtips['sum_range']=
"{if((is_empty($_minV) && is_empty($_maxV)),".
"'',".
"if(is_empty($_maxV),".
"sprintf('".$this->gT("The sum must be at least %s")."',fixnum($_minV)),".
"if(is_empty($_minV),".
"sprintf('".$this->gT("The sum must be at most %s")."',fixnum($_maxV)),".
"if(($_minV)==($_maxV),".
"sprintf('".$this->gT("The sum must equal %s")."',fixnum($_minV)),".
"sprintf('".$this->gT("The sum must be between %s and %s")."',fixnum($_minV),fixnum($_maxV))".
")".
")".
")".
")}";
}

// equals_num_value
Expand Down

0 comments on commit 51589bd

Please sign in to comment.