ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LSTOCBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26class 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 if ($this->parent instanceof LSTOCBuilder) {
67 $this->parent->structure['childs'][] = $this->structure;
68 }
69 return $this->parent;
70 }
71
75 public function node(string $label, ?int $parameter = null, ?int $lp = null): TOCBuilder
76 {
77 //build node
78 $toc = new LSTOCBuilder($this, $this->command, $label, $parameter, $lp);
79 return $toc;
80 }
81
85 public function item(string $label, int $parameter, $state = null, bool $current = false): TOCBuilder
86 {
87 $item = [
88 'label' => $label,
89 'command' => $this->command,
90 'parameter' => $parameter,
91 'state' => $state,
92 'current' => $current
93 ];
94 $this->structure['childs'][] = $item;
95 return $this;
96 }
97}
Class LSTOCBuilder.
end()
Finish building the TOC.ControlBuilder|TOCBuilder depending on the nesting level.
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....
string $command
__construct($parent, string $command, string $label='', ?int $parameter=null, $state=null)
LSControlBuilder|LSTOCBuilder $parent.
array $structure
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....
Build a nested table of contents for the view.
Definition: TOCBuilder.php:29