Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Mar 26, 2018
2 parents d69e1b7 + 0f55db9 commit 297a3ee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
36 changes: 20 additions & 16 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -102,9 +102,8 @@ public function run($surveyid, $args)
}

$this->checkForDataSecurityAccepted();

$this->initMove(); // main methods to init session, LEM, moves, errors, etc
if (!$this->previewgrp && !$this->previewquestion) {
$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();
Expand All @@ -114,7 +113,6 @@ public function run($surveyid, $args)
$this->setNotAnsweredAndNotValidated();

} else {
$this->initMove(); // main methods to init session, LEM, moves, errors, etc
$this->setPreview();
}

Expand All @@ -123,6 +121,8 @@ public function run($surveyid, $args)

$this->fixMaxStep();

/* Update Survey text after move : get current (static) value (TODO : find the solution to get javascripted EM) */
$this->processSurveyText();
//******************************************************************************************************
//PRESENT SURVEY
//******************************************************************************************************
Expand Down Expand Up @@ -299,7 +299,6 @@ public function run($surveyid, $args)
$this->aSurveyInfo['errorHtml']['messages'] = $aErrorHtmlMessage;

$_gseq = -1;

foreach ($_SESSION[$this->LEMsessid]['grouplist'] as $gl) {

++$_gseq;
Expand Down Expand Up @@ -541,7 +540,7 @@ private function initMove()
$this->initFirstStep(); // If it's the first time user load this survey, will init session and LEM
$this->initTotalAndMaxSteps();
$this->checkIfUseBrowserNav(); // Check if user used browser navigation, or relaoded page

$this->processSurveyText(); // Basic replacement (can be need to be updated)
if ($this->sMove != 'clearcancel' && $this->sMove != 'confirmquota') {
$this->checkPrevStep(); // Check if prev step is set, else set it
$this->setMoveResult();
Expand Down Expand Up @@ -953,13 +952,6 @@ private function displayFirstPageIfNeeded()
if (empty($this->aSurveyInfo['datasecurity_error'])) {
$this->aSurveyInfo['datasecurity_error'] = gT("You will have to accept our survey policy!");
}

$this->aSurveyInfo['description'] = $this->processString($this->aSurveyInfo['description']);
$this->aSurveyInfo['welcome'] = $this->processString($this->aSurveyInfo['welcome']) ;
$this->aSurveyInfo['datasecurity_notice'] = $this->processString($this->aSurveyInfo['datasecurity_notice']) ;
$this->aSurveyInfo['datasecurity_error'] = $this->processString($this->aSurveyInfo['datasecurity_error']) ;
$this->aSurveyInfo['datasecurity_notice_label'] = Survey::replacePolicyLink($this->aSurveyInfo['datasecurity_notice_label'],$this->aSurveyInfo['sid']);
$this->aSurveyInfo['datasecurity_notice_label'] = $this->processString($this->aSurveyInfo['datasecurity_notice_label']) ;
}

if ($bDisplayFirstPage) {
Expand All @@ -969,6 +961,20 @@ private function displayFirstPageIfNeeded()
}
}

/**
* process Expression on Survey Text
*/
private function processSurveyText()
{
$this->aSurveyInfo['name'] = $this->processString($this->aSurveyInfo['name']);
$this->aSurveyInfo['description'] = $this->processString($this->aSurveyInfo['description']);
$this->aSurveyInfo['welcome'] = $this->processString($this->aSurveyInfo['welcome']) ;
$this->aSurveyInfo['datasecurity_notice'] = $this->processString($this->aSurveyInfo['datasecurity_notice']) ;
$this->aSurveyInfo['datasecurity_error'] = $this->processString($this->aSurveyInfo['datasecurity_error']) ;
$this->aSurveyInfo['datasecurity_notice_label'] = Survey::replacePolicyLink($this->aSurveyInfo['datasecurity_notice_label'],$this->aSurveyInfo['sid']);
$this->aSurveyInfo['datasecurity_notice_label'] = $this->processString($this->aSurveyInfo['datasecurity_notice_label']) ;
}

private function checkForDataSecurityAccepted(){
if($this->param['thisstep'] === '0' && Survey::model()->findByPk($this->aSurveyInfo['sid'])->showsurveypolicynotice>0) {
$data_security_accepted = App()->request->getPost('datasecurity_accepted', false);
Expand Down Expand Up @@ -1231,6 +1237,7 @@ private function moveSubmitIfNeeded()
* Check in a string if it uses expressions to replace them
* @param string $sString the string to evaluate
* @return string
* @todo : find/get current qid for processing string
*/
private function processString($sString, $iRecursionLevel = 1)
{
Expand All @@ -1240,10 +1247,7 @@ private function processString($sString, $iRecursionLevel = 1)
// process string anyway so that it can be pretty-printed
$aStandardsReplacementFields = getStandardsReplacementFields($this->aSurveyInfo);
$sProcessedString = LimeExpressionManager::ProcessString( $sString, null, $aStandardsReplacementFields, $iRecursionLevel);

}


return $sProcessedString;
}

Expand All @@ -1269,7 +1273,7 @@ private function setVarFromArgs($args)
$this->aSurveyOptions = isset($surveyOptions) ? $surveyOptions : null;
$this->aMoveResult = isset($moveResult) ? $moveResult : null;
$this->sMove = isset($move) ? $move : null;
$this->bInvalidLastPage = isset($invalidLastPage) ? $invalidLastPage : null;
$this->bInvalidLastPage = isset($invalidLastPage) ? $invalidLastPage : null;
$this->notanswered = isset($notanswered) ? $notanswered : null;
$this->filenotvalidated = isset($filenotvalidated) ? $filenotvalidated : null;
$this->completed = isset($completed) ? $completed : null;
Expand Down
23 changes: 22 additions & 1 deletion application/helpers/expressions/em_core_helper.php
Expand Up @@ -1668,11 +1668,22 @@ public function sProcessStringContainingExpressions($src, $questionNum = 0, $num
$prettyPrint = '';
$errors = array();

$prettyPrintIterationDone = false;
for ($i = 1; $i <= $numRecursionLevels; ++$i) {
// TODO - Since want to use <span> for dynamic substitution, what if there are recursive substititons?
$prevResult = $result;
$result = $this->sProcessStringContainingExpressionsHelper($result, $questionNum, $staticReplacement);
if($result === $prevResult) {
// No update during process : can exit of iteration
if(!$prettyPrintIterationDone) {
$prettyPrint = $this->prettyPrintSource;
}
// No need errors : already done
break;
}
if ($i == $whichPrettyPrintIteration) {
$prettyPrint = $this->prettyPrintSource;
$prettyPrintIterationDone = true;
}
$errors = array_merge($errors, $this->RDP_errs);
}
Expand Down Expand Up @@ -1962,10 +1973,20 @@ private function RDP_SetVariableValue($op, $name, $value)
*/
public function asSplitStringOnExpressions($src)
{
// Empty string, return an array
if($src === "") {
return array();
}
// No replacement to do, preg_split get more time than strpos
if(strpos($src, "{") === false || $src==="{" || $src==="}") {
return array (
0 => array ($src,0,'STRING')
);
};

// Seems to need split and replacement
$parts = preg_split($this->RDP_ExpressionRegex, $src, -1, (PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE));


$count = count($parts);
$tokens = array();
$inSQString = false;
Expand Down

0 comments on commit 297a3ee

Please sign in to comment.