Skip to content

Commit

Permalink
Dev: Factor out composeQuestionText() (not correct yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Sep 5, 2016
1 parent f9c6b8a commit 7c4089e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
2 changes: 0 additions & 2 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -1034,15 +1034,13 @@ function run($surveyid,$args)
continue;
}
$qidattributes = getQuestionAttributeValues($ia[0]);
var_dump($qidattributes);

$questionIsNotEquation = $ia[4] != '*';
$questionIsHidden = !isset($qidattributes['hidden']) || $qidattributes['hidden'] == 1;
if ($questionIsNotEquation &&
($qidattributes === false ||
$questionIsHidden))
{
die('here');
continue;
}

Expand Down
55 changes: 38 additions & 17 deletions application/helpers/qanda_helper.php
Expand Up @@ -331,30 +331,18 @@ function retrieveAnswers($ia)

$qtitle .= $validation_msg;

if (($_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']))
{
$file_validation_msg = file_validation_message($ia);
}
else
{
$file_validation_msg = '';
$isValid = true; // don't want to show any validation messages.
}
list($file_valid_message, $isValid) = getFileValidationMessage($ia);

$qtitle .= $ia[4] == "|" ? $file_validation_msg : "";
$question_text['file_valid_message'] = $ia[4] == "|" ? $file_validation_msg : "";

if (!empty($question_text['man_message']) || !$isValid || !empty($question_text['file_valid_message']))
{
$question_text['input_error_class'] = ' input-error';// provides a class to style question wrapper differently if there is some kind of user input error;
}

// =====================================================
// START: legacy question_start.pstpl code
// The following section adds to the templating system by allowing
// templaters to control where the various parts of the question text
// are put.

$question_text = composeQuestionText($ia);

$sTemplate = isset($thissurvey['template']) ? $thissurvey['template'] : NULL;
if (is_file('templates/'.$sTemplate.'/question_start.pstpl'))
{
Expand Down Expand Up @@ -403,6 +391,8 @@ function retrieveAnswers($ia)
};
// END: legacy question_start.pstpl code
//===================================================================
//
//$question_text['all'] = 'dummy';

$qanda=array($question_text, $answer, 'help', $display, $qid, $ia[2], $ia[5], $ia[1] );

Expand Down Expand Up @@ -458,13 +448,44 @@ function composeQuestionText(array $ia)

$question_text['man_message'] = getMandatoryMessage($ia);

$_vshow = (!isset($aQuestionAttributes['hide_tip']) || $aQuestionAttributes['hide_tip']==0); // whether should initially be visible - TODO should also depend upon 'hidetip'?
list($validation_msg, $isValid) = validation_message($ia,$_vshow);
$_vshow = !isset($aQuestionAttributes['hide_tip']) || $aQuestionAttributes['hide_tip'] == 0; // whether should initially be visible - TODO should also depend upon 'hidetip'?
list($validation_msg, $isValid1) = validation_message($ia,$_vshow);
$question_text['valid_message'] = $validation_msg;

list($file_valid_message, $isValid2) = getFileValidationMessage($ia);
$question_text['file_valid_message'] = $ia[4] == "|" ? $file_validation_msg : "";

if (!empty($question_text['man_message']) || !$isValid1 || !$isValid2 || !empty($question_text['file_valid_message']))
{
$question_text['input_error_class'] = ' input-error';// provides a class to style question wrapper differently if there is some kind of user input error;
}

return $question_text;
}

/**
* @param array $ia
* return array (file_valid_message, isValid)
*/
function getFileValidationMessage(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)
{
$file_validation_msg = file_validation_message($ia);
$isValid = false;
}
else
{
$file_validation_msg = '';
$isValid = true; // don't want to show any validation messages.
}

return array($file_valid_message, $isValid);
}

/**
* Check if we should display mandatory message
* @param array $ia
Expand Down

0 comments on commit 7c4089e

Please sign in to comment.