/**
  * Get an Instance of OperationManufacturer
  *
  * @return ilAssLacOperationManufacturer
  */
 public static function _getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new ilAssLacOperationManufacturer();
     }
     return self::$instance;
 }
Пример #2
0
 /**
  * @param array $nodes
  *
  * @return array
  */
 public function create($nodes)
 {
     if ($nodes['type'] == 'group') {
         foreach ($nodes['nodes'] as $key => $child) {
             $nodes['nodes'][$key] = $this->create($child);
         }
         foreach ($this->operators as $next_operator) {
             do {
                 $index = -1;
                 for ($i = 0; $i < count($nodes['nodes']); $i++) {
                     if (!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) {
                         $index = $i;
                         break;
                     }
                 }
                 if ($index >= 0) {
                     $operation_manufacture = ilAssLacOperationManufacturer::_getInstance();
                     $operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']);
                     $operator->setNegated($nodes["negated"]);
                     $operator->addNode($this->getExpression($nodes, $index - 1));
                     $operator->addNode($this->getExpression($nodes, $index + 1));
                     $new_nodes = array_slice($nodes['nodes'], 0, $index - 1);
                     $new_nodes[] = $operator;
                     $nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2));
                 }
             } while ($index >= 0);
         }
         return $nodes['nodes'][0];
     }
     return $nodes;
 }
Пример #3
0
 /**
  * Cannonicalize the condition into a more general form. <br />
  * It replaces all expression with "n" and all orperators with "o" <br />
  * so that the result of an condition after cannonicalization could be:<br />
  * <br />
  * (n o n) o (n o n) o n
  */
 protected function cannonicalizeCondition()
 {
     $manufacturer = ilAssLacExpressionManufacturer::_getInstance();
     $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition);
     $manufacturer = ilAssLacOperationManufacturer::_getInstance();
     $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition);
     $this->condition = preg_replace("/no/", "n o", $this->condition);
     $this->condition = preg_replace("/on/", "o n", $this->condition);
     for ($i = 0; $i < strlen($this->condition); $i++) {
         if ($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) {
             $this->surroundNegationExpression($i);
         }
     }
 }