From f8fb291cd9a8a3bb826f877d60c605e557f51f42 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Wed, 19 Jun 2019 14:00:53 +0200 Subject: [PATCH] Fixed issue #14936: Preview group : relevance on question broken (#1298) 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 --- application/helpers/SurveyRuntimeHelper.php | 36 +++++++++---------- .../helpers/expressions/em_manager_helper.php | 12 +++---- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/application/helpers/SurveyRuntimeHelper.php b/application/helpers/SurveyRuntimeHelper.php index 477e9fcc8bc..d698a7c64fa 100644 --- a/application/helpers/SurveyRuntimeHelper.php +++ b/application/helpers/SurveyRuntimeHelper.php @@ -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(); } @@ -655,9 +654,8 @@ 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); @@ -665,7 +663,7 @@ private function initFirstStep() // Check surveyid coherence if ($this->iSurveyid != LimeExpressionManager::getLEMsurveyId()) { - LimeExpressionManager::SetDirtyFlag(); + LimeExpressionManager::SetDirtyFlag(); } // Init $LEM states. @@ -1608,24 +1606,23 @@ 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) { @@ -1633,7 +1630,7 @@ private function setPreview() 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); @@ -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']); } } diff --git a/application/helpers/expressions/em_manager_helper.php b/application/helpers/expressions/em_manager_helper.php index 7a4387b50f8..df7ae5f2a70 100644 --- a/application/helpers/expressions/em_manager_helper.php +++ b/application/helpers/expressions/em_manager_helper.php @@ -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; /** @@ -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) @@ -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; @@ -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