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

Added more transactions

This commit is contained in:
azammitdcarf
2009-02-17 22:46:43 +00:00
parent 6788638d68
commit 822a72c74d

View File

@@ -209,6 +209,8 @@ function is_respondent_selection($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$questionnaire_id = get_questionnaire_id($operator_id); $questionnaire_id = get_questionnaire_id($operator_id);
if (!$questionnaire_id) return false; if (!$questionnaire_id) return false;
@@ -219,6 +221,9 @@ function is_respondent_selection($operator_id)
$rs = $db->GetRow($sql); $rs = $db->GetRow($sql);
if (!$db->CompleteTrans())
return false;
if (!$rs) return false; if (!$rs) return false;
if ($rs['respondent_selection'] == 1) return true; if ($rs['respondent_selection'] == 1) return true;
return false; return false;
@@ -639,7 +644,12 @@ function is_on_shift($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$case_id = get_case_id($operator_id,false); $case_id = get_case_id($operator_id,false);
$shift_id = false;
if ($case_id) if ($case_id)
{ {
$sql = "SELECT s.shift_id $sql = "SELECT s.shift_id
@@ -651,11 +661,14 @@ function is_on_shift($operator_id)
$row = $db->GetRow($sql); $row = $db->GetRow($sql);
if (empty($row)) return false; if (!empty($row))
return $row['shift_id']; $shift_id = $row['shift_id'];
} }
else
return false; if ($db->CompleteTrans())
return $shift_id;
return false;
} }
@@ -672,7 +685,12 @@ function is_on_call($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$case_id = get_case_id($operator_id,false); $case_id = get_case_id($operator_id,false);
$call_state_id = false;
if ($case_id) if ($case_id)
{ {
$ca = get_call_attempt($operator_id); $ca = get_call_attempt($operator_id);
@@ -686,11 +704,14 @@ function is_on_call($operator_id)
$row = $db->GetRow($sql); $row = $db->GetRow($sql);
if (empty($row)) return false; if (!empty($row))
return $row['state']; $call_state_id = $row['state'];
} }
else
return false; if ($db->CompleteTrans())
return $call_state_id;
return false;
} }
@@ -706,8 +727,12 @@ function is_on_call_attempt($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$case_id = get_case_id($operator_id,false); $case_id = get_case_id($operator_id,false);
$return = false;
if ($case_id) if ($case_id)
{ {
$sql = "SELECT call_attempt_id $sql = "SELECT call_attempt_id
@@ -718,11 +743,14 @@ function is_on_call_attempt($operator_id)
$row = $db->GetRow($sql); $row = $db->GetRow($sql);
if (empty($row)) return false; if (!empty($row))
return true; $return = true;
} }
return false;
if ($db->CompleteTrans())
return $return;
return false;
} }
@@ -741,14 +769,15 @@ function get_call($operator_id,$respondent_id = "",$contact_phone_id = "")
{ {
global $db; global $db;
$db->StartTrans();
$case_id = get_case_id($operator_id,false); $case_id = get_case_id($operator_id,false);
$ca = get_call_attempt($operator_id); $ca = get_call_attempt($operator_id);
$id = false;
if ($case_id && $ca) if ($case_id && $ca)
{ {
$db->StartTrans();
$sql = "SELECT call_id $sql = "SELECT call_id
FROM `call` FROM `call`
WHERE case_id = '$case_id' WHERE case_id = '$case_id'
@@ -776,15 +805,12 @@ function get_call($operator_id,$respondent_id = "",$contact_phone_id = "")
$id = $row['call_id']; $id = $row['call_id'];
} }
}
$db->CompleteTrans(); if ($db->CompleteTrans())
return $id; return $id;
}
else
{
return false;
}
return $false;
} }
@@ -800,29 +826,34 @@ function get_limesurvey_url($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$url = "nocaseavailable.php";
$case_id = get_case_id($operator_id); $case_id = get_case_id($operator_id);
if ($case_id) if ($case_id)
{ {
$sid = get_limesurvey_id($operator_id); $sid = get_limesurvey_id($operator_id);
$url = LIME_URL . "index.php?loadall=reload&sid=$sid&token=$case_id&lang=en"; $url = LIME_URL . "index.php?loadall=reload&sid=$sid&token=$case_id&lang=en";
$questionnaire_id = get_questionnaire_id($operator_id); $questionnaire_id = get_questionnaire_id($operator_id);
//get prefills //get prefills
$sql = "SELECT lime_sgqa,value $sql = "SELECT lime_sgqa,value
FROM questionnaire_prefill FROM questionnaire_prefill
WHERE questionnaire_id = '$questionnaire_id'"; WHERE questionnaire_id = '$questionnaire_id'";
$pf = $db->GetAll($sql); $pf = $db->GetAll($sql);
if (!empty($pf)) if (!empty($pf))
{ {
foreach ($pf as $p) foreach ($pf as $p)
$url .= "&" . $p['lime_sgqa'] . "=" . template_replace($p['value'],$operator_id,$case_id); $url .= "&" . $p['lime_sgqa'] . "=" . template_replace($p['value'],$operator_id,$case_id);
} }
return $url;
}
else
{
//no cases currently available
return "nocaseavailable.php";
} }
$db->CompleteTrans();
return $url;
} }
@@ -925,12 +956,14 @@ function end_case($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$case_id = get_case_id($operator_id,false); $case_id = get_case_id($operator_id,false);
$return = false;
if ($case_id) if ($case_id)
{ {
$db->StartTrans();
//determine current final outcome code //determine current final outcome code
//Look over all calls, for each phone number that is to be tried again //Look over all calls, for each phone number that is to be tried again
//Calculate outcome based on //Calculate outcome based on
@@ -938,8 +971,6 @@ function end_case($operator_id)
//If one phone number is to be tried again, use: "Differences in Response Rates using Most recent versus Final dispositions in Telephone Surveys" by Christopher McCarty //If one phone number is to be tried again, use: "Differences in Response Rates using Most recent versus Final dispositions in Telephone Surveys" by Christopher McCarty
// //
//Look for any calls where none should be tried again (this should be a final outcome) //Look for any calls where none should be tried again (this should be a final outcome)
$sql = "SELECT c.call_id, c.outcome_id $sql = "SELECT c.call_id, c.outcome_id
FROM `call` as c, `outcome` as o FROM `call` as c, `outcome` as o
@@ -1034,15 +1065,16 @@ function end_case($operator_id)
WHERE case_id = '$case_id'"; WHERE case_id = '$case_id'";
$o = $db->Execute($sql); $o = $db->Execute($sql);
$db->CompleteTrans();
return $o; $return = true;
} }
else else
{ $return = false;
return false;
}
if ($db->CompleteTrans())
return $return;
return false;
} }
/** /**
@@ -1069,57 +1101,6 @@ function outcome_description($outcome_id)
} }
/**
* Determine the outcome for this call attempt
*
* @param int $call_attempt The call attempt
* @return int The outcome_id for this call attempt
function determine_outcome($call_attempt,$update = false)
{
global $db;
//determine outcome code (for now select the last one)
$sql = "SELECT c.outcome_id as outcome_id,c.call_id
FROM `call` as c
LEFT JOIN `outcome` as o on (o.outcome_id = c.outcome_id)
WHERE c.call_attempt_id = '$call_attempt'
ORDER BY o.outcome_type_id ASC, o.default_delay_minutes ASC";
$r = $db->GetRow($sql);
$sql = "SELECT appointment_id
FROM appointment
WHERE call_attempt_id = '$call_attempt'";
$a = $db->GetRow($sql);
$outcome = 1; //default outcome is 1 - not attempted
if (!empty($r))
{
$outcome = $r['outcome_id'];
$call = $r['call_id'];
$a = is_on_appointment($call_attempt); //if we were on an appointment, complete it
if ($update && $a)
{
$sql = "UPDATE appointment
SET completed_call_id = '$call'
WHERE appointment_id = '$a'";
$db->Execute($sql);
}
}
else
{
if (!empty($a)) //made an appointment without making a call
$outcome = 20;
}
return $outcome;
}
*/
/** /**
* End the current call attempt * End the current call attempt
* *
@@ -1131,6 +1112,10 @@ function end_call_attempt($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$return = false;
$ca = get_call_attempt($operator_id); $ca = get_call_attempt($operator_id);
if ($ca) if ($ca)
@@ -1143,15 +1128,13 @@ function end_call_attempt($operator_id)
$o = $db->Execute($sql); $o = $db->Execute($sql);
$db->CompleteTrans(); $return = true;
return $o;
}
else
{
return false;
} }
if ($db->CompleteTrans())
return $return;
return $false;
} }
/** /**
@@ -1189,12 +1172,14 @@ function get_call_attempt($operator_id)
{ {
global $db; global $db;
$db->StartTrans();
$case_id = get_case_id($operator_id,false); $case_id = get_case_id($operator_id,false);
$id = false;
if ($case_id) if ($case_id)
{ {
$db->StartTrans();
$sql = "SELECT call_attempt_id $sql = "SELECT call_attempt_id
FROM `call_attempt` FROM `call_attempt`
WHERE case_id = '$case_id' WHERE case_id = '$case_id'
@@ -1229,16 +1214,12 @@ function get_call_attempt($operator_id)
{ {
$id = $row['call_attempt_id']; $id = $row['call_attempt_id'];
} }
}
if ($db->CompleteTrans())
$db->CompleteTrans();
return $id; return $id;
}
else
{
return false;
}
return false;
} }
/** /**
@@ -1257,6 +1238,10 @@ function end_call($operator_id,$outcome_id,$state = 5)
{ {
global $db; global $db;
$db->StartTrans();
$o = false;
$ca = get_call($operator_id); $ca = get_call($operator_id);
if ($ca) if ($ca)
@@ -1278,15 +1263,13 @@ function end_call($operator_id,$outcome_id,$state = 5)
SET end = CONVERT_TZ(NOW(),'System','UTC'), outcome_id = '$outcome_id', state = '$state' SET end = CONVERT_TZ(NOW(),'System','UTC'), outcome_id = '$outcome_id', state = '$state'
WHERE call_id = '$ca'"; WHERE call_id = '$ca'";
$o = $db->Execute($sql); $db->Execute($sql);
}
if ($db->CompleteTrans())
return $o; return $o;
}
else
{
return false;
}
return false;
} }
/** /**
@@ -1312,7 +1295,8 @@ function get_limesurvey_id($operator_id)
$rs = $db->GetRow($sql); $rs = $db->GetRow($sql);
if (empty($rs)) return false; if (empty($rs))
return false;
return $rs['lime_sid']; return $rs['lime_sid'];