Skip to content

Commit

Permalink
Dev: Factor out setTotalSteps()
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 30, 2016
1 parent e8ed58d commit f498241
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions application/helpers/frontend_helper.php
Expand Up @@ -1028,23 +1028,8 @@ function buildsurveysession($surveyid,$preview=false)

$_SESSION['survey_'.$surveyid]['totalquestions'] = $totalquestions - (int) reset($iNumberofQuestions);

//2. SESSION VARIABLE: totalsteps
//The number of "pages" that will be presented in this survey
//The number of pages to be presented will differ depending on the survey format
switch($thissurvey['format'])
{
case "A":
$_SESSION['survey_'.$surveyid]['totalsteps']=1;
break;
case "G":
if (isset($_SESSION['survey_'.$surveyid]['grouplist']))
{
$_SESSION['survey_'.$surveyid]['totalsteps']=count($_SESSION['survey_'.$surveyid]['grouplist']);
}
break;
case "S":
$_SESSION['survey_'.$surveyid]['totalsteps']=$totalquestions;
}
// 2. SESSION VARIABLE: totalsteps
setTotalSteps($surveyid, $thissurvey, $totalquestions);

// Break out and crash if there are no questions!
if ($totalquestions == 0 || $iTotalGroupsWithoutQuestions > 0)
Expand Down Expand Up @@ -1565,6 +1550,32 @@ function resetAllSessionVariables($surveyid)
$_SESSION['survey_'.$surveyid]['fieldnamesInfo'] = Array();
}

/**
* The number of "pages" that will be presented in this survey
* The number of pages to be presented will differ depending on the survey format
* Set totalsteps in session
* @param int $surveyid
* @param array $thissurvey
* @return void
*/
function setTotalSteps($surveyid, array $thissurvey, $totalquestions)
{
switch($thissurvey['format'])
{
case "A":
$_SESSION['survey_'.$surveyid]['totalsteps']=1;
break;
case "G":
if (isset($_SESSION['survey_'.$surveyid]['grouplist']))
{
$_SESSION['survey_'.$surveyid]['totalsteps']=count($_SESSION['survey_'.$surveyid]['grouplist']);
}
break;
case "S":
$_SESSION['survey_'.$surveyid]['totalsteps']=$totalquestions;
}
}

/**
* @todo Rename
* @todo Move HTML to view
Expand Down

0 comments on commit f498241

Please sign in to comment.