Skip to content

Commit

Permalink
Fixed issue #09344: AND rules with ATTRIBUTE disappear when modify an…
Browse files Browse the repository at this point in the history
…d importing the survey

Dev : importing : bad order for getConditionsForEM : with $qid set : it work
Dev : modify : debug to 2 show Notice, surely broke before
  • Loading branch information
Shnoulle committed Nov 25, 2014
1 parent cacfd7a commit 14d6a1c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
15 changes: 12 additions & 3 deletions application/controllers/admin/conditionsaction.php
Expand Up @@ -1379,14 +1379,23 @@ function index($subaction, $iSurveyID=null, $gid=null, $qid=null)
{
$leftOperandType = 'tokenattr';
$aTokenAttrNames=getTokenFieldsAndNames($iSurveyID);
if (count($aTokenAttrNames) != 0)
if(isset($aTokenAttrNames[strtolower($extractedTokenAttr[1])]))
{
$thisAttrName=HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])]['description'])." [".$clang->gT("From token table")."]";
$thisAttrName=HTMLEscape($aTokenAttrNames[strtolower($extractedTokenAttr[1])]['description']);
}
else
{
$thisAttrName=HTMLEscape($extractedTokenAttr[1])." [".$clang->gT("Inexistant token table")."]";
$thisAttrName=HTMLEscape($extractedTokenAttr[1]);
}
if(tableExists("{{tokens_$iSurveyID}}"))
{
$thisAttrName.= " [".$clang->gT("From token table")."]";
}
else
{
$thisAttrName.= " [".$clang->gT("Inexistant token table")."]";
}

$aViewUrls['output'] .= "\t$thisAttrName\n";
// TIBO not sure this is used anymore !!
$conditionsList[]=array("cid"=>$rows['cid'],
Expand Down
67 changes: 39 additions & 28 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -767,10 +767,11 @@ public static function UpgradeConditionsToRelevance($surveyId=NULL, $qid=NULL)
else{
$aSurveyIDs=array($surveyId);
}
foreach ($aSurveyIDs as $surveyId ) {
// echo $surveyId.'<br>';flush();@ob_flush();
foreach ($aSurveyIDs as $surveyId )
{
$releqns = self::ConvertConditionsToRelevance($surveyId,$qid);
foreach ($releqns as $key=>$value) {
foreach ($releqns as $key=>$value)
{
$sQuery = "UPDATE {{questions}} SET relevance=".Yii::app()->db->quoteValue($value)." WHERE qid=".$key;
Yii::app()->db->createCommand($sQuery)->execute();
}
Expand Down Expand Up @@ -880,14 +881,15 @@ public static function ConvertConditionsToRelevance($surveyId=NULL, $qid=NULL)
$_cqid = $row['cqid'];
$_subqid = -1;
}

// fix fieldnames
if ($row['type'] == '' && preg_match('/^{.+}$/',$row['cfieldname'])) {
if (empty($row['type']) && preg_match('/^{.+}$/',$row['cfieldname']))
{
$fieldname = substr($row['cfieldname'],1,-1); // {TOKEN:xxxx}
$subqid = $fieldname;
$value = $row['value'];
}
else if ($row['type'] == 'M' || $row['type'] == 'P') {
elseif ($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) . '.NAOK';
Expand All @@ -901,11 +903,13 @@ public static function ConvertConditionsToRelevance($surveyId=NULL, $qid=NULL)
$value = 'Y';
}
}
else {
else
{
$fieldname = $row['cfieldname'] . '.NAOK';
$subqid = $fieldname;
$value = $row['value'];
}

if ($_subqid != -1 && $_subqid != $subqid)
{
$relAndList[] = '(' . implode(' or ', $relOrList) . ')';
Expand All @@ -917,17 +921,19 @@ public static function ConvertConditionsToRelevance($surveyId=NULL, $qid=NULL)
if (preg_match('/^@\d+X\d+X\d+.*@$/',$value)) {
$value = substr($value,1,-1);
}
else if (preg_match('/^{.+}$/',$value)) {
$value = substr($value,1,-1);
}
else if ($row['method'] == 'RX') {
if (!preg_match('#^/.*/$#',$value))
{
$value = '"/' . $value . '/"'; // if not surrounded by slashes, add them.
}
elseif (preg_match('/^{.+}$/',$value))
{
$value = substr($value,1,-1);
}
elseif ($row['method'] == 'RX')
{
if (!preg_match('#^/.*/$#',$value))
{
$value = '"/' . $value . '/"'; // if not surrounded by slashes, add them.
}
else {
$value = '"' . $value . '"';
}
else {
$value = '"' . $value . '"';
}

// add equation
Expand Down Expand Up @@ -988,9 +994,11 @@ public static function ConvertConditionsToRelevance($surveyId=NULL, $qid=NULL)
}
}

if (($row['cqid'] == 0 && !preg_match('/^{TOKEN:([^}]*)}$/',$row['cfieldname'])) || substr($row['cfieldname'],0,1) == '+') {
if (($row['cqid'] == 0 && !preg_match('/^{TOKEN:([^}]*)}$/',$row['cfieldname'])) || substr($row['cfieldname'],0,1) == '+')
{
$_cqid = -1; // forces this statement to be ANDed instead of being part of a cqid OR group (except for TOKEN fields)
}

}
// output last one
if ($_qid != -1)
Expand All @@ -1006,10 +1014,12 @@ public static function ConvertConditionsToRelevance($surveyId=NULL, $qid=NULL)
$relevanceEqn = implode(' or ', $scenarios);
$relevanceEqns[$_qid] = $relevanceEqn;
}
if (is_null($qid)) {
if (is_null($qid))
{
return $relevanceEqns;
}
else {
else
{
if (isset($relevanceEqns[$qid]))
{
$result = array();
Expand Down Expand Up @@ -8021,11 +8031,13 @@ private static function getConditionsForEM($surveyid=NULL, $qid=NULL)
if (!is_null($qid)) {
$where = " c.qid = ".$qid." AND ";
}
else if (!is_null($surveyid)) {
$where = " qa.sid = {$surveyid} AND ";
}
else {
$where = "";
else if (!is_null($surveyid))
{
$where = " qa.sid = {$surveyid} AND ";
}
else
{
$where = "";
}

$query = "SELECT DISTINCT c.*, q.sid, q.type
Expand All @@ -8043,11 +8055,11 @@ private static function getConditionsForEM($surveyid=NULL, $qid=NULL)
$databasetype = Yii::app()->db->getDriverName();
if ($databasetype=='mssql' || $databasetype=='dblib')
{
$query .= " order by sid, c.qid, scenario, cqid, cfieldname, value";
$query .= " order by c.qid, sid, scenario, cqid, cfieldname, value";
}
else
{
$query .= " order by sid, qid, scenario, cqid, cfieldname, value";
$query .= " order by qid, sid, scenario, cqid, cfieldname, value";
}

return Yii::app()->db->createCommand($query)->query();
Expand Down Expand Up @@ -8910,7 +8922,6 @@ static public function ShowSurveyLogicFile($sid, $gid=NULL, $qid=NULL,$LEMdebugL
);

$varNamesUsed = array(); // keeps track of whether variables have been declared

if (!is_null($qid))
{
$surveyMode='question';
Expand Down

0 comments on commit 14d6a1c

Please sign in to comment.