Skip to content

Commit

Permalink
New Feature #05269: Use ExpressionManager for Branching logic as opti…
Browse files Browse the repository at this point in the history
…onal alternative to Conditions

Dev Optimized how INSERTANS: is declared & processed by EM, lowering memory usage and shortening size of embedded JavaScript.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev_tms@11582 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
TMSWhite committed Dec 4, 2011
1 parent 47cbb19 commit cce443a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion admin/importgroup.php
Expand Up @@ -1031,7 +1031,7 @@ function XMLImportGroup($sFullFilepath, $newsid)
// now translate any links
$insertdata['title']=translink('survey', $oldsid, $newsid, $insertdata['title']);
$insertdata['question']=translink('survey', $oldsid, $newsid, $insertdata['question']);
$insertdata['help']=translink('survey', $oldsid, $newsid, $insertdata['help']);
$insertdata['help']=(isset($insertdata['help']) ? translink('survey', $oldsid, $newsid, $insertdata['help']) : '');
if (isset($aQIDReplacements[$oldsqid])){
$insertdata['qid']=$aQIDReplacements[$oldsqid];
db_switchIDInsert('questions',true);
Expand Down
3 changes: 2 additions & 1 deletion classes/eval/ExpressionManager.php
Expand Up @@ -1418,6 +1418,7 @@ public function GetVarAttribute($name,$attr,$default)
{
$args = explode(".", $name);
$varName = $args[0];
$varName = preg_replace("/^(?:INSERTANS:)?(.*?)$/", "$1", $varName);
if (!isset($this->amVars[$varName]))
{
// echo 'UNDEFINED VARIABLE: ' . $varName;
Expand Down Expand Up @@ -1646,7 +1647,7 @@ private function isValidFunction($name)
*/
private function isValidVariable($name)
{
$varName = preg_replace("/^(.*?)(?:\.(?:" . ExpressionManager::$regex_var_attr . "))?$/", "$1", $name);
$varName = preg_replace("/^(?:INSERTANS:)?(.*?)(?:\.(?:" . ExpressionManager::$regex_var_attr . "))?$/", "$1", $name);
return array_key_exists($varName,$this->amVars);
}

Expand Down
16 changes: 8 additions & 8 deletions classes/eval/LimeExpressionManager.php
Expand Up @@ -1419,17 +1419,17 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
);

$this->knownVars[$varName] = $varInfo_Code;
$this->knownVars['INSERTANS:' . $code] = $varInfo_Code; // $varInfo_DisplayVal;
// $this->knownVars['INSERTANS:' . $code] = $varInfo_Code; // $varInfo_DisplayVal;
$this->knownVars[$code] = $varInfo_Code;

$this->jsVar2qid[$jsVarName] = $questionNum;

// Create JavaScript arrays
$this->alias2varName[$varName] = array('jsName'=>$jsVarName, 'jsPart' => "'" . $varName . "':'" . $jsVarName . "'");
$this->alias2varName[$jsVarName_on] = array('jsName'=>$jsVarName, 'jsPart' => "'" . $jsVarName_on . "':'" . $jsVarName . "'");
$this->alias2varName[$jsVarName] = array('jsName'=>$jsVarName, 'jsPart' => "'" . $jsVarName . "':'" . $jsVarName . "'");
// $this->alias2varName[$jsVarName_on] = array('jsName'=>$jsVarName, 'jsPart' => "'" . $jsVarName_on . "':'" . $jsVarName . "'");
// $this->alias2varName[$jsVarName] = array('jsName'=>$jsVarName, 'jsPart' => "'" . $jsVarName . "':'" . $jsVarName . "'");
$this->alias2varName[$code] = array('jsName'=>$jsVarName, 'jsPart' => "'" . $code . "':'" . $jsVarName . "'");
$this->alias2varName['INSERTANS:' . $code] = array('jsName'=>$jsVarName, 'jsPart' => "'INSERTANS:" . $code . "':'" . $jsVarName . "'");
// $this->alias2varName['INSERTANS:' . $code] = array('jsName'=>$jsVarName, 'jsPart' => "'INSERTANS:" . $code . "':'" . $jsVarName . "'");

$this->varNameAttr[$jsVarName] = "'" . $jsVarName . "':{ "
. "'jsName':'" . $jsVarName
Expand Down Expand Up @@ -3958,10 +3958,10 @@ static function GetRelevanceAndTailoringJavaScript()
$relStatus = 1;
}
$jsParts[] = "<input type='hidden' id='relevance" . $qid . "' name='relevance" . $qid . "' value='" . $relStatus . "'/>\n";
if (isset($LEM->qid2code[$qid]))
{
$jsParts[] = "<input type='hidden' id='relevance" . $qid . "codes' name='relevance" . $qid . "codes' value='" . $LEM->qid2code[$qid] . "'/>\n";
}
// if (isset($LEM->qid2code[$qid]))
// {
// $jsParts[] = "<input type='hidden' id='relevance" . $qid . "codes' name='relevance" . $qid . "codes' value='" . $LEM->qid2code[$qid] . "'/>\n";
// }
}
$LEM->runtimeTimings[] = array(__METHOD__,(microtime(true) - $now));

Expand Down
12 changes: 7 additions & 5 deletions classes/eval/em_javascript.js
Expand Up @@ -205,10 +205,14 @@ function LEMval(alias)
var str = new String(alias);
var varName = alias;
var suffix = 'code'; // the default
if (str.match(/\.(codeValue|code|displayValue|gid|jsName|mandatory|NAOK|qid|question|readWrite|relevanceNum|relevanceStatus|relevance|shown|type)$/)) {
varName = str.replace(/\.(codeValue|code|displayValue|gid|jsName|mandatory|NAOK|qid|question|readWrite|relevanceNum|relevanceStatus|relevance|shown|type)$/,'')
if (str.match(/\.(codeValue|code|displayValue|gid|jsName|mandatory|NAOK|qid|question|readWrite|relevanceNum|relevanceStatus|relevance|sgqa|shown|type)$/)) {
varName = str.replace(/\.(codeValue|code|displayValue|gid|jsName|mandatory|NAOK|qid|question|readWrite|relevanceNum|relevanceStatus|relevance|sgqa|shown|type)$/,'')
suffix = str.replace(/^(.+)\./,'');
}
if (str.match(/^INSERTANS:/)) {
suffix = 'shown';
varName = varName.substr(10);
}

jsName = LEMalias2varName[varName];
attr = LEMvarNameAttr[jsName];
Expand All @@ -224,9 +228,7 @@ function LEMval(alias)
else {
whichJsName = attr.jsName;
}
if (str.match(/^INSERTANS:/)) {
suffix = 'shown';
}

// values should always be stored encoded with htmlspecialchars()
switch (suffix) {
case 'displayValue':
Expand Down

0 comments on commit cce443a

Please sign in to comment.