Skip to content

Commit

Permalink
Dev EM now accurately creates Relevance equation from all know Condit…
Browse files Browse the repository at this point in the history
…ion types and combinations.

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@11101 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
TMSWhite committed Oct 4, 2011
1 parent ed1cb19 commit 65383cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
32 changes: 25 additions & 7 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -113,14 +113,30 @@ public function ConvertConditionsToRelevance($surveyId, $qid=NULL)
$relOrList = array();
$_cqid = $row['cqid'];
}
if ($row['type'] == 'M' || $row['type'] == 'P') {
$fieldname = $row['cfieldname'] . $row['value'];
$value = 'Y';

// fix fieldnames
if ($row['type'] == '' && preg_match('/^{.+}$/',$row['cfieldname'])) {
$fieldname = substr($row['cfieldname'],1,-1); // {TOKEN:xxxx}
$value = $row['value'];
}
else if ($row['type'] == 'M' || $row['type'] == 'P') {
if (substr($row['cfieldname'],0,1) == '+') {
// if prefixed with +, then a fully resolved name
$fieldname = substr($row['cfieldname'],1);
$value = $row['value'];
}
else {
// else create name by concatenating two parts together
$fieldname = $row['cfieldname'] . $row['value'];
$value = 'Y';
}
}
else {
$fieldname = $row['cfieldname'];
$value = $row['value'];
}

// fix values
if (preg_match('/^@\d+X\d+X\d+.*@$/',$value)) {
$value = substr($value,1,-1);
}
Expand All @@ -130,10 +146,8 @@ public function ConvertConditionsToRelevance($surveyId, $qid=NULL)
else {
$value = $CI->db->escape($value); // TODO - is this the desired behavior - esp for regex?
}
// TODO - test for for the following additional types of Conditions
// (1) +SGQA - is that just M or P type questions that are fully-specified (so don't append $value and compare to 'Y')?
// (2) Can Constant contain {INSERTANS:xxxx}?
// (3) {TOKEN:xxx} == xxxx - how should that be stored in the database? have cfield={TOKEN:xxx}? Right now it is stored wrong in 1.91+

// add equation
if ($row['method'] == 'RX')
{
$relOrList[] = "regexMatch(" . $value . "," . $fieldname . ")";
Expand All @@ -142,6 +156,10 @@ public function ConvertConditionsToRelevance($surveyId, $qid=NULL)
{
$relOrList[] = $fieldname . " " . $row['method'] . " " . $value;
}

if ($row['cqid'] == 0 || substr($row['cfieldname'],0,1) == '+') {
$_cqid = -1; // forces this statement to be ANDed instead of being part of a cqid OR group
}
}
// output last one
if ($_qid != -1)
Expand Down
16 changes: 14 additions & 2 deletions application/models/conditions_model.php
Expand Up @@ -11,7 +11,13 @@ function getAllRecordsForSurvey($surveyid, $qid=NULL)
.", ".$this->db->dbprefix('questions')." as q"
." where c.qid in (select qid from ".$this->db->dbprefix('questions')." where sid = ".$surveyid.")"
." and c.cqid = q.qid"
." order by qid, scenario, cqid";
." union "
." select c.*, '' as type"
." from ".$this->db->dbprefix('conditions')." as c"
.", ".$this->db->dbprefix('questions')." as q"
." where c.qid in (select qid from ".$this->db->dbprefix('questions')." where sid = ".$surveyid.")"
." and c.cqid = 0"
." order by qid, scenario, cqid, cfieldname, value";
}
else {
$query = "select c.*"
Expand All @@ -20,7 +26,13 @@ function getAllRecordsForSurvey($surveyid, $qid=NULL)
.", ".$this->db->dbprefix('questions')." as q"
." where c.qid = ".$qid
." and c.cqid = q.qid"
." order by qid, scenario, cqid";
." union "
." select c.*, '' as type"
." from ".$this->db->dbprefix('conditions')." as c"
.", ".$this->db->dbprefix('questions')." as q"
." where c.qid = ".$qid
." and c.cqid = 0"
." order by qid, scenario, cqid, cfieldname, value";
}

$data = $this->db->query($query);
Expand Down

0 comments on commit 65383cc

Please sign in to comment.