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