Skip to content

Commit

Permalink
Dev: Factor out prefillFromCommandLine()
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 30, 2016
1 parent 5826f71 commit 9fe4a7a
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions application/helpers/frontend_helper.php
Expand Up @@ -1082,29 +1082,7 @@ function buildsurveysession($surveyid,$preview=false)
initFieldArray($surveyid, $fieldmap);

// Prefill questions/answers from command line params
$reservedGetValues= array('token','sid','gid','qid','lang','newtest','action');
$startingValues=array();
if (isset($_GET))
{
foreach ($_GET as $k=>$v)
{
if (!in_array($k,$reservedGetValues) && isset($_SESSION['survey_'.$surveyid]['fieldmap'][$k]))
{
$startingValues[$k] = $v;
}
else
{ // Search question codes to use those for prefilling.
foreach($_SESSION['survey_'.$surveyid]['fieldmap'] as $sgqa => $details)
{
if ($details['title'] == $k)
{
$startingValues[$sgqa] = $v;
}
}
}
}
}
$_SESSION['survey_'.$surveyid]['startingValues']=$startingValues;
prefillFromCommandLine($surveyid);

if (isset($_SESSION['survey_'.$surveyid]['fieldarray'])) $_SESSION['survey_'.$surveyid]['fieldarray']=array_values($_SESSION['survey_'.$surveyid]['fieldarray']);

Expand Down Expand Up @@ -1143,6 +1121,37 @@ function buildsurveysession($surveyid,$preview=false)
Yii::trace('end', 'survey.buildsurveysession');
}

/**
* Prefill startvalues from command line param
* @return void
*/
function prefillFromCommandLine($surveyid)
{
$reservedGetValues= array('token','sid','gid','qid','lang','newtest','action');
$startingValues=array();
if (isset($_GET))
{
foreach ($_GET as $k=>$v)
{
if (!in_array($k,$reservedGetValues) && isset($_SESSION['survey_'.$surveyid]['fieldmap'][$k]))
{
$startingValues[$k] = $v;
}
else
{ // Search question codes to use those for prefilling.
foreach($_SESSION['survey_'.$surveyid]['fieldmap'] as $sgqa => $details)
{
if ($details['title'] == $k)
{
$startingValues[$sgqa] = $v;
}
}
}
}
}
$_SESSION['survey_'.$surveyid]['startingValues']=$startingValues;
}

/**
* @param array $fieldmap
* @return void
Expand Down

0 comments on commit 9fe4a7a

Please sign in to comment.