ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ToolbarNavigationRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Blog\Navigation;
22
26
28{
29 protected array $items;
31 protected int $portfolio_page;
32 protected int $blog_page;
33 protected \ILIAS\Blog\Presentation\Util $util;
34 protected $current_month;
35 protected \ilCtrl $ctrl;
38
39 public function __construct(
42 ) {
43 $this->domain = $domain;
44 $this->gui = $gui;
45 $this->util = $gui->presentation()->util();
46 }
47
48 public function renderToolbarNavigation(
49 PermissionManager $blog_acces,
50 array $a_items,
51 int $blog_page,
52 bool $single_posting,
53 $month,
55 ): void {
56
57 $this->blog_access = $blog_acces;
58 $this->ctrl = $ctrl = $this->gui->ctrl();
59 $this->items = $a_items;
60 $this->current_month = $month;
61 $this->blog_page = $blog_page;
62 $this->portfolio_page = $portfolio_page;
63
64 $cmd = "previewFullscreen";
65
66 if ($single_posting) { // single posting view
67 $next_posting = $this->getNextPosting($blog_page);
68 if ($next_posting > 0) {
69 $this->renderPreviousButton($this->getPostingTarget($next_posting, $cmd));
70 } else {
71 $this->renderPreviousButton("");
72 }
73
74 $this->renderPostingDropdown($cmd);
75
76 $prev_posting = $this->getPreviousPosting($blog_page);
77 if ($prev_posting > 0) {
78 $this->renderNextButton($this->getPostingTarget($prev_posting, $cmd));
79 } else {
80 $this->renderNextButton("");
81 }
82
83
84 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "blpg", $blog_page);
85
86 $this->renderActionDropdown(true);
87
88 } else { // month view
89 $next_month = $this->getNextMonth($month);
90 if ($next_month !== "") {
91 $this->renderPreviousButton($this->getMonthTarget($next_month));
92 } else {
93 $this->renderPreviousButton("");
94 }
95
96 $this->renderMonthDropdown();
97
98 $prev_month = $this->getPreviousMonth($month);
99 if ($prev_month !== "") {
100 $this->renderNextButton($this->getMonthTarget($prev_month));
101 } else {
102 $this->renderNextButton("");
103 }
104
105 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "bmn", $month);
106
107 $this->renderActionDropdown(false);
108 }
109 }
110
111 protected function renderActionDropdown(bool $single_posting): void
112 {
113 $lng = $this->domain->lng();
114 $toolbar = $this->gui->toolbar();
115 $f = $this->gui->ui()->factory();
116 $ctrl = $this->ctrl;
117 $actions = [];
118 if ($this->blog_access->mayContribute()) {
119 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "prvm", "");
120
121 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "bmn", "");
122 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "blpg", "");
123 $link = $ctrl->getLinkTargetByClass(\ilObjBlogGUI::class, "");
124 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "blpg", $this->blog_page);
125 $ctrl->setParameterByClass(\ilObjBlogGUI::class, "bmn", $this->current_month);
126 $actions[] = $f->button()->shy(
127 $lng->txt("blog_edit"),
128 $link
129 );
130 }
131
132 if ($single_posting && $this->blog_access->mayContribute() && $this->blog_access->mayEditPosting($this->blog_page)) {
133 $ctrl->setParameterByClass(\ilBlogPostingGUI::class, "blpg", $this->blog_page);
134 $link = $ctrl->getLinkTargetByClass(\ilBlogPostingGUI::class, "edit");
135 $actions[] = $f->button()->shy(
136 $lng->txt("blog_edit_posting"),
137 $link
138 );
139 }
140 if (count($actions) > 0) {
141 $toolbar->addStickyItem($f->dropdown()->standard($actions));
142 }
143 }
144
145 protected function getLatestPosting(): int
146 {
147 reset($this->items);
148 $month = current($this->items);
149 if (is_array($month)) {
150 return (int) current($month)["id"];
151 }
152 return 0;
153 }
154
155 public function getNextPosting(
156 int $blog_page
157 ): int {
158 reset($this->items);
159 $found = "";
160 $next_blpg = 0;
161 foreach ($this->items as $month => $items) {
162 foreach ($items as $item) {
163 if (!$this->blog_access->isActive((int) $item["id"])) {
164 continue;
165 }
166 if ($item["id"] == $blog_page) {
167 $found = true;
168 }
169 if (!$found) {
170 $next_blpg = (int) $item["id"];
171 }
172 }
173 }
174 return $next_blpg;
175 }
176
177 protected function getPreviousPosting(
178 int $blog_page
179 ): int {
180 reset($this->items);
181 $found = "";
182 $prev_blpg = 0;
183 foreach ($this->items as $month => $items) {
184 foreach ($items as $item) {
185 if (!$this->blog_access->isActive((int) $item["id"])) {
186 continue;
187 }
188 if ($found && $prev_blpg === 0) {
189 $prev_blpg = (int) $item["id"];
190 }
191 if ((int) $item["id"] === $blog_page) {
192 $found = true;
193 }
194 }
195 }
196 return $prev_blpg;
197 }
198
199 protected function getPostingTarget(int $posting, string $cmd): string
200 {
201 $this->ctrl->setParameterByClass(\ilBlogPostingGUI::class, "blpg", (string) $posting);
202 return $this->ctrl->getLinkTargetByClass(\ilBlogPostingGUI::class, $cmd);
203 }
204
205 protected function getMonthTarget(string $month): string
206 {
207 $this->ctrl->setParameterByClass(\ilObjBlogGUI::class, "bmn", $month);
208 return $this->ctrl->getLinkTargetByClass(\ilObjBlogGUI::class, "preview");
209 }
210
211 protected function renderMonthDropdown(): void
212 {
213 $toolbar = $this->gui->toolbar();
214 $f = $this->gui->ui()->factory();
215 $m = [];
216 foreach ($this->items as $month => $items) {
217 $label = $this->util->getMonthPresentation($month);
218 if ($month === $this->current_month) {
219 $label = "» " . $label;
220 }
221 $m[] = $f->link()->standard(
222 $label,
223 $this->getMonthTarget($month)
224 );
225 }
226 if (count($m) > 0) {
227 $toolbar->addStickyItem($f->dropdown()->standard($m)->withLabel(
228 $this->getDropdownLabel($this->util->getMonthPresentation($this->current_month))
229 ));
230 }
231 }
232
233 protected function getNextMonth(
234 $current_month
235 ): string {
236 reset($this->items);
237 $found = "";
238 foreach ($this->items as $month => $items) {
239 if ($month > $current_month) {
240 $found = $month;
241 }
242 }
243 return $found;
244 }
245
246 protected function getPreviousMonth(
247 $current_month
248 ): string {
249 reset($this->items);
250 $found = "";
251 foreach ($this->items as $month => $items) {
252 if ($month < $current_month && $found === "") {
253 $found = $month;
254 }
255 }
256 return $found;
257 }
258
262 protected function getLatestMonth(): string
263 {
264 reset($this->items);
265 return key($this->items);
266 }
267
268 protected function renderNextButton(string $href = ""): void
269 {
270 $this->renderNavButton("right", $href);
271 }
272
273 protected function renderPreviousButton(string $href = ""): void
274 {
275 $this->renderNavButton("left", $href);
276 }
277
278 protected function renderNavButton(string $dir, string $href = ""): void
279 {
280 $toolbar = $this->gui->toolbar();
281 $b = $this->gui->ui()->factory()->button()->standard(
282 "<span class=\"glyphicon glyphicon-chevron-" . $dir . " \" aria-hidden=\"true\"></span>",
283 $href
284 );
285 if ($href === "") {
286 $b = $b->withUnavailableAction();
287 }
288 $toolbar->addStickyItem($b);
289 }
290
291 protected function renderPostingDropdown(string $cmd): void
292 {
293 $toolbar = $this->gui->toolbar();
294 $f = $this->gui->ui()->factory();
295 $m = [];
296 $dd_title = "";
297 foreach ($this->items as $month => $items) {
298 $label = $this->util->getMonthPresentation($month);
299 $m[] = $f->button()->shy(
300 $label,
301 $this->getMonthTarget($month)
302 )->withUnavailableAction();
303 foreach ($items as $item) {
304 if (!$this->blog_access->isActive((int) $item["id"])) {
305 continue;
306 }
307 $label = $item["title"];
308 if ((int) $item["id"] === $this->blog_page) {
309 $label = "» " . $label;
310 $dd_title = $item["title"];
311 }
312 $label = str_pad("", 12, "&nbsp;") . $label;
313 $m[] = $f->link()->standard(
314 $label,
315 $this->getPostingTarget((int) $item["id"], $cmd)
316 );
317 }
318 }
319 if (count($m) > 0) {
320 $toolbar->addStickyItem($f->dropdown()->standard($m)->withLabel(
321 $this->getDropdownLabel($dd_title)
322 ));
323 }
324 }
325
326 protected function getDropdownLabel(string $label): string
327 {
328 return "<span style='vertical-align: bottom; max-width:60px; display: inline-block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;'>" . $label . "</span>";
329 }
330
331}
__construct(InternalDomainService $domain, InternalGUIService $gui)
renderToolbarNavigation(PermissionManager $blog_acces, array $a_items, int $blog_page, bool $single_posting, $month, int $portfolio_page)
global $lng
Definition: privfeed.php:31