2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Fixes lp:1510368 Lime quota with more than one option in list doesn't display in queXS quota report

This commit is contained in:
Adam Zammit
2015-11-20 14:01:34 +11:00
parent 1041e73849
commit a055129674
2 changed files with 84 additions and 56 deletions

View File

@@ -238,25 +238,36 @@ if ($questionnaire_id)
{ {
//limesurvey quotas for this question //limesurvey quotas for this question
$quotas = (get_limesurvey_quota_info($r['id'])); $quotas = (get_limesurvey_quota_info($r['id']));
$sqlq = array(); $cob = array();
foreach ($quotas as $q) foreach ($quotas as $qr)
$sqlq[] = "s." . $q['fieldname'] . " = '" . $q['value'] . "'"; {
$sqlq = array();
foreach($qr as $qid => $q)
{
$sqlq[] = "s." . $q['fieldname'] . " = '" . $q['value'] . "'";
}
$cob[] = "( " . implode(' OR ', $sqlq) . " )";
}
if (!empty($cob))
{
$sql = "SELECT COUNT(id) as count $sql = "SELECT COUNT(id) as count
FROM ".LIME_PREFIX."survey_{$r['sid']} as s FROM ".LIME_PREFIX."survey_{$r['sid']} as s
JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id') JOIN `case` as c ON (c.questionnaire_id = '$questionnaire_id')
JOIN `sample` as sam ON (c.sample_id = sam.sample_id AND sam.import_id = '$sample_import_id') JOIN `sample` as sam ON (c.sample_id = sam.sample_id AND sam.import_id = '$sample_import_id')
WHERE ".implode(' AND ',$sqlq)." "." WHERE ".implode(' AND ',$cob)." "."
AND submitdate IS NOT NULL AND submitdate IS NOT NULL
AND s.token = c.token"; AND s.token = c.token";
$rs = $db->GetRow($sql); $rs = $db->GetRow($sql);
$completions = $rs['count']; $completions = $rs['count'];
$perc = ROUND(($completions / $r['qlimit']) * 100,2); $perc = ROUND(($completions / $r['qlimit']) * 100,2);
$report[] = array("strata" => "<a href='" . LIME_URL . "/admin/admin.php?action=quotas&sid={$r['sid']}&quota_id={$r['id']}&subaction=quota_editquota'>" . $r['name'] . "</a>", "quota" => $r['qlimit'], "completions" => $completions, "perc" => $perc); $report[] = array("strata" => "<a href='" . LIME_URL . "/admin/admin.php?action=quotas&sid={$r['sid']}&quota_id={$r['id']}&subaction=quota_editquota'>" . $r['name'] . "</a>", "quota" => $r['qlimit'], "completions" => $completions, "perc" => $perc);
}
} }

View File

@@ -441,57 +441,74 @@ function get_limesurvey_quota_info($lime_quota_id)
$ret = array(); $ret = array();
$sql = "SELECT q.*,s.language $sql = "SELECT q.qid
FROM ".LIME_PREFIX."quota_members as q, ".LIME_PREFIX."surveys as s FROM ".LIME_PREFIX."quota_members as q, ".LIME_PREFIX."surveys as s
WHERE q.quota_id='$lime_quota_id' WHERE q.quota_id='$lime_quota_id'
AND s.sid = q.sid"; AND s.sid = q.sid
GROUP BY q.qid";
$rs = $db->GetAll($sql); $rsq = $db->GetAll($sql);
foreach($rs as $quota_entry) foreach ($rsq as $q)
{ {
$lime_qid = $quota_entry['qid']; $qid = $q['qid'];
$surveyid = $quota_entry['sid'];
$language = $quota_entry['language'];
$sql = "SELECT type, title,gid $sql = "SELECT q.*,s.language
FROM ".LIME_PREFIX."questions FROM ".LIME_PREFIX."quota_members as q, ".LIME_PREFIX."surveys as s
WHERE qid='$lime_qid' WHERE q.quota_id='$lime_quota_id'
AND language='$language'"; AND s.sid = q.sid
AND q.qid = $qid";
$qtype = $db->GetRow($sql);
$fieldnames = "0"; $rs = $db->GetAll($sql);
if ($qtype['type'] == "I" || $qtype['type'] == "G" || $qtype['type'] == "Y")
{
$fieldnames= ($surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
$value = $quota_entry['code'];
}
if($qtype['type'] == "L" || $qtype['type'] == "O" || $qtype['type'] =="!")
{
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
$value = $quota_entry['code'];
}
if($qtype['type'] == "M") $r2 = array();
{
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$quota_entry['code']);
$value = "Y";
}
if($qtype['type'] == "A" || $qtype['type'] == "B")
{
$temp = explode('-',$quota_entry['code']);
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$temp[0]);
$value = $temp[1];
}
$ret[] = array('code' => $quota_entry['code'], 'value' => $value, 'qid' => $quota_entry['qid'], 'fieldname' => $fieldnames); foreach($rs as $quota_entry)
{
$lime_qid = $quota_entry['qid'];
$surveyid = $quota_entry['sid'];
$language = $quota_entry['language'];
$sql = "SELECT type, title,gid
FROM ".LIME_PREFIX."questions
WHERE qid='$lime_qid'
AND language='$language'";
$qtype = $db->GetRow($sql);
$fieldnames = "0";
if ($qtype['type'] == "I" || $qtype['type'] == "G" || $qtype['type'] == "Y")
{
$fieldnames= ($surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
$value = $quota_entry['code'];
}
if($qtype['type'] == "L" || $qtype['type'] == "O" || $qtype['type'] =="!")
{
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
$value = $quota_entry['code'];
}
if($qtype['type'] == "M")
{
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$quota_entry['code']);
$value = "Y";
}
if($qtype['type'] == "A" || $qtype['type'] == "B")
{
$temp = explode('-',$quota_entry['code']);
$fieldnames=( $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$temp[0]);
$value = $temp[1];
}
$r2[] = array('code' => $quota_entry['code'], 'value' => $value, 'qid' => $quota_entry['qid'], 'fieldname' => $fieldnames);
}
$ret[$qid] = $r2;
} }
return $ret; return $ret;
} }