ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAssLacConditionParser Class Reference
+ Collaboration diagram for ilAssLacConditionParser:

Public Member Functions

 parse ($condition)
 Parses the delivered condition and creates a composite tree Structure. More...
 
 getExpressions ()
 

Protected Member Functions

 fetchExpressions ()
 Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions. More...
 
 fetchOperators ()
 Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators. More...
 
 cannonicalizeCondition ()
 Cannonicalize the condition into a more general form. More...
 
 checkBrackets ()
 
 createNodeArray ()
 Creates an array representing all Nodes in a condition based on the fetched expressions and operators. More...
 
 surroundNegationExpression ($index)
 
 isNegationSurroundedByBrackets ($index)
 

Protected Attributes

 $condition
 
 $expressions
 
 $operators
 
 $index
 
 $spaces
 

Detailed Description

Definition at line 27 of file ilAssLacConditionParser.php.

Member Function Documentation

◆ cannonicalizeCondition()

ilAssLacConditionParser::cannonicalizeCondition ( )
protected

Cannonicalize the condition into a more general form.


It replaces all expression with "n" and all orperators with "o"
so that the result of an condition after cannonicalization could be:

(n o n) o (n o n) o n

Definition at line 120 of file ilAssLacConditionParser.php.

120 : void
121 {
123 $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition);
125 $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition);
126 $this->condition = preg_replace("/no/", "n o", $this->condition);
127 $this->condition = preg_replace("/on/", "o n", $this->condition);
128
129 for ($i = 0; $i < strlen($this->condition); $i++) {
130 if ($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) {
132 }
133 }
134 }
static _getInstance()
Get an Instance of ExpressionManufacturer.
static _getInstance()
Get an Instance of OperationManufacturer.

References ilAssLacExpressionManufacturer\_getInstance(), ilAssLacOperationManufacturer\_getInstance(), isNegationSurroundedByBrackets(), and surroundNegationExpression().

Referenced by parse().

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

◆ checkBrackets()

ilAssLacConditionParser::checkBrackets ( )
protected

Definition at line 136 of file ilAssLacConditionParser.php.

136 : void
137 {
138 $num_brackets_open = substr_count($this->condition, "(");
139 $num_brackets_close = substr_count($this->condition, ")");
140
141 if ($num_brackets_open > $num_brackets_close) {
142 throw new ilAssLacMissingBracket(")");
143 }
144 if ($num_brackets_open < $num_brackets_close) {
145 throw new ilAssLacMissingBracket("(");
146 }
147 }

Referenced by parse().

+ Here is the caller graph for this function:

◆ createNodeArray()

ilAssLacConditionParser::createNodeArray ( )
protected

Creates an array representing all Nodes in a condition based on the fetched expressions and operators.


The array has a tree representation which depth is dependent to the bracketing in the condition
The array contains of four main keys to identify the elements:

KeyValuesDescription
type"group", "expression", "operator"The type of the node - Group is used to introduce the next tree depth
valuemixedContains an extracted expression or operation from a condition
nodesarrayContains an node array
Returns
array

Definition at line 171 of file ilAssLacConditionParser.php.

171 : array
172 {
173 $expected = ["n", "(", "!"];
174 $group = [];
175 $negation = false;
176
177 while ($this->index < strlen($this->condition)) {
178 $a = $this->condition[$this->index];
179 if (trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) {
180 if ($this->condition[$this->index] == ')') {
181 return $group;
182 } elseif ($this->condition[$this->index] == 'n') {
183 $group[] = ['type' => 'expression', 'value' => array_shift($this->expressions)];
184 $expected = ["o", ")"];
185 } elseif ($this->condition[$this->index] == 'o') {
186 $group[] = ['type' => 'operator', 'value' => array_shift($this->operators)];
187 $expected = ["n", "(", "!"];
188 } elseif ($this->condition[$this->index] == '(') {
189 $this->index++;
190 $elements = $this->createNodeArray();
191 $group[] = ['type' => "group", "negated" => $negation, 'nodes' => $elements];
192 $negation = false;
193 $expected = ["o",")"];
194 } elseif ($this->condition[$this->index] == "!") {
195 $negation = true;
196 }
197 } elseif (trim($this->condition[$this->index]) != "") {
198 throw new ilAssLacConditionParserException($this->index - $this->spaces + 1);
199 } else {
200 $this->spaces++;
201 }
202
203 $this->index++;
204 }
205 return ['type' => 'group', "negated" => $negation, 'nodes' => $group];
206 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createNodeArray()
Creates an array representing all Nodes in a condition based on the fetched expressions and operators...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, $index, and createNodeArray().

Referenced by createNodeArray(), and parse().

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

◆ fetchExpressions()

ilAssLacConditionParser::fetchExpressions ( )
protected

Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions.

See also
AbstractManufacturer::match()
ExpressionManufacturer::getPattern()
Parser::$expressions

Definition at line 94 of file ilAssLacConditionParser.php.

94 : void
95 {
97 $this->expressions = $manufacturer->match($this->condition);
98 }

References ilAssLacExpressionManufacturer\_getInstance().

Referenced by parse().

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

◆ fetchOperators()

ilAssLacConditionParser::fetchOperators ( )
protected

Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators.

See also
AbstractManufacturer::match()
OperationManufacturer::getPattern()
Parser::$operators

Definition at line 107 of file ilAssLacConditionParser.php.

107 : void
108 {
110 $this->operators = $manufacturer->match($this->condition);
111 }

References ilAssLacOperationManufacturer\_getInstance().

Referenced by parse().

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

◆ getExpressions()

ilAssLacConditionParser::getExpressions ( )
Returns
array

Definition at line 211 of file ilAssLacConditionParser.php.

211 : array
212 {
213 return $this->expressions;
214 }

References $expressions.

◆ isNegationSurroundedByBrackets()

ilAssLacConditionParser::isNegationSurroundedByBrackets (   $index)
protected
Parameters
int$index
Returns
boolean

Definition at line 238 of file ilAssLacConditionParser.php.

239 {
240 $next_bracket = strpos($this->condition, "(", $index + 1);
241 $next_expression = strpos($this->condition, "n", $index + 1);
242
243 return $next_bracket !== false && $next_bracket < $next_expression;
244 }

References $index.

Referenced by cannonicalizeCondition().

+ Here is the caller graph for this function:

◆ parse()

ilAssLacConditionParser::parse (   $condition)

Parses the delivered condition and creates a composite tree Structure.

Parameters
$condition
See also
CompositeBuilder::create()
Returns
ilAssLacAbstractComposite

Definition at line 74 of file ilAssLacConditionParser.php.

75 {
76 $this->condition = $condition;
77 $this->index = 0;
78 $this->checkBrackets();
79 $this->fetchExpressions();
80 $this->fetchOperators();
82 $nodes = $this->createNodeArray();
83 $compositeBuilder = new ilAssLacCompositeBuilder();
84 return $compositeBuilder->create($nodes);
85 }
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...
cannonicalizeCondition()
Cannonicalize the condition into a more general form.
fetchExpressions()
Matches all expressions in the current condition and assign these to the class attribute ConditionPar...
fetchOperators()
Matches all operators in the current condition and assign these to the class attribute ConditionParse...

References $condition, cannonicalizeCondition(), checkBrackets(), createNodeArray(), fetchExpressions(), and fetchOperators().

+ Here is the call graph for this function:

◆ surroundNegationExpression()

ilAssLacConditionParser::surroundNegationExpression (   $index)
protected
Parameters
int$index

Definition at line 219 of file ilAssLacConditionParser.php.

219 : void
220 {
221 $start = strpos($this->condition, "n", $index + 1);
222 $end = false;
223
224 if ($start !== false) {
225 $end = strpos($this->condition, "n", $start + 1);
226 }
227
228 if ($start !== false && $end !== false) {
229 $this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1);
230 }
231 }

References $index.

Referenced by cannonicalizeCondition().

+ Here is the caller graph for this function:

Field Documentation

◆ $condition

ilAssLacConditionParser::$condition
protected

Definition at line 34 of file ilAssLacConditionParser.php.

Referenced by parse().

◆ $expressions

ilAssLacConditionParser::$expressions
protected

Definition at line 42 of file ilAssLacConditionParser.php.

Referenced by getExpressions().

◆ $index

ilAssLacConditionParser::$index
protected

◆ $operators

ilAssLacConditionParser::$operators
protected

Definition at line 50 of file ilAssLacConditionParser.php.

◆ $spaces

ilAssLacConditionParser::$spaces
protected

Definition at line 64 of file ilAssLacConditionParser.php.


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