Skip to content

Commit

Permalink
Dev: Factor out getMandatoryMessage()
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 4, 2016
1 parent db92fd3 commit 240db11
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions application/helpers/qanda_helper.php
Expand Up @@ -320,18 +320,15 @@ function retrieveAnswers($ia)
//$inputnames is an array containing the names of each input field
list($answer, $inputnames)=$values;

if ($ia[6] == 'Y')
$questionIsMandatory = $ia[6] == 'Y';
if ($questionIsMandatory)
{

//$qtitle .= doRender('/survey/question_help/asterisk', array(), true);
//$qtitle .= $qtitle;
//$question_text['mandatory'] = gT('*');
$question_text['mandatory'] = doRender('/survey/question_help/asterisk', array(), true);
}

//If this question is mandatory but wasn't answered in the last page
//add a message HIGHLIGHTING the question
$mandatory_msg = (($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] != $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep']) || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'] == $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep']))?mandatory_message($ia):'';
$mandatory_msg = getMandatoryMessage($ia);
$qtitle .= $mandatory_msg;
$question_text['man_message'] = $mandatory_msg;

Expand Down Expand Up @@ -455,6 +452,29 @@ function retrieveAnswers($ia)
return array($qanda, $inputnames);
}

/**
* Check if we should display mandatory message
* @param array $ia
* @return string
*/
function getMandatoryMessage(array $ia)
{
$step = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['step'];
$maxStep = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['maxstep'];
$prevStep = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['prevstep'];

if ($step != $maxStep || $step == $prevStep)
{
$mandatoryMessage = mandatory_message($ia);
}
else
{
$mandatoryMessage = '';
}

return $mandatoryMessage;
}

function mandatory_message($ia)
{
$qinfo = LimeExpressionManager::GetQuestionStatus($ia[0]);
Expand Down

0 comments on commit 240db11

Please sign in to comment.