ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
class.ilAssQuestionTypeOrderer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
19  const ORDER_MODE_FIX = 'fix';
20 
24  const ORDER_MODE_ALPHA = 'alpha';
25 
31  static $fixQuestionTypeOrder = array(
32  'assSingleChoice',
33  'assMultipleChoice',
34  'assKprimChoice',
35 
36  'assErrorText',
37  'assImagemapQuestion',
38 
39  'assClozeTest',
40  'assNumeric',
41  'assFormulaQuestion',
42  'assTextSubset',
43 
44  'assOrderingQuestion',
45  'assOrderingHorizontal',
46  'assMatchingQuestion',
47 
48  'assTextQuestion',
49  'assFileUpload',
50  'assLongMenu',
51 
52  'assFlashQuestion',
53  'assJavaApplet',
54  );
55 
62 
70  public function __construct($unOrderedTypes, $orderMode = self::ORDER_MODE_ALPHA)
71  {
72  self::$flippedQuestionTypeOrder = array_flip(self::$fixQuestionTypeOrder);
73  #vd($unOrderedTypes);
74  $this->types = $unOrderedTypes;
75 
76  switch($orderMode)
77  {
78  case self::ORDER_MODE_FIX:
79 
80  uasort($this->types, array($this, 'fixQuestionTypeOrderSortCallback'));
81  break;
82 
83  case self::ORDER_MODE_ALPHA:
84 
85  ksort($this->types);
86  break;
87 
88  default:
89 
90  throw new ilTestQuestionPoolException('invalid order mode given: '.$orderMode);
91  }
92 
93  #vd($this->types);
94  }
95 
101  public function getOrderedTypes()
102  {
103  return $this->types;
104  }
105 
114  public function fixQuestionTypeOrderSortCallback($a, $b)
115  {
116  if( self::$flippedQuestionTypeOrder[ $a['type_tag'] ] > self::$flippedQuestionTypeOrder[ $b['type_tag'] ] )
117  {
118  return 1;
119  }
120  elseif( !isset(self::$flippedQuestionTypeOrder[ $a['type_tag'] ]) )
121  {
122  return 1;
123  }
124  elseif( self::$flippedQuestionTypeOrder[ $a['type_tag'] ] < self::$flippedQuestionTypeOrder[ $b['type_tag'] ] )
125  {
126  return -1;
127  }
128  elseif( !isset(self::$flippedQuestionTypeOrder[ $b['type_tag'] ]) )
129  {
130  return -1;
131  }
132 
133  return 0;
134  }
135 
136 }
const ORDER_MODE_FIX
order mode with fixed priority for ordering
const ORDER_MODE_ALPHA
order mode that orders by alphanumerical priority
__construct($unOrderedTypes, $orderMode=self::ORDER_MODE_ALPHA)
Constructor.
getOrderedTypes()
getter for ordered question types
fixQuestionTypeOrderSortCallback($a, $b)
custom sort callback for ordering the question types