Skip to content

Commit

Permalink
Fixed issue #10085: fixed question index
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 23, 2015
1 parent 1a964e2 commit 9bd256d
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 48 deletions.
233 changes: 186 additions & 47 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -14,21 +14,20 @@

class SurveyRuntimeHelper {


protected function createFullQuestionIndex($LEMsessid, $surveyMode)
protected function createFullQuestionIndexMenu($LEMsessid, $surveyMode)
{
if ($surveyMode == 'group')
{
return $this->createFullQuestionIndexByGroup($LEMsessid);
return $this->createFullQuestionIndexByGroupMenu($LEMsessid);
}
else
{
return $this->createFullQuestionIndexByQuestion($LEMsessid);
return $this->createFullQuestionIndexByQuestionMenu($LEMsessid);
}

}

protected function createFullQuestionIndexByGroup($LEMsessid)
protected function createFullQuestionIndexByGroupMenu($LEMsessid)
{
// Button will be shown inside the form. Not handled by replacement.
$htmlButtons = array();
Expand Down Expand Up @@ -76,7 +75,7 @@ protected function createFullQuestionIndexByGroup($LEMsessid)
return array('menulist'=>$html, 'buttons'=>$htmlButtons );
}

protected function createFullQuestionIndexByQuestion($LEMsessid)
protected function createFullQuestionIndexByQuestionMenu($LEMsessid)
{
$html = '';
$html .= CHtml::openTag('li', array('id' => 'index', 'class'=>'dropdown'));
Expand All @@ -91,7 +90,7 @@ protected function createFullQuestionIndexByQuestion($LEMsessid)
return array('menulist'=>$html, 'buttons'=>array() );
}

protected function createIncrementalQuestionIndex($LEMsessid, $surveyMode)
protected function createIncrementalQuestionIndexMenu($LEMsessid, $surveyMode)
{
$html = '';
$html .= "\n\n<!-- PRESENT THE INDEX -->\n";
Expand Down Expand Up @@ -184,14 +183,162 @@ protected function createIncrementalQuestionIndex($LEMsessid, $surveyMode)
return array('menulist'=>$html, 'buttons'=>array() );
}

protected function createFullQuestionIndex($LEMsessid, $surveyMode)
{
if ($surveyMode == 'group')
{
$this->createFullQuestionIndexByGroup($LEMsessid);
}
else
{
$this->createFullQuestionIndexByQuestion($LEMsessid);
}

}

protected function createFullQuestionIndexByGroup($LEMsessid)
{
echo "\n\n<!-- PRESENT THE INDEX -->\n";
echo CHtml::openTag('div', array('id' => 'index'));
echo CHtml::openTag('div', array('class' => 'container', 'id'=>'indexcontainer'));
echo CHtml::tag('h2', array(), gT("Question index"));
echo CHtml::openTag('ol');
foreach ($_SESSION[$LEMsessid]['grouplist'] as $key => $group)
{
// echo '<script>';
// echo 'var session = '. json_encode(LimeExpressionManager::singleton()->_ValidateGroup($key)) . ';';
// echo 'console.log(session);';
// echo '</script>';
// Better to use tracevar /
if (LimeExpressionManager::GroupIsRelevant($group['gid']))
{
$group['step'] = $key + 1;
$stepInfo = LimeExpressionManager::singleton()->_ValidateGroup($key);
$classes = implode(' ', array(
'row',
$stepInfo['anyUnanswered'] ? 'missing' : '',
$_SESSION[$LEMsessid]['step'] == $group['step'] ? 'current' : ''

));
$sButtonSubmit=CHtml::htmlButton(gT('Go to this group'),array('type'=>'submit', 'id'=> 'button-'.$group['gid'],'value'=>$group['step'],'name'=>'move','class'=>'jshide'));
echo CHtml::tag('li', array(
'data-gid' => $group['gid'],
'title' => $group['description'],
'class' => $classes,
), $group['group_name'].$sButtonSubmit);
}
}
echo CHtml::closeTag('ol');
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');

App()->getClientScript()->registerScript('manageIndex',"manageIndex()\n",CClientScript::POS_END);
}

protected function createFullQuestionIndexByQuestion($LEMsessid)
{
echo CHtml::openTag('div', array('id' => 'index'));
echo CHtml::openTag('div', array('class' => 'container', 'id'=>'indexcontainer'));
echo CHtml::tag('h2', array(), gT("Question index"));
echo 'Question by question not yet supported, use incremental index.';
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');

App()->getClientScript()->registerScript('manageIndex',"manageIndex()\n",CClientScript::POS_END);
}

protected function createIncrementalQuestionIndex($LEMsessid, $surveyMode)
{
echo "\n\n<!-- PRESENT THE INDEX -->\n";

echo '<div id="index"><div class="container" id="indexcontainer"><h2>' . gT("Question index") . '</h2>';

$stepIndex = LimeExpressionManager::GetStepIndexInfo();
$lastGseq=-1;
$gseq = -1;
$grel = true;
for($v = 0, $n = 0; $n != $_SESSION[$LEMsessid]['maxstep']; ++$n)
{
if (!isset($stepIndex[$n])) {
continue; // this is an invalid group - skip it
}
$stepInfo = $stepIndex[$n];

if ($surveyMode == 'question')
{
if ($lastGseq != $stepInfo['gseq']) {
// show the group label
++$gseq;
$g = $_SESSION[$LEMsessid]['grouplist'][$gseq];
$grel = !LimeExpressionManager::GroupIsIrrelevantOrHidden($gseq);
if ($grel)
{
$gtitle = LimeExpressionManager::ProcessString($g['group_name']);
echo '<h3>' . flattenText($gtitle) . "</h3>";
}
$lastGseq = $stepInfo['gseq'];
}
if (!$grel || !$stepInfo['show'])
{
continue;
}
$q = $_SESSION[$LEMsessid]['fieldarray'][$n];
}
else
{
++$gseq;
if (!$stepInfo['show'])
{
continue;
}
$g = $_SESSION[$LEMsessid]['grouplist'][$gseq];
}

if ($surveyMode == 'group')
{
$indexlabel = LimeExpressionManager::ProcessString($g['group_name']);
$sButtonText=gT('Go to this group');
}
else
{
$indexlabel = LimeExpressionManager::ProcessString($q[3]);
$sButtonText=gT('Go to this question');
}

$sText = (($surveyMode == 'group') ? flattenText($indexlabel) : flattenText($indexlabel));
$bGAnsw = !$stepInfo['anyUnanswered'];

++$v;

$class = ($n == $_SESSION[$LEMsessid]['step'] - 1 ? 'current' : ($bGAnsw ? 'answer' : 'missing'));
if ($v % 2)
$class .= " odd";

$s = $n + 1;
echo "<div class=\"row $class\">";
echo "<span class=\"hdr\">$v</span>";
echo "<span title=\"$sText\">$sText</span>";
echo CHtml::htmlButton($sButtonText,array('type'=>'submit','value'=>$s,'name'=>'move','class'=>'jshide'));
echo "</div>";
}

if ($_SESSION[$LEMsessid]['maxstep'] == $_SESSION[$LEMsessid]['totalsteps'])
{
echo CHtml::htmlButton(gT('Submit'),array('type'=>'submit','value'=>'movesubmit','name'=>'move','class'=>'submit button'));
}

echo '</div></div>';
App()->getClientScript()->registerScript('manageIndex',"manageIndex()\n",CClientScript::POS_END);

}

/**
* Main function
*
* @param mixed $surveyid
* @param mixed $args
*/
function run($surveyid,$args)
function run($surveyid,$args)
{
global $errormsg;
extract($args);
Expand Down Expand Up @@ -943,18 +1090,23 @@ function run($surveyid,$args)
* Question Index
*/
$aQuestionindexbuttons = null;
$aQuestionindexbuttonsmenu = null;
if (!$previewgrp && !$previewquestion)
{
if ($surveyMode != 'survey' && $thissurvey['questionindex'] == 1)
{
$aQuestionindex = $this->createIncrementalQuestionIndex($LEMsessid, $surveyMode);
//$aQuestionindex = $this->createIncrementalQuestionIndex($LEMsessid, $surveyMode);
$aQuestionindexmenu = $this->createIncrementalQuestionIndexMenu($LEMsessid, $surveyMode);
}
elseif ($surveyMode != 'survey' && $thissurvey['questionindex'] == 2)
{
$aQuestionindex = $this->createFullQuestionIndex($LEMsessid, $surveyMode);
//$aQuestionindex = $this->createFullQuestionIndex($LEMsessid, $surveyMode);
$aQuestionindexmenu = $this->createFullQuestionIndexMenu($LEMsessid, $surveyMode);
}
$questionindex = (isset($aQuestionindex['menulist']))?$aQuestionindex['menulist']:'';
$aQuestionindexbuttons = (isset($aQuestionindex['buttons']))?$aQuestionindex['buttons']:'';
//$questionindex = (isset($aQuestionindex['menulist']))?$aQuestionindex['menulist']:'';
$questionindexmenu = (isset($aQuestionindexmenu['menulist']))?$aQuestionindexmenu['menulist']:'';
//$aQuestionindexbuttons = (isset($aQuestionindex['buttons']))?$aQuestionindex['buttons']:'';
$aQuestionindexbuttonsmenu = (isset($aQuestionindexmenu['buttons']))?$aQuestionindexmenu['buttons']:'';
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1161,51 +1313,38 @@ function run($surveyid,$args)
echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript();
LimeExpressionManager::FinishProcessingPage();

/**
* Navigator
*/
if (!$previewgrp && !$previewquestion)
{

$aNavigator = surveymover();
$moveprevbutton = $aNavigator['sMovePrevButton'];
$movenextbutton = $aNavigator['sMoveNextButton'];
$navigator = $moveprevbutton.' '.$movenextbutton;

/**
* Navigator
*/
if (!$previewgrp && !$previewquestion)
{

//$redata = compact(array_keys(get_defined_vars()));
$redata = compact(array_keys(get_defined_vars()));
$aNavigator = surveymover();
$moveprevbutton = $aNavigator['sMovePrevButton'];
$movenextbutton = $aNavigator['sMoveNextButton'];
$navigator = $moveprevbutton.' '.$movenextbutton;

echo "\n\n<!-- PRESENT THE NAVIGATOR -->\n";
echo templatereplace(file_get_contents($sTemplatePath."navigator.pstpl"), array(), $redata);
echo "\n";
$redata = compact(array_keys(get_defined_vars()));

if ($thissurvey['active'] != "Y")
{
echo "<p style='text-align:center' class='error'>" . gT("This survey is currently not active. You will not be able to save your responses.") . "</p>\n";
}
echo "\n\n<!-- PRESENT THE NAVIGATOR -->\n";
echo templatereplace(file_get_contents($sTemplatePath."navigator.pstpl"), array(), $redata);
echo "\n";

/**
* Question Index buttons
*/
if($aQuestionindexbuttons)
{
echo '<div class="hidden">';
foreach($aQuestionindexbuttons as $button)
{
echo $button;
}
echo '</div>';
}
if ($thissurvey['active'] != "Y")
{
echo "<p style='text-align:center' class='error'>" . gT("This survey is currently not active. You will not be able to save your responses.") . "</p>\n";
}


if ($surveyMode != 'survey' && $thissurvey['questionindex'] == 1)
{
$this->createIncrementalQuestionIndex($LEMsessid, $surveyMode);
$this->createIncrementalQuestionIndexMenu($LEMsessid, $surveyMode);
}
elseif ($surveyMode != 'survey' && $thissurvey['questionindex'] == 2)
{
$this->createFullQuestionIndex($LEMsessid, $surveyMode);
$this->createFullQuestionIndexMenu($LEMsessid, $surveyMode);
}

echo "<input type='hidden' name='thisstep' value='{$_SESSION[$LEMsessid]['step']}' id='thisstep' />\n";
Expand Down Expand Up @@ -1261,13 +1400,13 @@ public function setJavascriptVar($iSurveyId)

/**
* Construction of replacement array, actually doing it with redata
*
*
* @param $aQuestionQanda : array from qanda helper
* @return aray of replacement for question.psptl
**/
public static function getQuestionReplacement($aQuestionQanda)
{

// Get the default replacement and set empty value by default
$aReplacement=array(
"QID"=>"",
Expand Down Expand Up @@ -1301,7 +1440,7 @@ public static function getQuestionReplacement($aQuestionQanda)
$oSurveyId=Survey::model()->findByPk($iSurveyId);
$sType=$lemQuestionInfo['info']['type'];

// Core value : not replaced
// Core value : not replaced
$aReplacement['QID']=$iQid;
$aReplacement['GID']=$aQuestionQanda[6];// Not sure for aleatory : it's the real gid or the updated gid ? We need original gid or updated gid ?
$aReplacement['SGQ']=$aQuestionQanda[7];
Expand Down
2 changes: 2 additions & 0 deletions application/helpers/replacements_helper.php
Expand Up @@ -70,6 +70,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
'totalBoilerplatequestions',
'totalquestions',
'questionindex',
'questionindexmenu',
);

$varsPassed = array();
Expand Down Expand Up @@ -569,6 +570,7 @@ function templatereplace($line, $replacements = array(), &$redata = array(), $de
$coreReplacements['PRIVACY'] = isset($privacy) ? $privacy : ''; // global
$coreReplacements['PRIVACYMESSAGE'] = "<span style='font-weight:bold; font-style: italic;'>".gT("A Note On Privacy")."</span><br />".gT("This survey is anonymous.")."<br />".gT("The record of your survey responses does not contain any identifying information about you, unless a specific survey question explicitly asked for it.").' '.gT("If you used an identifying token to access this survey, please rest assured that this token will not be stored together with your responses. It is managed in a separate database and will only be updated to indicate whether you did (or did not) complete this survey. There is no way of matching identification tokens with survey responses.");
$coreReplacements['QUESTION_INDEX']=isset($questionindex) ? $questionindex: '';
$coreReplacements['QUESTION_INDEX_MENU']=isset($questionindexmenu) ? $questionindexmenu: '';
$coreReplacements['RESTART'] = $_restart;
$coreReplacements['RETURNTOSURVEY'] = $_return_to_survey;
$coreReplacements['SAVE_LINKS'] = $_savelinks;
Expand Down
2 changes: 1 addition & 1 deletion templates/default/startpage.pstpl
Expand Up @@ -30,7 +30,7 @@
<ul class="nav navbar-nav navbar-right">
{SAVE_LINKS}
{CLEARALL_LINKS}
{QUESTION_INDEX}
{QUESTION_INDEX_MENU}
</ul>
</div><!--/.nav-collapse -->
</div>
Expand Down
3 changes: 3 additions & 0 deletions templates/default/template.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9bd256d

Please sign in to comment.