Ich recycle gerade einen alten Fragebogen. Darin enthalten war ein Zufallsgenerator (Variablenname ZF06), sowie ein PhP Code der die Abfolge von 4 Blöcken (C1, C2, C3, C4) und einiger Seiten innerhalb eines Blocks mischt.
Der Zufallsgenerator befindet sich auf der Seite vor dem PhP Code, und hat den folgenden Inhalt:
1 = C1in, C1p, C1ready, C1e1,C1d1,C1aed,C1d2,C1d3,C1aem,C1lcm,C1e2,C1d4,C1d5,C1aemps,C1d6,C1lcd,C1aempd,C1d7, C1done
2 = C1in, C1p, C1ready, C1d1,C1lcm,C1e1,C1d2,C1aed,C1d3,C1aem,C1d4,C1e2,C1lcd,C1d5,C1aemps,C1d6,C1d7,C1aempd, C1done
3 = C1in, C1p, C1ready, C1e1,C1d1,C1aed,C1d2,C1lcm,C1d3,C1d4,C1aem,C1d5,C1lcd,C1e2,C1d6,C1aemps,C1d7,C1aempd, C1done
4 = C1in, C1p, C1ready, C1d1,C1e1,C1d2,C1aed,C1lcm,C1d3,C1aem,C1e2,C1d4,C1lcd,C1d5,C1aemps,C1d6,C1aempd,C1d7, C1done
5 = C1in, C1p, C1ready, C1e1,C1lcm,C1d1,C1d2,C1aed,C1d3,C1aem,C1d4,C1e2,C1d5,C1aemps,C1d6,C1lcd,C1d7,C1aempd, C1done
6 = C1in, C1p, C1ready, C1e1,C1d1,C1lcm,C1aed,C1d2,C1aem,C1d3,C1lcd,C1d4,C1e2,C1d5,C1aemps,C1d6,C1d7,C1aempd, C1done
Der PhP Code lautet wie folgt:
//Block 1 mischen
$block1 = value('ZF06x1', 'label');
$pages1 = explode(',', $block1);
$freeIndices = array();
$freePages1a = array();
foreach ($pages1 as $i => $page) {
if (substr($page, 2, 2) == 'ae') {
$freeIndices[] = $i;
$freePages1a[] = $page;
}
}
shuffle($freePages1a);
foreach ($freePages1a as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages1[$orgIndex] = $page;
}
$freeIndices = array();
$freePages1b = array();
foreach ($pages1 as $i => $page) {
if (substr($page, 2, 2) == 'lc') {
$freeIndices[] = $i;
$freePages1b[] = $page;
}
}
shuffle($freePages1b);
foreach ($freePages1b as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages1[$orgIndex] = $page;
}
$vars = array(
'C1aem' => 'ZF09_01',
'C1aed' => 'ZF09_02',
'C1aemps' => 'ZF09_03',
'C1aempd' => 'ZF09_04',
'C1lcm' => 'ZF10_01',
'C1lcd' => 'ZF10_02',
);
foreach ($freePages1a as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
foreach ($freePages1b as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
$vars = array(
'C1aem' => 'ZF17_01',
'C1aed' => 'ZF17_02',
'C1aemps' => 'ZF17_03',
'C1aempd' => 'ZF17_04',
'C1lcm' => 'ZF21_01',
'C1lcd' => 'ZF21_02',
);
foreach ($pages1 as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
debug($block1); // Original-Abfolge
debug($pages1); // Gemischte Abfolge
debug($freePages1a);
debug($freePages1b);
//Block 2 mischen
$block2 = str_replace('C1', 'C2', value('ZF06x2', 'label'));
$pages2 = explode(',', $block2);
$freeIndices = array();
$freePages2a = array();
foreach ($pages2 as $i => $page) {
if (substr($page, 2, 2) == 'ae') {
$freeIndices[] = $i;
$freePages2a[] = $page;
}
}
shuffle($freePages2a);
foreach ($freePages2a as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages2[$orgIndex] = $page;
}
$freeIndices = array();
$freePages2b = array();
foreach ($pages2 as $i => $page) {
if (substr($page, 2, 2) == 'lc') {
$freeIndices[] = $i;
$freePages2b[] = $page;
}
}
shuffle($freePages2b);
foreach ($freePages2b as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages2[$orgIndex] = $page;
}
$vars = array(
'C2aem' => 'ZF11_01',
'C2aed' => 'ZF11_02',
'C2aemps' => 'ZF11_03',
'C2aempd' => 'ZF11_04',
'C2lcm' => 'ZF14_01',
'C2lcd' => 'ZF14_02',
);
foreach ($freePages2a as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
foreach ($freePages2b as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
$vars = array(
'C2aem' => 'ZF18_01',
'C2aed' => 'ZF18_02',
'C2aemps' => 'ZF18_03',
'C2aempd' => 'ZF18_04',
'C2lcm' => 'ZF22_01',
'C2lcd' => 'ZF22_02',
);
foreach ($pages2 as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
debug($block2); // Original-Abfolge
debug($pages2); // Gemischte Abfolge
debug($freePages2a);
debug($freePages2b);
//Block 3 mischen
$block3 = str_replace('C1', 'C3', value('ZF06x3', 'label'));
$pages3 = explode(',', $block3);
$freeIndices = array();
$freePages3a = array();
foreach ($pages3 as $i => $page) {
if (substr($page, 2, 2) == 'ae') {
$freeIndices[] = $i;
$freePages3a[] = $page;
}
}
shuffle($freePages3a);
foreach ($freePages3a as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages3[$orgIndex] = $page;
}
$freeIndices = array();
$freePages3b = array();
foreach ($pages3 as $i => $page) {
if (substr($page, 2, 2) == 'lc') {
$freeIndices[] = $i;
$freePages3b[] = $page;
}
}
shuffle($freePages3b);
foreach ($freePages3b as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages3[$orgIndex] = $page;
}
$vars = array(
'C3aem' => 'ZF12_01',
'C3aed' => 'ZF12_02',
'C3aemps' => 'ZF12_03',
'C3aempd' => 'ZF12_04',
'C3lcm' => 'ZF15_01',
'C3lcd' => 'ZF15_02',
);
foreach ($freePages3a as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
foreach ($freePages3b as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
$vars = array(
'C3aem' => 'ZF19_01',
'C3aed' => 'ZF19_02',
'C3aemps' => 'ZF19_03',
'C3aempd' => 'ZF19_04',
'C3lcm' => 'ZF23_01',
'C3lcd' => 'ZF23_02',
);
foreach ($pages3 as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
debug($block3); // Original-Abfolge
debug($pages3); // Gemischte Abfolge
debug($freePages3a);
debug($freePages3b);
//Block 4 mischen
$block4 = str_replace('C1', 'C4', value('ZF06x4', 'label'));
$pages4 = explode(',', $block4);
$freeIndices = array();
$freePages4a = array();
foreach ($pages4 as $i => $page) {
if (substr($page, 2, 2) == 'ae') {
$freeIndices[] = $i;
$freePages4a[] = $page;
}
}
shuffle($freePages4a);
foreach ($freePages4a as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages4[$orgIndex] = $page;
}
$freeIndices = array();
$freePages4b = array();
foreach ($pages4 as $i => $page) {
if (substr($page, 2, 2) == 'lc') {
$freeIndices[] = $i;
$freePages4b[] = $page;
}
}
shuffle($freePages4b);
foreach ($freePages4b as $j => $page) {
$orgIndex = $freeIndices[$j];
$pages4[$orgIndex] = $page;
}
$vars = array(
'C4aem' => 'ZF13_01',
'C4aed' => 'ZF13_02',
'C4aemps' => 'ZF13_03',
'C4aempd' => 'ZF13_04',
'C4lcm' => 'ZF16_01',
'C4lcd' => 'ZF16_02',
);
foreach ($freePages4a as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
foreach ($freePages4b as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
$vars = array(
'C4aem' => 'ZF20_01',
'C4aed' => 'ZF20_02',
'C4aemps' => 'ZF20_03',
'C4aempd' => 'ZF20_04',
'C4lcm' => 'ZF24_01',
'C4lcd' => 'ZF24_02',
);
foreach ($pages4 as $rank => $page) {
if (isset($vars[$page])) {
put($vars[$page], $rank+1);
}
}
debug($block4); // Original-Abfolge
debug($pages4); // Gemischte Abfolge
debug($freePages4a);
debug($freePages4b);
// Erst einmal die Blöcke als Array speichern
$blocks = array($pages1, $pages2, $pages3, $pages4);
// Jetzt noch die Reihenfolge der Blöcke zufällig mischen
shuffle($blocks);
for ($i=0; $i<count($blocks); $i++) {
// Kennung der internen Variable aus Frage-Kennung plus Index erstellen
$id = id('ZF05', $i + 1);
// Hier den Wert aus dem Array speichern
put($id, $blocks[$i][0]);
}
// Jetzt das Ergebnis noch als Seitenabfolge festlegen
// Weiter soll es anschließend mit Seite 'FQ0' gehen
setPageOrder($blocks, 'FQ0');
debug($blocks);
Jedoch erhalte ich jetzt beim Testen des Fragebogens immer die Meldung:
Variable ZF06x1 is unknown to this project (see listing of variables).
Therefore no result can be retrieved.
Variable ZF06x2 is unknown to this project (see listing of variables).
Therefore no result can be retrieved.
Variable ZF06x3 is unknown to this project (see listing of variables).
Therefore no result can be retrieved.
ariable ZF06x4 is unknown to this project (see listing of variables).
Therefore no result can be retrieved.
Was läuft hier denn falsch?