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

New feature: Sample only quota for row quota (set quotas based on sample record values)

This commit is contained in:
azammitdcarf
2012-05-01 00:13:26 +00:00
parent 45755f6485
commit dd73eb4196
3 changed files with 62 additions and 6 deletions

View File

@@ -106,6 +106,38 @@ function limesurvey_quota_match($lime_sgqa,$lime_sid,$case_id,$value,$comparison
return false;
}
/**
* Return whether the given case matches the replicate sample only quota
*
* @param int $lime_sid The Limesurvey survey id
* @param int $case_id The case id
* @param string $val The sample value to compare
* @param string $var The sample variable to compare
*
* @return bool|int False if failed, otherwise 1 if matched, 0 if doesn't
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @since 2012-04-30
*/
function limesurvey_quota_replicate_match($lime_sid,$case_id,$val,$var)
{
global $db;
$sql = "SELECT count(*) as c
FROM " . LIME_PREFIX . "survey_$lime_sid as s
JOIN `case` as c ON (c.case_id = '$case_id')
JOIN `sample` as sam ON (c.sample_id = sam.sample_id)
JOIN `sample_var` as sv ON (sv.sample_id = sam.sample_id AND sv.var LIKE '$var' AND sv.val LIKE '$val')
WHERE s.token = c.case_id";
$rs = $db->GetRow($sql);
if (isset($rs) && !empty($rs))
return $rs['c'];
return false;
}
/**
* Return the number of completions for a given
* questionnaire, where the given question has

View File

@@ -1509,7 +1509,10 @@ function update_row_quota($questionnaire_id,$case_id = false)
//the quota criteria, and if so, increment the quota completions counter
if ($case_id != false)
{
$match = limesurvey_quota_match($r['lime_sgqa'],$r['lime_sid'],$case_id,$r['value'],$r['comparison']);
if ($r['lime_sgqa'] == -2)
$match = limesurvey_quota_replicate_match($r['lime_sid'],$case_id,$r['exclude_val'],$r['exclude_var']);
else
$match = limesurvey_quota_match($r['lime_sgqa'],$r['lime_sid'],$case_id,$r['value'],$r['comparison']);
if ($match == 1)
{
@@ -1527,7 +1530,10 @@ function update_row_quota($questionnaire_id,$case_id = false)
}
else
{
$completions = limesurvey_quota_completions($r['lime_sgqa'],$r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['value'],$r['comparison']);
if ($r['lime_sgqa'] == -2)
$completions = limesurvey_quota_replicate_completions($r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['exclude_val'],$r['exclude_var']);
else
$completions = limesurvey_quota_completions($r['lime_sgqa'],$r['lime_sid'],$r['questionnaire_id'],$r['sample_import_id'],$r['value'],$r['comparison']);
$updatequota = true;
}