ILIAS  trunk Revision v5.2.0beta1-34115-g3a2438be29
ilAssLacCompositeValidator Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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)
 

Private Attributes

RandomGroup $randomGroup
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 28 of file ilAssLacCompositeValidator.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 42 of file ilAssLacCompositeValidator.php.

References $DIC, and $object_loader.

43  {
44  global $DIC;
45 
46  $this->object_loader = $object_loader;
47  $this->randomGroup = $DIC->refinery()->random();
48  }
$DIC
Definition: xapitoken.php:62

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

Referenced by validateSubTree().

238  : void
239  {
240  if (!in_array($answer_expression::$identifier, $expressions)) {
241  throw new ilAssLacExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index);
242  }
243  }
+ 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 190 of file ilAssLacCompositeValidator.php.

Referenced by validateSubTree().

190  : void
191  {
192  $answer_options = $question->getAvailableAnswerOptions($answer_index);
193  if ($answer_options == null) {
194  throw new ilAssLacAnswerIndexNotExist($question_index, $answer_index + 1);
195  }
196  }
+ 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 252 of file ilAssLacCompositeValidator.php.

Referenced by validateSubTree().

252  : void
253  {
254  if (!in_array($pattern, $operators)) {
255  throw new ilAssLacOperatorNotSupportedByExpression($answer_expression->getValue(), $pattern);
256  }
257  }
+ 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 204 of file ilAssLacCompositeValidator.php.

Referenced by validateSubTree().

204  : void
205  {
206  if ($question == null) {
207  throw new ilAssLacQuestionNotExist($index);
208  }
209  }
+ Here is the caller graph for this function:

◆ getNonShuffler()

ilAssLacCompositeValidator::getNonShuffler ( )
protected

Definition at line 259 of file ilAssLacCompositeValidator.php.

260  {
261  return $this->randomGroup->dontShuffle();
262  }
A transformation is a function from one datatype to another.

◆ isResultOfAnswerExpression()

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

Definition at line 216 of file ilAssLacCompositeValidator.php.

Referenced by validateSubTree().

216  : bool
217  {
218  // @PHP8-CR I suspect this cluster of typizations is broken in some way. I still leave these remarks "intact"
219  // to assist a more thorough analysis.
220  if ($expression instanceof ilAssLacResultOfAnswerOfQuestionExpression) {
221  return true;
222  }
223 
224  if ($expression instanceof ilAssLacResultOfAnswerOfCurrentQuestionExpression) {
225  return true;
226  }
227 
228  return false;
229  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ validate()

ilAssLacCompositeValidator::validate ( ilAssLacAbstractComposite  $composite)

Definition at line 50 of file ilAssLacCompositeValidator.php.

References validateSubTree().

50  : void
51  {
52  if (count($composite->nodes) > 0) {
53  $this->validate($composite->nodes[0]);
54  $this->validate($composite->nodes[1]);
55  $this->validateSubTree($composite);
56  }
57 
58  return;
59  }
validate(ilAssLacAbstractComposite $composite)
validateSubTree(ilAssLacAbstractComposite $composite)
+ Here is the call 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 137 of file ilAssLacCompositeValidator.php.

Referenced by validateSubTree().

137  : void
138  {
139  if ($answer_index !== null) {
140  $options = $question->getAvailableAnswerOptions($answer_index);
141  $found = false;
142  switch ($options->getType()) {
143  case 0: // text
144  if (
145  $answer_expression instanceof ilAssLacStringResultExpression
146  ) {
147  $found = true;
148  }
149 
150  break;
151  case 1: // select
152 
153  if ($answer_expression instanceof ilAssLacStringResultExpression) {
154  foreach ($options->getItems($this->getNonShuffler()) as $item) {
155  if ($item->getAnswertext() == $answer_expression->getText()) {
156  $found = true;
157  }
158  }
159  } elseif ($answer_expression instanceof ilAssLacNumberOfResultExpression) {
160  foreach ($options->getItems($question->getShuffler()) as $item) {
161  if ($item->getOrder() == $answer_expression->getNumericValue() - 1) {
162  $found = true;
163  }
164  }
165  }
166  break;
167  case 2: // numeric
168  if ($answer_expression instanceof ilAssLacNumericResultExpression) {
169  $found = true;
170  }
171  break;
172  }
173 
174  if ($answer_expression instanceof ilAssLacEmptyAnswerExpression) {
175  $found = true;
176  }
177  if (!$found && !($answer_expression instanceof ilAssLacPercentageResultExpression)) {
178  throw new ilAssLacAnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index + 1);
179  }
180  }
181  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the caller graph for this function:

◆ validateSubTree()

ilAssLacCompositeValidator::validateSubTree ( ilAssLacAbstractComposite  $composite)
private

Definition at line 61 of file ilAssLacCompositeValidator.php.

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

Referenced by validate().

61  : void
62  {
63  if ($composite->nodes[0] instanceof ilAssLacQuestionExpressionInterface &&
64  $composite->nodes[1] instanceof ilAssLacSolutionExpressionInterface
65  ) {
66  $question_expression = $composite->nodes[0];
67  $answer_expression = $composite->nodes[1];
68  $question_index = $composite->nodes[0]->getQuestionIndex();
69  $answer_index = null;
70  $question = $this->object_loader->getQuestion($question_index);
71 
72  $this->checkQuestionExists($question, $question_index);
73  //$this->checkQuestionIsReachable($question, $question_index);
74 
75  if ($this->isResultOfAnswerExpression($question_expression)) {
76  $answer_index = $question_expression->getAnswerIndex() - 1;
77  // @PHP8-CR I suspect this cluster of typizations is broken in some way. I still leave these remarks "intact"
78  // to assist a more thorough analysis.
79  $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index);
80  }
81  if ($answer_expression instanceof ilAssLacNumberOfResultExpression && !($question instanceof assClozeTest)) {
82  // @PHP8-CR I suspect this cluster of typizations is broken in some way. I still leave these remarks "intact"
83  // to assist a more thorough analysis.
84  $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue() - 1);
85  }
86 
87  $this->checkAnswerExpressionExist($question->getExpressionTypes(), $answer_expression, $question_index);
88  $this->checkOperatorExistForExpression($question->getOperators($answer_expression::$identifier), $answer_expression, $composite::$pattern);
89 
90  if ($answer_expression instanceof ilAssLacOrderingResultExpression &&
91  ($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion)
92  ) {
93  foreach ($answer_expression->getOrdering() as $order) {
94  $count = 0;
95  foreach ($answer_expression->getOrdering() as $element) {
96  if ($element == $order) {
97  $count++;
98  }
99  }
100  if ($count > 1) {
101  throw new ilAssLacDuplicateElement($order);
102  }
103 
104  $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order - 1);
105  }
106  }
107  if ($question instanceof assClozeTest) {
108  $this->validateClozeTest($answer_index, $question, $answer_expression, $question_index);
109  } elseif (
110  $answer_expression instanceof ilAssLacPercentageResultExpression &&
111  // @PHP8-CR I suspect this cluster of typizations is broken in some way. I still leave these remarks "intact"
112  // to assist a more thorough analysis.
113  $this->isResultOfAnswerExpression($question_expression) &&
114  !($question instanceof assFormulaQuestion)
115  ) {
116  throw new ilAssLacExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[" . ($answer_index + 1) . "]");
117  }
118  } elseif (
119  ($composite->nodes[0] instanceof ilAssLacAbstractOperation &&
120  $composite->nodes[1] instanceof ilAssLacExpressionInterface) ||
121  ($composite->nodes[0] instanceof ilAssLacExpressionInterface &&
122  $composite->nodes[1] instanceof ilAssLacAbstractOperation) ||
123  ($composite->nodes[0] instanceof ilAssLacSolutionExpressionInterface)
124  ) {
125  throw new ilAssLacUnableToParseCondition("");
126  }
127  }
checkOperatorExistForExpression($operators, $answer_expression, $pattern)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
validateClozeTest($answer_index, $question, $answer_expression, $question_index)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkAnswerExpressionExist($expressions, $answer_expression, $question_index)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ 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 35 of file ilAssLacCompositeValidator.php.

Referenced by __construct().

◆ $randomGroup

RandomGroup ilAssLacCompositeValidator::$randomGroup
private

Definition at line 37 of file ilAssLacCompositeValidator.php.


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