Hi, sorry for butting into the discussion, I am sure it has been resolved since then, but thought it might be useful to add a working code here, if anyone needs a clear, simple solution.
The basic setup is that you operate with two questionnaires. One is your "base" questionnaire, where you record all quota related info (and in general, where you have your sruve) and then you have a second questionnaire that is for internal use to "count" the quotas.
Code in Base Questionnaire:
// Pages where quota is set up. SA01 is direct question about gender, and QU01_01 is internal variable to save info from SA01, IF respondent arrives to last page.
<!-- Page 1 -->
//Adds internal variable Q01_01 to questionnaire
<question id="QU01" intID="93" />
<!-- Page 2-->
//Creates quotas and manages if quotas are fill
$quotaGender = [
1 => 50, // 1 Women (Code 01)
2 => 50, // 0 Men (Code 02)
];
$gender = value('SA01');
$maxPerGender = $quotaGender[$gender];
$casesGender = statistic('count', 'QU01_01', $gender);
if ($casesGender >= $maxPerGender) {
redirect('EXTERNAL LINK');
}
<!-- Page 4-->
// Note: there needs to be a page with a "normal" question between pages of quota definition and put() command
$gender = value('SA01');
put('QU01_01', $gender);
Code in "Counting" Questionnaire:
//Essentially a single page that gives the information. In the html I manually added the number of cases I would want to reach in brackets.
// Gender-Information
$casesGender1 = statistic('count', 'QU01_01', 1);
$casesGender2 = statistic('count', 'QU01_01', 2);
html('<p><b>Gender Quotas</b></p>');
html('<p>Female '.$casesGender1.' (50)</p>');
html('<p>Male '.$casesGender2.' (50)</p>');