ILIAS  release_8 Revision v8.23
LSTOCBuilder.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
26 class LSTOCBuilder implements TOCBuilder
27 {
31  protected array $structure;
32 
36  protected $parent;
37 
38  protected ?string $command;
39 
43  public function __construct($parent, string $command, string $label = '', int $parameter = null, $state = null)
44  {
45  $this->structure = [
46  'label' => $label,
47  'command' => $command,
48  'parameter' => $parameter,
49  'state' => $state,
50  'childs' => []
51  ];
52  $this->parent = $parent;
53  $this->command = $command;
54  }
55 
56  public function toJSON(): string
57  {
58  return json_encode($this->structure);
59  }
60 
64  public function end()
65  {
66  $this->parent->structure['childs'][] = $this->structure;
67  return $this->parent;
68  }
69 
73  public function node(string $label, int $parameter = null, int $lp = null): TOCBuilder
74  {
75  //build node
76  $toc = new LSTOCBuilder($this, $this->command, $label, $parameter, $lp);
77  return $toc;
78  }
79 
83  public function item(string $label, int $parameter, $state = null, bool $current = false): TOCBuilder
84  {
85  $item = [
86  'label' => $label,
87  'command' => $this->command,
88  'parameter' => $parameter,
89  'state' => $state,
90  'current' => $current
91  ];
92  $this->structure['childs'][] = $item;
93  return $this;
94  }
95 }
end()
Finish building the TOC.ControlBuilder|TOCBuilder depending on the nesting level. ...
Build a nested table of contents for the view.
Definition: TOCBuilder.php:14
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct($parent, string $command, string $label='', int $parameter=null, $state=null)
LSControlBuilder|LSTOCBuilder $parent.
Class LSTOCBuilder.
string $command
array $structure
node(string $label, int $parameter=null, int $lp=null)
Build a sub tree in the TOC.If a parameter is provided, the node in the TOC can be accessed itself...
item(string $label, int $parameter, $state=null, bool $current=false)
Build an entry in the TOC.The parameter will be appended to the command when updating the state...