Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
en:create:functions:setpageorder [07.12.2017 17:28] – [PHP-Code] janinejulianerpen:create:functions:setpageorder [29.09.2020 17:49] sophia.schauer
Line 27: Line 27:
 **Note:** Filters can be inserted within the page order by using ''goToPage()''. If the filter jumps to a page within the ongoing page order, the sequence will be resumed there. If the filter jumps to a page outside of the page order, the normal page order in the questionnaire will be resumed from this page onwards. **Note:** Filters can be inserted within the page order by using ''goToPage()''. If the filter jumps to a page within the ongoing page order, the sequence will be resumed there. If the filter jumps to a page outside of the page order, the normal page order in the questionnaire will be resumed from this page onwards.
  
-===== Example 1 =====+In the following the use of ''setPageOrder()'' in connection with a [[:en:create:randomization]] or [[:en:create:rotation]] is illustrated by several examples. 
 + 
 +===== Two possible processes =====
  
 The following scenario should be implemented using ''setPageOrder()''. There are two question blocks  in the questionnaire: one of which is comprised of 5 pages and the other one of 7 pages. In one half of the questionnaire, Block A should be shown first and then Block B, and in the other half of the questionnaire, Block B should be shown first and then Block A.  The following scenario should be implemented using ''setPageOrder()''. There are two question blocks  in the questionnaire: one of which is comprised of 5 pages and the other one of 7 pages. In one half of the questionnaire, Block A should be shown first and then Block B, and in the other half of the questionnaire, Block B should be shown first and then Block A. 
Line 60: Line 62:
  
  
-===== Example 2 =====+===== Random sequence I =====
  
 The questionnaire contains 5 pages that shall be displayed in random order. The questionnaire contains 5 pages that shall be displayed in random order.
Line 74: Line 76:
 <code php> <code php>
 if (!isset($pages)) { if (!isset($pages)) {
-  $pages = array('LA', 'GE');+  $pages = array('PA', 'PB', 'PC', 'PD', 'PE');
   shuffle($pages);   shuffle($pages);
-  $pages[] = 'EM';+  $pages[] = 'PX';
   registerVariable($pages);   registerVariable($pages);
 } }
Line 97: Line 99:
 </code> </code>
  
 +===== Random sequence II =====
  
 +In this example there are 3 blocks (A, B, C) with 3 to 5 pages (A1, A2, A3, B1, ...). The order of the blocks should be shuffled randomly and additionally the pages should be shuffled within each block -- only the first one should always stay at the beginning.
 +
 +**Note:** See also the example under Rotation -> [[:en:create:rotation#rotation_and_mix_of_blocks|Rotation and Mixing of Blocks]].
 +
 +==== Preparation ====
 +
 +If the individual pages are to be rotated, each page requires its own [[:en: glossary#page_ID]]. For the example the pages were named as follows: A1, A2, A3, B1 to B5, C1 to C4, and after C4 follows page D1, where the rotation should continue.
 +
 +==== PHP-Code ====
 +
 +<code php>
 +// First save the page labels as array
 +$rotation = array(
 +  'A' => array('A1','A2','A3'),
 +  'B' => array('B1','B2','B3','B4','B5'),
 +  'C' => array('C1','C2','C3','C4')
 +);
 +// Mix each block individually
 +foreach ($rotation as $key => $pages) {
 +  // Remove the first page from the array $pages
 +  $first = array_shift($pages);
 +  // Mix the rest
 +  shuffle($pages);
 +  // Put the two back together again
 +  array_unshift($pages, $first);
 +  // And save back to the $rotation array
 +  $rotation[$key] = $pages;
 +}
 +
 +// Now mix the order of the blocks randomly
 +shuffle($rotation);
 +
 +// Now set the result as page sequence
 +// Continue with page 'D1' afterwards
 +setPageOrder($rotation, 'D1');
 +</code>
  
-===== Example 3 =====+===== Save sequence =====
  
 In the survey project there are five topical question blocks. To simplify matters, these are put in sections ''R1'' to ''R5'' (this is optional). The question blocks are comprised of a different number of questions.   In the survey project there are five topical question blocks. To simplify matters, these are put in sections ''R1'' to ''R5'' (this is optional). The question blocks are comprised of a different number of questions.  
en/create/functions/setpageorder.txt · Last modified: 28.07.2022 21:58 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki