mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
New feature: Choose Limesurvey attributes to assign sample records to on case creation
This commit is contained in:
@@ -67,7 +67,6 @@ function limerpc_init ($url,$user,$pass)
|
||||
if (is_array($limeKey) && isset($limeKey['status'])) {
|
||||
die($limeKey['status']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -276,7 +275,37 @@ function lime_get_responses_by_questionnaire($qid,$fields = null)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function lime_get_token_attributes($qid)
|
||||
{
|
||||
global $limeKey;
|
||||
global $limeRPC;
|
||||
|
||||
$ret = false;
|
||||
$lime_id = limerpc_init_qid($qid);
|
||||
|
||||
if ($lime_id !== false) {
|
||||
//attribute array (test for all attributes)
|
||||
for ($i = 1; $i < 256; $i++) {
|
||||
$aa[] = "attribute_$i";
|
||||
}
|
||||
//add a dummy participant
|
||||
$dtoken = 'QUEXSTESTTOKEN';
|
||||
try {
|
||||
$np = $limeRPC->add_participants($limeKey,$lime_id,array(array('firstname'=>$dtoken,'lastname'=>$dtoken)));
|
||||
} catch (Exception $e) {
|
||||
limerpc_close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($np[0]['tid'])) {
|
||||
$ret = array_keys($np[0]); //array of data
|
||||
$limeRPC->delete_participants($limeKey,$lime_id,array($np[0]['tid']));
|
||||
}
|
||||
}
|
||||
|
||||
limerpc_close();
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function lime_add_token($qid,$params)
|
||||
{
|
||||
|
||||
@@ -447,55 +447,28 @@ function add_case($sample_id,$questionnaire_id,$operator_id = "NULL",$testing =
|
||||
|
||||
if ($lime_sid)
|
||||
{
|
||||
$lfirstname = "";
|
||||
$llastname = "";
|
||||
$lemail = "";
|
||||
$params = array('token' => $token);
|
||||
|
||||
$params = array('firstname' => "",
|
||||
'lastname' => "",
|
||||
'email' => "",
|
||||
'token' => $token);
|
||||
//get remote sample fields for this questionaire/sample only
|
||||
$sql = "SELECT rv.var_id,rv.field
|
||||
FROM remote_sample_var as rv
|
||||
JOIN sample as s ON (s.sample_id = $sample_id)
|
||||
JOIN sample_import_var_restrict as sv ON (s.import_id = sv.sample_import_id AND rv.var_id = sv.var_id)
|
||||
WHERE questionnaire_id = $questionnaire_id";
|
||||
|
||||
$params['firstname'] = ($db->GetOne("SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.type = '6'"));
|
||||
$ps = $db->GetAll($sql);
|
||||
|
||||
$params['lastname'] = ($db->GetOne("SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.type = '7'"));
|
||||
|
||||
$params['email'] = ($db->GetOne("SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.type = '8'"));
|
||||
//copy across all selected variables to matching Limesurvey fields
|
||||
foreach($ps as $p) {
|
||||
$params[$p['field']] = $db->GetOne("SELECT val
|
||||
FROM sample_var
|
||||
WHERE var_id = {$p['var_id']}
|
||||
AND sample_id = '$sample_id'");
|
||||
}
|
||||
|
||||
//include limesurvey functions
|
||||
include_once(dirname(__FILE__).'/functions.limesurvey.php');
|
||||
|
||||
if ($addlimeattributes)
|
||||
{
|
||||
$sql = "SELECT sv.val
|
||||
FROM sample_var as sv, sample_import_var_restrict as s
|
||||
WHERE sv.var_id = s.var_id
|
||||
AND sv.sample_id = '$sample_id'
|
||||
AND s.type = '1'
|
||||
ORDER BY s.var_id ASC";
|
||||
|
||||
$vars = $db->GetAll($sql);
|
||||
|
||||
$att = 1;
|
||||
|
||||
foreach($vars as $v) {
|
||||
$params['attribute_' . $att] = $v['val'];
|
||||
$att++;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = lime_add_token($questionnaire_id,$params);
|
||||
|
||||
//fail to create case if can't add remote token
|
||||
|
||||
Reference in New Issue
Block a user