This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:create:functions:looppage [26.08.2020 22:23] – [loopPage()] sophia.schauer | en:create:functions:looppage [05.09.2023 23:00] (current) – swissel.uni-mannheim | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== loopPage() ====== | ====== loopPage() ====== | ||
- | '' | + | '' |
- | '' | + | '' |
- | '' | + | '' |
- | Repeats the page -- beginning | + | Repeats the page -- starting |
- | * // | + | * // |
- | * // | + | * // |
- | * //increment//\\ (optional) | + | * //Increment//\\ (optional) |
- | If only a nummeric | + | If only a numeric |
- | * //repetitions//\\ number of repetitions | + | * //repeats//\\ number of repetitions |
- | **Note:** To repeat more than one page, please use '' | ||
+ | If only one array is specified as parameter (// | ||
- | ===== Example ===== | + | * // |
- | <code php>// | + | **Note:** To repeat multiple pages, use '' |
- | // create, shuffle and cache list with questions | + | |
+ | **Note:** For sample code to use, see the instructions for '' | ||
+ | |||
+ | ===== Application examples ===== | ||
+ | |||
+ | ==== All questions of a rubric in random order ==== | ||
+ | |||
+ | <code php> | ||
+ | if (!isset($questions)) { | ||
+ | | ||
+ | $questions = getQuestions(' | ||
+ | // Shuffle and cache the list of questions (array) | ||
+ | shuffle($questions); | ||
+ | registerVariable($questions); | ||
+ | } | ||
+ | // Process all identifiers from the $questions list | ||
+ | $questions = loopPage($questions); | ||
+ | question($questions); | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Present questions in random order II ==== | ||
+ | |||
+ | <code php>// PHP-Code auf einer der ersten Seiten im Fragebogen | ||
+ | // Create, shuffle and cache list of questions | ||
$questions = array( | $questions = array( | ||
' | ' | ||
Line 29: | Line 53: | ||
); | ); | ||
shuffle($questions); | shuffle($questions); | ||
- | registerVariable('questions');</ | + | registerVariable($questions);</ |
- | <code php>// PHP code later in questionnaire | + | <code php>// PHP code later in the questionnaire |
$i = loopPage(6); | $i = loopPage(6); | ||
question($questions[$i]); | question($questions[$i]); | ||
</ | </ | ||
- | **Note:** As the same page is shown repeatedly, | + | In this example, |
- | <code php>// PHP code later in questionnaire - page 21 | + | ==== Questions in random order with dwell time ==== |
+ | |||
+ | **Note:** Because the same page is displayed again and again, the response times for all repetitions are added. If you want to collect the processing times separately, you have to use multiple pages instead of '' | ||
+ | |||
+ | <code php>// PHP code on one of the first pages in the questionnaire. | ||
+ | // Create, shuffle and cache list of questions | ||
+ | $questions = array( | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | shuffle($questions); | ||
+ | registerVariable($questions);</ | ||
+ | |||
+ | <code php>// PHP code later in the questionnaire - page 21 | ||
question($questions[0]); | question($questions[0]); | ||
Line 44: | Line 81: | ||
question($questions[1]); | question($questions[1]); | ||
- | // and so on. | + | // etc. |
// PHP code on page 26 | // PHP code on page 26 | ||
question($questions[5]); | question($questions[5]); | ||
</ | </ | ||
+ | |||
+ | |||
+ | ===== Workaround for page sequence ===== | ||
+ | |||
+ | Within a page order defined by '' | ||
+ | |||
+ | If you want to repeat a page within a page sequence, then define this repetition already in the page sequence. In the following example, for example, the page with the identifier " | ||
+ | |||
+ | <code php> | ||
+ | setPageOrder([' | ||
+ | </ | ||
+ | |||
+ | To determine which repeat the page is currently in, you can use the function '' | ||
+ | |||
+ | Here you could simply subtract 3. But if the repetition appears in a different place in the questionnaire, | ||
+ | |||
+ | <code php> | ||
+ | // Determine the current position | ||
+ | $pos = loopIndex(); | ||
+ | // Check if we already know the first position of this page | ||
+ | if (!isset($firstIndex)) { | ||
+ | $firstIndex = $pos; | ||
+ | registerVariable($firstIndex); | ||
+ | } | ||
+ | // Store the different in variable $i | ||
+ | // this corresponds in other codes to $i = loopPage(...) | ||
+ | $i = $pos - $firstIndex; | ||
+ | </ | ||
+ | |||
+ | If you repeat several (different) pages, you must use a different variable name instead of '' |