ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 220 of file ilAssLacCompositeValidator.php.

221 {
222 if (!in_array($answer_expression::$identifier, $expressions)) {
223 throw new ilAssLacExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index);
224 }
225 }

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 174 of file ilAssLacCompositeValidator.php.

175 {
176 $answer_options = $question->getAvailableAnswerOptions($answer_index);
177 if ($answer_options == null) {
178 throw new ilAssLacAnswerIndexNotExist($question_index, $answer_index + 1);
179 }
180 }

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 234 of file ilAssLacCompositeValidator.php.

235 {
236 if (!in_array($pattern, $operators)) {
237 throw new ilAssLacOperatorNotSupportedByExpression($answer_expression->getValue(), $pattern);
238 }
239 }

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 188 of file ilAssLacCompositeValidator.php.

189 {
190 if ($question == null) {
192 }
193 }
$index
Definition: metadata.php:60

References $index.

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ getNonShuffler()

ilAssLacCompositeValidator::getNonShuffler ( )
protected

Definition at line 241 of file ilAssLacCompositeValidator.php.

242 {
243 require_once 'Services/Randomization/classes/class.ilArrayElementOrderKeeper.php';
244 return new ilArrayElementOrderKeeper();
245 }

◆ isResultOfAnswerExpression()

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

Definition at line 200 of file ilAssLacCompositeValidator.php.

201 {
202 if ($expression instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
203 return true;
204 }
205
206 if ($expression instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression) {
207 return true;
208 }
209
210 return false;
211 }
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 $this->validate($composite->nodes[0]);
44 $this->validate($composite->nodes[1]);
45 $this->validateSubTree($composite);
46 }
47
48 return;
49 }
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 121 of file ilAssLacCompositeValidator.php.

122 {
123 if ($answer_index !== null) {
124 $options = $question->getAvailableAnswerOptions($answer_index);
125 $found = false;
126 switch ($options->getType()) {
127 case 0: // text
128 if (
129 $answer_expression instanceof ilAssLacStringResultExpression
130 ) {
131 $found = true;
132 }
133
134 break;
135 case 1: // select
136
137 if ($answer_expression instanceof ilAssLacStringResultExpression) {
138 foreach ($options->getItems($this->getNonShuffler()) as $item) {
139 if ($item->getAnswertext() == $answer_expression->getText()) {
140 $found = true;
141 }
142 }
143 } elseif ($answer_expression instanceof ilAssLacNumberOfResultExpression) {
144 foreach ($options->getItems($question->getShuffler()) as $item) {
145 if ($item->getOrder() == $answer_expression->getNumericValue() - 1) {
146 $found = true;
147 }
148 }
149 }
150 break;
151 case 2: // numeric
152 if ($answer_expression instanceof ilAssLacNumericResultExpression) {
153 $found = true;
154 }
155 break;
156 }
157
158 if ($answer_expression instanceof ilAssLacEmptyAnswerExpression) {
159 $found = true;
160 }
161 if (!$found && !($answer_expression instanceof ilAssLacPercentageResultExpression)) {
162 throw new ilAssLacAnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index + 1);
163 }
164 }
165 }
Class NumberOfResultExpression fot the expression +n+.
Class NumericResultExpression for the expression #n#.
Class PercentageResultExpression for the expression n%.
Class StringResultExpression for the expression ~TEXT~.

References PHPMailer\PHPMailer\$options.

Referenced by validateSubTree().

+ Here is the caller graph for this function:

◆ validateSubTree()

ilAssLacCompositeValidator::validateSubTree ( ilAssLacAbstractComposite  $composite)
private

Definition at line 51 of file ilAssLacCompositeValidator.php.

52 {
53 if ($composite->nodes[0] instanceof ilAssLacQuestionExpressionInterface &&
54 $composite->nodes[1] instanceof ilAssLacSolutionExpressionInterface
55 ) {
56 $question_expression = $composite->nodes[0];
57 $answer_expression = $composite->nodes[1];
58 $question_index = $composite->nodes[0]->getQuestionIndex();
59 $answer_index = null;
60 $question = $this->object_loader->getQuestion($question_index);
61
62 $this->checkQuestionExists($question, $question_index);
63 //$this->checkQuestionIsReachable($question, $question_index);
64
65 if ($this->isResultOfAnswerExpression($question_expression)) {
66 $answer_index = $question_expression->getAnswerIndex() - 1;
67 $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index);
68 }
69 if ($answer_expression instanceof ilAssLacNumberOfResultExpression && !($question instanceof assClozeTest)) {
70 $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue() - 1);
71 }
72
73 $this->checkAnswerExpressionExist($question->getExpressionTypes(), $answer_expression, $question_index);
74 $this->checkOperatorExistForExpression($question->getOperators($answer_expression::$identifier), $answer_expression, $composite::$pattern);
75
76 if ($answer_expression instanceof ilAssLacOrderingResultExpression &&
77 ($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion)
78 ) {
79 foreach ($answer_expression->getOrdering() as $order) {
80 $count = 0;
81 foreach ($answer_expression->getOrdering() as $element) {
82 if ($element == $order) {
83 $count++;
84 }
85 }
86 if ($count > 1) {
87 throw new ilAssLacDuplicateElement($order);
88 }
89
90 $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order - 1);
91 }
92 }
93 if ($question instanceof assClozeTest) {
94 $this->validateClozeTest($answer_index, $question, $answer_expression, $question_index);
95 } elseif (
96 $answer_expression instanceof ilAssLacPercentageResultExpression &&
97 $this->isResultOfAnswerExpression($question_expression) &&
98 !($question instanceof assFormulaQuestion)
99 ) {
100 throw new ilAssLacExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[" . ($answer_index + 1) . "]");
101 }
102 } elseif (
103 ($composite->nodes[0] instanceof ilAssLacAbstractOperation &&
104 $composite->nodes[1] instanceof ilAssLacExpressionInterface) ||
105 ($composite->nodes[0] instanceof ilAssLacExpressionInterface &&
106 $composite->nodes[1] instanceof ilAssLacAbstractOperation) ||
107 ($composite->nodes[0] instanceof ilAssLacSolutionExpressionInterface)
108 ) {
109 throw new ilAssLacUnableToParseCondition("");
110 }
111 }
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: