ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilAssLacCompositeBuilder.php
Go to the documentation of this file.
1 <?php
2 
27 {
34  protected $operators = ['<=','<','=','>=','>','<>','&','|'];
35 
53  public function create(array $nodes): ilAssLacAbstractComposite
54  {
55  if ($nodes['type'] == 'group') {
56  foreach ($nodes['nodes'] as $key => $child) {
57  if ($child['type'] == 'group') {
58  $nodes['nodes'][$key] = $this->create($child);
59  }
60  }
61 
62  foreach ($this->operators as $next_operator) {
63  do {
64  $index = -1;
65  for ($i = 0; $i < count($nodes['nodes']); $i++) {
66  if (!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) {
67  $index = $i;
68  break;
69  }
70  }
71  if ($index >= 0) {
72  $operation_manufacture = ilAssLacOperationManufacturer::_getInstance();
73  $operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']);
74 
75  $operator->setNegated($nodes["negated"]);
76  $operator->addNode($this->getExpression($nodes, $index - 1));
77  $operator->addNode($this->getExpression($nodes, $index + 1));
78 
79  $new_nodes = array_slice($nodes['nodes'], 0, $index - 1);
80  $new_nodes[] = $operator;
81  $nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2));
82  }
83  } while ($index >= 0);
84  }
85  return $nodes['nodes'][0];
86  }
88  'need node structure with type group as input'
89  );
90  }
91 
101  private function getExpression(array $node, $index)
102  {
104 
105  $expression = $node['nodes'][$index];
106  if (!($expression instanceof ilAssLacAbstractComposite)) {
107  $expression = $manufacturer->manufacture($node['nodes'][$index]['value']);
108  }
109  return $expression;
110  }
111 }
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...
create(array $nodes)
Creates a composite tree structure from a nodes tree.
static _getInstance()
Get an Instance of ExpressionManufacturer.
static _getInstance()
Get an Instance of OperationManufacturer.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getExpression(array $node, $index)
Manufacure an expression from the delivered node and the index.