ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilAssLacCompositeValidator Class Reference

Class CompositeValidator. More...

+ Collaboration diagram for ilAssLacCompositeValidator:

Public Member Functions

 __construct ($object_loader)
 
 validate (ilAssLacAbstractComposite $composite)
 

Protected Member Functions

 getNonShuffler ()
 

Protected Attributes

 $object_loader
 

Private Member Functions

 validateSubTree (ilAssLacAbstractComposite $composite)
 
 validateClozeTest ($answer_index, $question, $answer_expression, $question_index)
 
 checkIfAnswerIndexOfQuestionExists ($question, $question_index, $answer_index)
 
 checkQuestionExists ($question, $index)
 
 isResultOfAnswerExpression ($expression)
 
 checkAnswerExpressionExist ($expressions, $answer_expression, $question_index)
 
 checkOperatorExistForExpression ($operators, $answer_expression, $pattern)
 

Detailed Description

Class CompositeValidator.

Date: 04.12.13 Time: 14:19

Author
Thomas Joußen tjous.nosp@m.sen@.nosp@m.datab.nosp@m.ay.d.nosp@m.e

Definition at line 22 of file ilAssLacCompositeValidator.php.

Constructor & Destructor Documentation

◆ __construct()

ilAssLacCompositeValidator::__construct (   $object_loader)
Parameters
ilAssLacQuestionProvider$object_loader

Definition at line 35 of file ilAssLacCompositeValidator.php.

36 {
37 $this->object_loader = $object_loader;
38 }

References $object_loader.

Member Function Documentation

◆ checkAnswerExpressionExist()

ilAssLacCompositeValidator::checkAnswerExpressionExist (   $expressions,
  $answer_expression,
  $question_index 
)
private
Parameters
array$expressions
ilAssLacExpressionInterface$answer_expression
int$question_index
Exceptions
ilAssLacExpressionNotSupportedByQuestion

Definition at line 252 of file ilAssLacCompositeValidator.php.

253 {
254 if(!in_array($answer_expression::$identifier, $expressions))
255 {
256 throw new ilAssLacExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index);
257 }
258 }

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ checkIfAnswerIndexOfQuestionExists()

ilAssLacCompositeValidator::checkIfAnswerIndexOfQuestionExists (   $question,
  $question_index,
  $answer_index 
)
private
Parameters
iQuestionCondition$question
int$question_index
int$answer_index
Exceptions
ilAssLacAnswerIndexNotExist

Definition at line 202 of file ilAssLacCompositeValidator.php.

203 {
204 $answer_options = $question->getAvailableAnswerOptions($answer_index);
205 if($answer_options == null)
206 {
207 throw new ilAssLacAnswerIndexNotExist($question_index, $answer_index+1);
208 }
209 }

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ checkOperatorExistForExpression()

ilAssLacCompositeValidator::checkOperatorExistForExpression (   $operators,
  $answer_expression,
  $pattern 
)
private
Parameters
array$operators
ilAssLacExpressionInterface$answer_expression
string$pattern
Exceptions
ilAssLacOperatorNotSupportedByExpression

Definition at line 267 of file ilAssLacCompositeValidator.php.

268 {
269 if(!in_array($pattern, $operators))
270 {
271 throw new ilAssLacOperatorNotSupportedByExpression($answer_expression->getValue(),$pattern);
272 }
273 }

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ checkQuestionExists()

ilAssLacCompositeValidator::checkQuestionExists (   $question,
  $index 
)
private
Parameters
assQuestion | null$question
int$index
Exceptions
ilAssLacQuestionNotExist

Definition at line 217 of file ilAssLacCompositeValidator.php.

218 {
219 if($question == null)
220 {
221 throw new ilAssLacQuestionNotExist($index);
222 }
223 }

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ getNonShuffler()

ilAssLacCompositeValidator::getNonShuffler ( )
protected

Definition at line 275 of file ilAssLacCompositeValidator.php.

276 {
277 require_once 'Services/Randomization/classes/class.ilArrayElementOrderKeeper.php';
278 return new ilArrayElementOrderKeeper();
279 }

◆ isResultOfAnswerExpression()

ilAssLacCompositeValidator::isResultOfAnswerExpression (   $expression)
private
Parameters
ilAssLacExpressionInterface$expression
Returns
bool

Definition at line 230 of file ilAssLacCompositeValidator.php.

231 {
232 if( $expression instanceof ilAssLacResultOfAnswerOfQuestionExpression )
233 {
234 return true;
235 }
236
237 if( $expression instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression )
238 {
239 return true;
240 }
241
242 return false;
243 }
Class ResultOfAnswerOfCurrentQuestion for the expression R[m].
Class ResultOfAnswerOfQuestion for the expression Qn[m].

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ validate()

ilAssLacCompositeValidator::validate ( ilAssLacAbstractComposite  $composite)

Definition at line 40 of file ilAssLacCompositeValidator.php.

41 {
42 if(count($composite->nodes) > 0)
43 {
44 $this->validate($composite->nodes[0]);
45 $this->validate($composite->nodes[1]);
46 $this->validateSubTree($composite);
47 }
48
49 return;
50 }
validateSubTree(ilAssLacAbstractComposite $composite)
validate(ilAssLacAbstractComposite $composite)

References validate(), and validateSubTree().

Referenced by validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateClozeTest()

ilAssLacCompositeValidator::validateClozeTest (   $answer_index,
  $question,
  $answer_expression,
  $question_index 
)
private
Parameters
int$answer_index
assQuestion | iQuestionCondition$question
ilAssLacExpressionInterface$answer_expression
int$question_index
Exceptions
ilAssLacAnswerValueNotExist

Definition at line 134 of file ilAssLacCompositeValidator.php.

135 {
136 if($answer_index !== null)
137 {
138 $options = $question->getAvailableAnswerOptions($answer_index);
139 $found = false;
140 switch($options->getType())
141 {
142 case 0: // text
143 if(
144 $answer_expression instanceof ilAssLacStringResultExpression
145 )
146 {
147 $found = true;
148 }
149
150 break;
151 case 1: // select
152
153 if($answer_expression instanceof ilAssLacStringResultExpression)
154 {
155 foreach($options->getItems($this->getNonShuffler()) as $item)
156 {
157 if($item->getAnswertext() == $answer_expression->getText())
158 {
159 $found = true;
160 }
161 }
162 }
163 elseif($answer_expression instanceof ilAssLacNumberOfResultExpression)
164 {
165
166 foreach($options->getItems($question->getShuffler()) as $item)
167 {
168 if($item->getOrder() == $answer_expression->getNumericValue()-1)
169 {
170 $found = true;
171 }
172 }
173 }
174 break;
175 case 2: // numeric
176 if($answer_expression instanceof ilAssLacNumericResultExpression)
177 {
178 $found = true;
179 }
180 break;
181 }
182
183 if($answer_expression instanceof ilAssLacEmptyAnswerExpression)
184 {
185 $found = true;
186 }
187 if(!$found && !($answer_expression instanceof ilAssLacPercentageResultExpression))
188 {
189 throw new ilAssLacAnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index+1);
190 }
191
192 }
193 }
Class NumberOfResultExpression fot the expression +n+.
Class NumericResultExpression for the expression #n#.
Class PercentageResultExpression for the expression n%.
Class StringResultExpression for the expression ~TEXT~.
if(!is_array($argv)) $options

References $options.

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ validateSubTree()

ilAssLacCompositeValidator::validateSubTree ( ilAssLacAbstractComposite  $composite)
private

Definition at line 52 of file ilAssLacCompositeValidator.php.

53 {
54 if($composite->nodes[0] instanceof ilAssLacQuestionExpressionInterface &&
55 $composite->nodes[1] instanceof ilAssLacSolutionExpressionInterface
56 ){
57 $question_expression = $composite->nodes[0];
58 $answer_expression = $composite->nodes[1];
59 $question_index = $composite->nodes[0]->getQuestionIndex();
60 $answer_index = null;
61 $question = $this->object_loader->getQuestion($question_index);
62
63 $this->checkQuestionExists($question, $question_index);
64 //$this->checkQuestionIsReachable($question, $question_index);
65
66 if($this->isResultOfAnswerExpression($question_expression))
67 {
68 $answer_index = $question_expression->getAnswerIndex()-1;
69 $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index);
70 }
71 if($answer_expression instanceof ilAssLacNumberOfResultExpression && !($question instanceof assClozeTest))
72 {
73 $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue()-1);
74 }
75
76 $this->checkAnswerExpressionExist($question->getExpressionTypes(), $answer_expression, $question_index);
77 $this->checkOperatorExistForExpression($question->getOperators($answer_expression::$identifier), $answer_expression, $composite::$pattern);
78
79 if($answer_expression instanceof ilAssLacOrderingResultExpression &&
80 ($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion )
81 )
82 {
83 foreach($answer_expression->getOrdering() as $order)
84 {
85 $count = 0;
86 foreach($answer_expression->getOrdering() as $element)
87 {
88 if($element == $order)
89 {
90 $count++;
91 }
92 }
93 if($count > 1)
94 {
95 throw new ilAssLacDuplicateElement($order);
96 }
97
98 $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order-1);
99 }
100 }
101 if($question instanceof assClozeTest)
102 {
103 $this->validateClozeTest($answer_index, $question, $answer_expression, $question_index);
104 }
105 elseif(
106 $answer_expression instanceof ilAssLacPercentageResultExpression &&
107 $this->isResultOfAnswerExpression($question_expression) &&
108 !($question instanceof assFormulaQuestion)
109 )
110 {
111 throw new ilAssLacExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[". ($answer_index+1) . "]");
112 }
113 }
114 elseif(
115 ($composite->nodes[0] instanceof ilAssLacAbstractOperation &&
116 $composite->nodes[1] instanceof ilAssLacExpressionInterface) ||
117 ($composite->nodes[0] instanceof ilAssLacExpressionInterface &&
118 $composite->nodes[1] instanceof ilAssLacAbstractOperation) ||
119 ($composite->nodes[0] instanceof ilAssLacSolutionExpressionInterface)
120 )
121 {
122 throw new ilAssLacUnableToParseCondition("");
123 }
124 }
Class for cloze tests.
Class for single choice questions assFormulaQuestion is a class for single choice questions.
Class for horizontal ordering questions.
Class for ordering questions.
validateClozeTest($answer_index, $question, $answer_expression, $question_index)
checkAnswerExpressionExist($expressions, $answer_expression, $question_index)
checkOperatorExistForExpression($operators, $answer_expression, $pattern)
checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index)
Class OrderingResultExpression for the expression $a,..,n,m$.

References checkAnswerExpressionExist(), checkIfAnswerIndexOfQuestionExists(), checkOperatorExistForExpression(), checkQuestionExists(), isResultOfAnswerExpression(), and validateClozeTest().

Referenced by validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $object_loader

ilAssLacCompositeValidator::$object_loader
protected

Definition at line 30 of file ilAssLacCompositeValidator.php.

Referenced by __construct().


The documentation for this class was generated from the following file: