Skip to content

Commit

Permalink
Fixed issue #14936: Preview group : relevance on question broken (#1298)
Browse files Browse the repository at this point in the history
Fixed issue #14987: Preview question not working
Dev: LimeExpressionManager:sPreviewMode
Dev: setVariableAndTokenMappingsForExpressionManager must have preview when it call
Dev: Don't need 1st step : preview must do whole
Dev: preview don't need checkForDataSecurityAccepted
  • Loading branch information
Shnoulle committed Jun 19, 2019
1 parent ae3e5e6 commit f8fb291
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
36 changes: 16 additions & 20 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -100,16 +100,15 @@ public function run($surveyid, $args)
$this->showTokenOrCaptchaFormsIfNeeded();
}

$this->checkForDataSecurityAccepted();
$this->initMove(); // main methods to init session, LEM, moves, errors, etc
if (!$this->previewgrp && !$this->previewquestion) {
$this->checkForDataSecurityAccepted();
$this->initMove(); // main methods to init session, LEM, moves, errors, etc
$this->checkQuotas(); // check quotas (then the process will stop here)
$this->displayFirstPageIfNeeded();
$this->saveAllIfNeeded();
$this->saveSubmitIfNeeded();
// TODO: move somewhere else
$this->setNotAnsweredAndNotValidated();

} else {
$this->setPreview();
}
Expand Down Expand Up @@ -655,17 +654,16 @@ private function setSurveyOptions()
*/
private function initFirstStep()
{

// First time the survey is loaded
if (!isset($_SESSION[$this->LEMsessid]['step']) || ($this->previewquestion || $this->previewgrp) ) {
if (!isset($_SESSION[$this->LEMsessid]['step']) ) {
// Init session, randomization and filed array
buildsurveysession($this->iSurveyid);
$fieldmap = randomizationGroupsAndQuestions($this->iSurveyid);
initFieldArray($this->iSurveyid, $fieldmap);

// Check surveyid coherence
if ($this->iSurveyid != LimeExpressionManager::getLEMsurveyId()) {
LimeExpressionManager::SetDirtyFlag();
LimeExpressionManager::SetDirtyFlag();
}

// Init $LEM states.
Expand Down Expand Up @@ -1608,32 +1606,31 @@ private function setSurveySettings($surveyid, $args)
$this->previewquestion = (isset($this->param['action']) && $this->param['action'] == 'previewquestion') ?true:false;

$this->preview = ($this->previewquestion || $this->previewgrp);

$this->sLangCode = App()->language;
}

private function setPreview()
{
$this->sSurveyMode = ($this->previewgrp) ? 'group' : 'question';
$this->sSurveyMode = ($this->previewgrp) ? 'group' : 'question'; // Can be great to have a survey here …
buildsurveysession($this->iSurveyid,true); // Preview part disable SurveyURLParameter , why ? Work without

/* Set steps for PHP notice */
$_SESSION[$this->LEMsessid]['prevstep'] = 2;
$_SESSION[$this->LEMsessid]['maxstep'] = 0;

if ($this->previewquestion) {
$_SESSION[$this->LEMsessid]['step'] = 0; //maybe unset it after the question has been displayed?
}

if ($this->sSurveyMode == 'group' && $this->previewgrp) {
$_SESSION[$this->LEMsessid]['step'] = 0;
if ($this->previewgrp) {
$_gid = sanitize_int($this->param['gid']);

LimeExpressionManager::StartSurvey($this->aSurveyInfo['sid'], 'group', $this->aSurveyOptions, false, $this->LEMdebugLevel);
LimeExpressionManager::StartSurvey($this->aSurveyInfo['sid'], $this->sSurveyMode, $this->aSurveyOptions, false, $this->LEMdebugLevel);
$gseq = LimeExpressionManager::GetGroupSeq($_gid);

if ($gseq == -1) {
$sMessage = gT('Invalid group number for this survey: ').$_gid;
renderError('', $sMessage, $this->aSurveyInfo, $this->sTemplateViewPath);
}

$this->aMoveResult = LimeExpressionManager::JumpTo($gseq + 1, true);
$this->aMoveResult = LimeExpressionManager::JumpTo($gseq + 1, 'group', false, true);
if (is_null($this->aMoveResult)) {
$sMessage = gT('This group contains no questions. You must add questions to this group before you can preview it');
renderError('', $sMessage, $this->aSurveyInfo, $this->sTemplateViewPath);
Expand All @@ -1649,12 +1646,11 @@ private function setPreview()
renderError('', $sMessage, $this->aSurveyInfo, $this->sTemplateViewPath);
}

} elseif ($this->sSurveyMode == 'question' && $this->previewquestion) {
} elseif ($this->previewquestion) {
$_qid = sanitize_int($this->param['qid']);

LimeExpressionManager::StartSurvey($this->iSurveyid, 'question', $this->aSurveyOptions, false, $this->LEMdebugLevel);
$qSec = LimeExpressionManager::GetQuestionSeq($_qid);
$this->aMoveResult = LimeExpressionManager::JumpTo($qSec + 1, true, false, true);
LimeExpressionManager::StartSurvey($this->iSurveyid, $this->sSurveyMode, $this->aSurveyOptions, true, $this->LEMdebugLevel);
$qSec = LimeExpressionManager::GetQuestionSeq($_qid);
$this->aMoveResult = LimeExpressionManager::JumpTo($qSec + 1, 'question', false, true);
$this->aStepInfo = LimeExpressionManager::GetStepIndexInfo($this->aMoveResult['seq']);
}
}
Expand Down
12 changes: 6 additions & 6 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -59,9 +59,9 @@ class LimeExpressionManager {
*/
private $debugLevel=0;
/**
* sPreviewMode used for relevance equation force to 1 in preview mode
* Maybe we can set it public
* @var string|boolean
* sPreviewMode used for relevance equation and to disable save value in DB
* 'question' or 'group' string force relevance to 1 if needed
* @var string|false
*/
private $sPreviewMode=false;
/**
Expand Down Expand Up @@ -714,7 +714,7 @@ public function __clone()

/**
* Set the previewmode
* @param boolean|string $previewmode 'question', 'group', false
* @param string|false $previewmode 'question', 'group', false
* @return void
*/
public static function SetPreviewMode($previewmode=false)
Expand Down Expand Up @@ -3738,7 +3738,7 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
$aid = (isset($fielddata['aid']) ? $fielddata['aid'] : '');
$sqid = (isset($fielddata['sqid']) ? $fielddata['sqid'] : '');
if($this->sPreviewMode=='question') $fielddata['relevance']=1;
if($this->sPreviewMode=='group') $fielddata['grelevance']=1;
if($this->sPreviewMode=='group' || $this->sPreviewMode=='question') $fielddata['grelevance']=1;

$questionNum = $fielddata['qid'];
$relevance = (isset($fielddata['relevance'])) ? $fielddata['relevance'] : 1;
Expand Down Expand Up @@ -5674,7 +5674,7 @@ public static function GetLastMoveResult($clearSubstitutionInfo=false)
/**
* Jump to a specific question or group sequence. If jumping forward, it re-validates everything in between
* @param int $seq - the sequential step
* @param boolean $preview - if true, then treat this group/question as relevant, even if it is not, so that it can be displayed. @see var $sPreviewMode
* @param string|false $preview @see var $sPreviewMode
* @param boolean $processPOST - add the updated value to be saved in the database
* @param boolean $force - if true, then skip validation of current group (e.g. will jump even if there are errors)
* @param boolean $changeLang
Expand Down

0 comments on commit f8fb291

Please sign in to comment.