1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<?php
/**
* Class ContentBar
* ContentBar for page, with optional ActionMenu, Table of contents and breadcrumbs.
*
* @author Thomas Hackl <hackl@data-quest.de>
* @license GPL2 or any later version
* @since Stud.IP 5.0
*/
class ContentBar
{
public $infoText = '';
public $iconShape = '';
public $toc = null;
/**
* ContentBar constructor.
*
* Note: An icon for consumer mode is always shown, this would have to be changed via template.
*
* @param TOCItem $toc Table of contents object.
* @param string $info Some information to show, like creation date, author etc.
* @param Icon|null $icon An icon to show in content bar.
* @param ActionMenu|null $actionMenu Optional action menu for page actions.
*/
public function __construct(TOCItem $toc, string $info = '', Icon $icon = null, ActionMenu $actionMenu = null)
{
$this->infoText = $info;
$this->icon = $icon;
$this->toc = $toc;
$this->actionMenu = $actionMenu;
}
public $actionMenu = null;
/**
* Provide some info text.
* @param string $info
* @return ContentBar $this Return current instance for method chaining.
*/
public function setInfo(string $info)
{
$this->infoText = $info;
return $this;
}
/**
* Set an icon.
* @param Icon $icon
* @return ContentBar $this Return current instance for method chaining.
*/
public function setIcon(Icon $icon)
{
$this->icon = $icon;
return $this;
}
/**
* Set a table of contents object.
* @param TOCItem $toc
* @return ContentBar $this Return current instance for method chaining.
*/
public function setTOC(TOCItem $toc)
{
$this->toc = $toc;
return $this;
}
/**
* Provide an action menu.
* @param ActionMenu $actionMenu
* @return ContentBar $this Return current instance for method chaining.
*/
public function setActionMenu(ActionMenu $actionMenu)
{
$this->actionMenu = $actionMenu;
return $this;
}
/**
* Render the content bar from corresponding template
* @return string
*/
public function render()
{
$template = $GLOBALS['template_factory']->open('contentbar/contentbar');
$template->actionMenu = $this->actionMenu;
$template->info = $this->infoText;
// Table of contents
$tocTemplate = $GLOBALS['template_factory']->open('toc/generic-toc-list');
$tocTemplate->set_attribute('root', $this->toc);
$template->toc = $this->toc;
$template->ttpl = $tocTemplate;
// Breadcrumbs
$brdcrmb = $GLOBALS['template_factory']->open('toc/generic-toc-breadcrumb');
$brdcrmb->set_attribute('item', $this->toc->getActiveItem() ?: $this->toc);
$template->breadcrumbs = $brdcrmb;
$template->icon = $this->icon;
return $template->render();
}
/**
* Magic method: when ContentBar is used as a string, this will just call
* the render method, returning a string representation of this object.
* @return string
*/
public function __toString()
{
return $this->render();
}
}
|