ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAssLacCompositeBuilder.php
Go to the documentation of this file.
1 <?php
2 
27 {
34  protected $operators = array('<=','<','=','>=','>','<>','&','|');
35 
39  public function __construct()
40  {
41  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacOperationManufacturer.php';
42  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacExpressionManufacturer.php';
43  }
44 
62  public function create(array $nodes): ilAssLacAbstractComposite
63  {
64  if ($nodes['type'] == 'group') {
65  foreach ($nodes['nodes'] as $key => $child) {
66  if ($child['type'] == 'group') {
67  $nodes['nodes'][$key] = $this->create($child);
68  }
69  }
70 
71  foreach ($this->operators as $next_operator) {
72  do {
73  $index = -1;
74  for ($i = 0; $i < count($nodes['nodes']); $i++) {
75  if (!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) {
76  $index = $i;
77  break;
78  }
79  }
80  if ($index >= 0) {
81  $operation_manufacture = ilAssLacOperationManufacturer::_getInstance();
82  $operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']);
83 
84  $operator->setNegated($nodes["negated"]);
85  $operator->addNode($this->getExpression($nodes, $index - 1));
86  $operator->addNode($this->getExpression($nodes, $index + 1));
87 
88  $new_nodes = array_slice($nodes['nodes'], 0, $index - 1);
89  $new_nodes[] = $operator;
90  $nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2));
91  }
92  } while ($index >= 0);
93  }
94  return $nodes['nodes'][0];
95  }
97  'need node structure with type group as input');
98  }
99 
109  private function getExpression(array $node, $index)
110  {
112 
113  $expression = $node['nodes'][$index];
114  if (!($expression instanceof ilAssLacAbstractComposite)) {
115  $expression = $manufacturer->manufacture($node['nodes'][$index]['value']);
116  }
117  return $expression;
118  }
119 }
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...
__construct()
Construct requirements.
$index
Definition: metadata.php:145
create(array $nodes)
Creates a composite tree structure from a nodes tree.
static _getInstance()
Get an Instance of ExpressionManufacturer.
string $key
Consumer key/client ID value.
Definition: System.php:193
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.
$i
Definition: metadata.php:41