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

Added PERCCOMPLETE token to enhance respondent selection scripts

Displays percentage complete of the main case instrument
Also can be used as a token for limesurvey conditions (i.e. check for it being > 0 to say "we have already started")
This commit is contained in:
azammitdcarf
2010-10-18 02:05:15 +00:00
parent 3586883a71
commit f7b418fb13
2 changed files with 105 additions and 15 deletions

View File

@@ -6152,6 +6152,7 @@ function GetTokenConditionsFieldNames($surveyid)
$basic_attrs=Array('firstname','lastname','email','token','language','sent','remindersent','remindercount');
$basic_attrs[] = 'callattempts'; //queXS addition
$basic_attrs[] = 'onappointment'; //queXS addition
$basic_attrs[] = 'perccomplete'; //queXS addition
return array_merge($basic_attrs,$extra_attrs);
}
@@ -6172,6 +6173,7 @@ function GetTokenFieldsAndNames($surveyid, $onlyAttributes=false)
$basic_attrs=Array('firstname','lastname','email','token','language','sent','remindersent','remindercount');
$basic_attrs[] = 'callattempts'; //queXS addition
$basic_attrs[] = 'onappointment'; //queXS addition
$basic_attrs[] = 'perccomplete'; //queXS addition
$basic_attrs_names=Array(
$clang->gT('First Name'),
$clang->gT('Last Name'),
@@ -6184,6 +6186,7 @@ function GetTokenFieldsAndNames($surveyid, $onlyAttributes=false)
$basic_attrs_names[] = $clang->gT('queXS: Number of call attempts'); //queXS addition
$basic_attrs_names[] = $clang->gT('queXS: On appointment?'); //queXS addition
$basic_attrs_names[] = $clang->gT('queXS: Percentage complete'); //queXS addition
$thissurvey=getSurveyInfo($surveyid);
$attdescriptiondata=!empty($thissurvey['attributedescriptions']) ? $thissurvey['attributedescriptions'] : "";
@@ -6236,7 +6239,7 @@ function GetAttributeValue($surveyid,$attrName,$token)
$sanitized_token=$connect->qstr($token,get_magic_quotes_gpc());
$surveyid=sanitize_int($surveyid);
if ($attrName == 'callattempts' || $attrName == 'onappointment') //queXS addition
if ($attrName == 'callattempts' || $attrName == 'onappointment' || $attrName == 'perccomplete') //queXS addition
{
include_once("quexs.php");
$quexs_operator_id = get_operator_id();
@@ -6247,6 +6250,8 @@ function GetAttributeValue($surveyid,$attrName,$token)
return get_call_attempts($quexs_case_id);
else if ($attrName == 'onappointment')
return is_on_appointment($quexs_case_id,$quexs_operator_id);
else if ($attrName == 'perccomplete')
return get_percent_complete($quexs_case_id);
}
else
return 0;

View File

@@ -35,6 +35,50 @@
*/
require_once(dirname(__FILE__).'/../../config.inc.php');
/**
* Return the percent complete a questionnaire is, or 0 if not started
*
* @param int $case_id The case id
* @return bool|float False if no data, otherwise the percentage of questions answered
*
*/
function get_percent_complete($case_id)
{
$db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$sql = "SELECT l.saved_thisstep, q.lime_sid
FROM ". LIME_PREFIX ."saved_control as l, questionnaire as q, `case` as c
WHERE c.case_id = '$case_id'
AND q.questionnaire_id = c.questionnaire_id
AND l.sid = q.lime_sid
AND l.identifier = '$case_id'";
$r = $db->GetRow($sql);
if (!empty($r))
{
$step = $r['saved_thisstep'];
$lime_sid = $r['lime_sid'];
$sql = "SELECT count(qid) as c
FROM " . LIME_PREFIX . "questions
WHERE sid = '$lime_sid'";
$qs = $db->GetRow($sql);
$questions = 1;
if (!empty($qs))
$questions = $qs['c'];
return ($step / $questions) * 100.0;
}
return 0;
}
/**
* Return the phone number of the latest appointment for this respondent
*
@@ -490,6 +534,12 @@ function quexs_template_replace($string)
$string=str_ireplace("{CALLATTEMPTS}", $call_attempts, $string);
}
while (stripos($string, "{RESPONDENTSELECTIONURL}") !== false)
{
$url = get_respondent_selection_url();
$string=str_ireplace("{RESPONDENTSELECTIONURL}", $url, $string);
}
while (stripos($string, "{ONAPPOINTMENT}") !== false)
{
$on_appointment = is_on_appointment($case_id,$operator_id);
@@ -504,6 +554,7 @@ function quexs_template_replace($string)
if (stripos($string, "{APPOINTMENTDATE}") !== false) $string=str_ireplace("{APPOINTMENTDATE}", get_appointment_date($respondent_id), $string);
if (stripos($string, "{APPOINTMENTTIME}") !== false) $string=str_ireplace("{APPOINTMENTTIME}", get_appointment_time($respondent_id), $string);
if (stripos($string, "{APPOINTMENTNUMBER}") !== false) $string=str_ireplace("{APPOINTMENTNUMBER}", get_appointment_number($respondent_id), $string);
if (stripos($string, "{PERCCOMPLETE}") !== false) $string=str_ireplace("{PERCCOMPLETE}", round(get_percent_complete($case_id),0), $string);
return $string;
}
@@ -512,30 +563,36 @@ function quexs_template_replace($string)
* Get the limesurvey "survey id" of the current questionnaire assigned to the operator
*
* @param int $operator_id The operator
* @param bool $rs Whether or not to get the respondent selection URL
* @return bool|int False if none found else the limesurvey sid
*
*/
function get_limesurvey_id($operator_id)
function get_limesurvey_id($operator_id,$rs = false)
{
$db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$sql = "SELECT q.lime_sid as lime_sid
FROM `case` as c, questionnaire_sample as qs, sample as s, questionnaire as q
WHERE c.current_operator_id = '$operator_id'
AND c.sample_id = s.sample_id
AND s.import_id = qs.sample_import_id
AND q.questionnaire_id = qs.questionnaire_id
AND c.questionnaire_id = q.questionnaire_id";
$sql = "";
$rs = $db->GetRow($sql);
if ($rs)
$sql = "SELECT q.lime_rs_sid as sid";
else
$sql = "SELECT q.lime_sid as sid";
if (empty($rs))
return false;
$sql .= " FROM `case` as c, questionnaire_sample as qs, sample as s, questionnaire as q
WHERE c.current_operator_id = '$operator_id'
AND c.sample_id = s.sample_id
AND s.import_id = qs.sample_import_id
AND q.questionnaire_id = qs.questionnaire_id
AND c.questionnaire_id = q.questionnaire_id";
return $rs['lime_sid'];
$rr = $db->GetRow($sql);
if (empty($rr))
return false;
return $rr['sid'];
}
@@ -566,6 +623,36 @@ function get_questionnaire_id($operator_id)
}
/**
* Get the URL of the respondent selection module
*
* @return string The URL of the respondent selection script
* @author Adam Zammit <adam.zammit@acspri.org.au>
* @since 2010-10-12
*/
function get_respondent_selection_url()
{
$db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$url = QUEXS_URL . "nocallavailable.php";
$operator_id = get_operator_id($operator_id);
$call_id = get_call($operator_id);
if ($call_id)
{
$sid = get_limesurvey_id($operator_id,true); //true for RS
if ($sid != false && !empty($sid) && $sid != 'NULL')
$url = LIME_URL . "index.php?loadall=reload&amp;sid=$sid&amp;token=$call_id&amp;lang=" . DEFAULT_LOCALE;
else
$url = 'rs_intro.php';
}
return $url;
}
/**
* Get start interviewer URL
@@ -603,8 +690,6 @@ function get_start_interview_url()
}
}
//if ($db->HasFailedTrans()) { print "FAILED in get_limesurvey_url"; exit; }
$db->CompleteTrans();
return $url;