ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAssLacCompositeBuilder.php
Go to the documentation of this file.
1 <?php
2 
11 
18  protected $operators = array('<=','<','=','>=','>','<>','&','|');
19 
23  public function __construct()
24  {
25  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacOperationManufacturer.php';
26  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacExpressionManufacturer.php';
27  }
28 
34  public function create($nodes)
35  {
36  if($nodes['type'] == 'group')
37  {
38  foreach($nodes['nodes'] as $key => $child)
39  {
40  $nodes['nodes'][$key] = $this->create($child);
41  }
42 
43  foreach($this->operators as $next_operator)
44  {
45  do{
46  $index = -1;
47  for($i = 0; $i < count($nodes['nodes']); $i++)
48  {
49  if(!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator)
50  {
51  $index = $i;
52  break;
53  }
54  }
55  if($index >= 0)
56  {
57  $operation_manufacture = ilAssLacOperationManufacturer::_getInstance();
58  $operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']);
59 
60  $operator->setNegated($nodes["negated"]);
61  $operator->addNode($this->getExpression($nodes, $index-1));
62  $operator->addNode($this->getExpression($nodes, $index+1));
63 
64  $new_nodes = array_slice($nodes['nodes'], 0, $index - 1);
65  $new_nodes[] = $operator;
66  $nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2));
67  }
68  }while($index >= 0);
69  }
70  return $nodes['nodes'][0];
71  }
72  return $nodes;
73  }
74 
84  private function getExpression(array $node, $index)
85  {
87 
88  $expression = $node['nodes'][$index];
89  if(!($expression instanceof ilAssLacAbstractComposite))
90  {
91  $expression = $manufacturer->manufacture($node['nodes'][$index]['value']);
92  }
93  return $expression;
94  }
95 }
__construct()
Construct requirements.
static _getInstance()
Get an Instance of ExpressionManufacturer.
Create styles array
The data for the language used.
static _getInstance()
Get an Instance of OperationManufacturer.
getExpression(array $node, $index)
Manufacure an expression from the delivered node and the index.