Hi,
I'm running a survey in nine countries and want to use a quota to balance age and gender. I have written the following test syntax:
Quota values are saved to the internal variable on the previous page (will move to last page when I know it works). I create 72 quotas (9 countries 2 gender 4 age groups) of 250 respondents each. I read the respondent values and combine to a variable $demgroup.
//*****************************************************
// Quota redirect page
//*****************************************************
$quota = [
'1-1-1' => 250, '1-2-1' => 250, //
'2-1-1' => 250, '2-2-1' => 250, //
'3-1-1' => 250, '3-2-1' => 250, //
'4-1-1' => 250, '4-2-1' => 250, //
'1-1-2' => 250, '1-2-2' => 250, //
'2-1-2' => 250, '2-2-2' => 250, //
'3-1-2' => 250, '3-2-2' => 250, //
'4-1-2' => 250, '4-2-2' => 250, //
'1-1-3' => 250, '1-2-3' => 250, //
'2-1-3' => 250, '2-2-3' => 250, //
'3-1-3' => 250, '3-2-3' => 250, //
'4-1-3' => 250, '4-2-3' => 250, //
'1-1-4' => 250, '1-2-4' => 250, //
'2-1-4' => 250, '2-2-4' => 250, //
'3-1-4' => 250, '3-2-4' => 250, //
'4-1-4' => 250, '4-2-4' => 250, //
'1-1-5' => 250, '1-2-5' => 250, //
'2-1-5' => 250, '2-2-5' => 250, //
'3-1-5' => 250, '3-2-5' => 250, //
'4-1-5' => 250, '4-2-5' => 250, //
'1-1-6' => 250, '1-2-6' => 250, //
'2-1-6' => 250, '2-2-6' => 250, //
'3-1-6' => 250, '3-2-6' => 250, //
'4-1-6' => 250, '4-2-6' => 250, //
'1-1-7' => 250, '1-2-7' => 250, //
'2-1-7' => 250, '2-2-7' => 250, //
'3-1-7' => 250, '3-2-7' => 250, //
'4-1-7' => 250, '4-2-7' => 250, //
'1-1-8' => 250, '1-2-8' => 250, //
'2-1-8' => 250, '2-2-8' => 250, //
'3-1-8' => 250, '3-2-8' => 250, //
'4-1-8' => 250, '4-2-8' => 250, //
'1-1-9' => 250, '1-2-9' => 250, //
'2-1-9' => 250, '2-2-9' => 250, //
'3-1-9' => 250, '3-2-9' => 250, //
'4-1-9' => 250, '4-2-9' => 250, //
];
// Gender is read out directly
$gender = value('SD05');
debug($gender);
if ($gender == 1) {
$genderGroup = 1;
} elseif ($gender == 2) {
$genderGroup = 2;
} else {
$genderGroup = 0;
}
debug($genderGroup);
// The age is recoded
$age = 2025 - value('SD04_01');
debug($age);
if ($age < 18) {
$ageGroup = 0;
} elseif ($age <= 30) {
$ageGroup = 1;
} elseif ($age <= 50) {
$ageGroup = 2;
} elseif ($age <= 68) {
$ageGroup = 3;
} else {
$ageGroup = 4;
}
debug($ageGroup);
if (getLanguage() == 'eng') {
$countryGroup = 1;
} else if (getLanguage() == 'cze') {
$countryGroup = 2;
} else if (getLanguage() == 'hun') {
$countryGroup = 3;
} else if (getLanguage() == 'spa') {
$countryGroup = 4;
} else if (getLanguage() == 'dut') {
$countryGroup = 5;
} else if (getLanguage() == 'fre') {
$countryGroup = 5;
} else if (getLanguage() == 'ger') {
$countryGroup = 6;
} else if (getLanguage() == 'qaa') {
$countryGroup = 7;
} else if (getLanguage() == 'qab') {
$countryGroup = 8;
} else if (getLanguage() == 'gsw ') {
$countryGroup = 8;
} else if (getLanguage() == 'qac') {
$countryGroup = 9;
};
debug($countryGroup);
$demGroup = $ageGroup.'-'.$genderGroup.'-'.$countryGroup ;
debug($demGroup);
/////////////////////////////////////
// Retrieval of the available cases for this characteristic
$cases = statistic('count', 'QU01_04', $demGroup, true);
debug($cases);
// screenout
if (!array_key_exists($demGroup, $quota)) {
redirect('https://www.');
html('<p>Redirect Screenout</p>');
pageStop();
}
// Reading the quota for the demographic group
$maxPerGroup = $quota[$demGroup];
debug($maxPerGroup);
// quota stop
if ($cases >= $maxPerGroup) {
//redirect('https://www.');
html('<p>Redirect Quota stop</p>');
pageStop();
}
However, when I try to read out all the quota-case values as an array as below it does not show it correctly in the debug, and trying to print the array as a string in HTML code is not possible ("There is an error in the PHP code: Questionnaire Error: Array to string conversion").
$casesarray = statistic('frequencies', 'QU01_04', true); // get all case values
debug($casesarray);
What would be a good way to see the current number of respondents in all quota groups?