This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:create:functions:looppage [14.05.2016 21:27] – [loopPage()] admin | en:create:functions:looppage [05.09.2023 23:00] (current) – swissel.uni-mannheim | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== loopPage() ====== | ====== loopPage() ====== | ||
- | '' | + | '' |
- | '' | + | '' |
- | Repeats the page -- beginning with the //start value// -- in a loop as often as it takes until the //end value// is reached. The current value is returned each time. | + | '' |
- | * // | + | Repeats |
- | * // | + | |
- | * //increment//\\ (optional) change in value on every loop pass (standard: 1) -- you can create an endless | + | |
- | If only one parameter (//repetitions//) is specified | + | * //startValue//\\ The value at the first pass. |
+ | * // | ||
+ | * // | ||
- | * //repetitions//\\ number of repetitions | + | If only a numeric parameter (//repeats//) is specified, the page will be repeated as many times as specified. The count variable starts with 0 in this case. |
- | **Note:** To repeat more than one page, please use '' | + | |
- | ===== Example ===== | + | If only one array is specified as parameter (// |
- | <code php>// | + | * // |
- | // create, shuffle and cache list with questions | + | |
+ | **Note:** To repeat multiple pages, use '' | ||
+ | |||
+ | **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 27: | 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 42: | 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 '' |