ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
RepositoryMainBarProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ilLink;
30use ilObject;
31use ilUtil;
32use InvalidArgumentException;
36use ilStr;
40
55{
57
58 public function __construct(Container $dic)
59 {
61 $this->request = $dic->repository()->internal()->gui()->standardRequest();
62 }
63
64 public function getStaticTopItems(): array
65 {
66 return [];
67 }
68
69 public function getStaticSubItems(): array
70 {
72 $f = $this->dic->ui()->factory();
73
74 $top = StandardTopItemsProvider::getInstance()->getRepositoryIdentification();
76
77 $title = $this->getHomeItem()->getTitle();
78 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::ROOT, $title);
79
80 // Home
81 $entries[] = $this->getHomeItem()
82 ->withVisibilityCallable($access_helper->isRepositoryVisible())
83 ->withParent($top)
84 ->withSymbol($icon)
85 ->withPosition(10);
86
87 // Tree-View
88 $title = $this->dic->language()->txt("mm_repo_tree_view");
89
90 $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_reptr.svg"), $title);
91
93 $ref_id = $this->request->getRefId();
95 $asynch = ($top_node === 0);
96 $entries[]
97 = $this->mainmenu->complex($this->if->identifier('rep_tree_view'))
98 ->withVisibilityCallable($access_helper->isRepositoryVisible())
99 ->withContentWrapper(function () use ($ref_id): Legacy\Content {
100 return $this->dic->ui()->factory()->legacy()->content($this->renderRepoTree($ref_id));
101 })
102 ->withSupportsAsynchronousLoading($asynch)
103 ->withTitle($title)
104 ->withSymbol($icon)
105 ->withParent($top)
106 ->withPosition(20);
107
108 $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_lstv.svg"), $title);
109
110 $p = $this;
111 $entries[] = $this->mainmenu
112 ->complex($this->if->identifier('last_visited'))
113 ->withTitle($this->dic->language()->txt('last_visited'))
114 ->withSupportsAsynchronousLoading(true)
115 ->withVisibilityCallable($access_helper->isUserLoggedIn($access_helper->isRepositoryReadable()))
116 ->withPosition(30)
117 ->withSymbol($icon)
118 ->withParent($top)
119 ->withContentWrapper(function () use ($p): Legacy\Content {
120 return $this->dic->ui()->factory()->legacy()->content($p->renderLastVisited());
121 });
122
123 $title = $this->dic->language()->txt("mm_favorites");
124 $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_fav.svg"), $title);
125
126 $entries[] = $this->mainmenu->complex($this->if->identifier('mm_pd_sel_items'))
127 ->withSupportsAsynchronousLoading(true)
128 ->withTitle($title)
129 ->withSymbol($icon)
130 ->withContentWrapper(
131 static fn(): Legacy\Content =>
132 $f->legacy()->content((new ilFavouritesListGUI())->render())
133 )
134 ->withParent(StandardTopItemsProvider::getInstance()->getPersonalWorkspaceIdentification())
135 ->withPosition(10)
136 ->withAvailableCallable(
137 static fn(): bool =>
138 (bool) $dic->settings()->get('rep_favourites', "0")
139 )
141 $access_helper->isUserLoggedIn($access_helper->isRepositoryReadable(
142 static function () use ($dic): bool {
143 $pdItemsViewSettings = new ilPDSelectedItemsBlockViewSettings($dic->user());
144 return $pdItemsViewSettings->allViewsEnabled() || $pdItemsViewSettings->enabledSelectedItems();
145 }
146 ))
147 );
148 return $entries;
149 }
150
151
152 private function getHomeItem(): Link
153 {
155
156 $title = static function () use ($dic): string {
157 try {
158 $nd = $dic['tree']->getNodeData(ROOT_FOLDER_ID);
159 $title = ($nd["title"] === "ILIAS" ? $dic->language()->txt("repository") : $nd["title"]);
161 } catch (InvalidArgumentException $e) {
162 return "";
163 }
164
165 return $title . " - " . $dic->language()->txt("rep_main_page");
166 };
167
168 $action = function (): string {
169 try {
171 $static_url_uri_builder = $this->dic['static_url.uri_builder'];
172 $static_link = $static_url_uri_builder->buildLegacy(1, 'root');
173 } catch (InvalidArgumentException $e) {
174 return "";
175 }
176
177 return $static_link;
178 };
179
180 return $this->mainmenu->link($this->if->identifier('rep_main_page'))
181 ->withTitle($title())
182 ->withAction($action());
183 }
184
185 protected function renderLastVisited(): string
186 {
187 $nav_items = [];
188 if (isset($this->dic['ilNavigationHistory'])) {
189 $nav_items = $this->dic['ilNavigationHistory']->getItems();
190 }
191 reset($nav_items);
192 $cnt = 0;
193 $first = true;
194 $item_groups = [];
195 $items = [];
196
197 $f = $this->dic->ui()->factory();
198 foreach ($nav_items as $k => $nav_item) {
199 if ($cnt++ >= 10) {
200 break;
201 }
202
203 if (!isset($nav_item["ref_id"]) || $this->request->getRefId() === 0
204 || ((int) $nav_item["ref_id"] !== $this->request->getRefId() || !$first)
205 ) { // do not list current item
206 $ititle = ilStr::shortenTextExtended(strip_tags($nav_item["title"]), 50, true); // #11023
207 $obj_id = ilObject::_lookupObjectId((int) $nav_item["ref_id"]);
208 $icon = $f->symbol()->icon()->custom(ilObject::_getIcon($obj_id), $ititle);
209 $icon->setLabel("");
210 $items[] = $f->item()->standard(
211 $f->link()->standard($ititle, $nav_item["link"])
212 )->withLeadIcon($icon);
213 }
214 $first = false;
215 }
216
217 if (count($items) > 0) {
218 $item_groups[] = $f->item()->group("", $items);
219 $panel = $f->panel()->secondary()->listing("", $item_groups);
220 return $this->dic->ui()->renderer()->render([$panel]);
221 }
222
223 return $this->dic->ui()->renderer()->render($this->getNoLastVisitedMessage());
224 }
225
226 // No favourites message box
228 {
229 global $DIC;
230
231 $lng = $DIC->language();
232 $ui = $DIC->ui();
233 $lng->loadLanguageModule("rep");
234 $txt = $lng->txt("rep_no_last_visited_mess");
235 $mbox = $ui->factory()->messageBox()->info($txt);
236
237 return $mbox;
238 }
239
240 protected function renderRepoTree(int $ref_id): string
241 {
242 global $DIC;
243 $tree = $DIC->repositoryTree();
244 if ($ref_id <= 0 || $this->request->getBaseClass() === "ilAdministrationGUI" || !$tree->isInTree($ref_id)) {
245 $ref_id = $tree->readRootId();
246 }
247 $DIC->ctrl()->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
248 $exp = new \ilRepositoryExplorerGUI("ilrepositorygui", "showRepTree");
249 $exp->setSkipRootNode(true);
250 return $exp->getHTML() . "<script>" . $exp->getOnLoadCode() . "</script>";
251 }
252}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
user()
Get the current user.
Definition: Container.php:71
language()
Get interface to the i18n service.
Definition: Container.php:95
settings()
Get the interface to the settings.
Definition: Container.php:135
static init(?ilGlobalTemplateInterface $a_main_tpl=null)
Class ilObject Basic functions for all objects.
static _lookupObjectId(int $ref_id)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilStr.php:20
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
Util class various functions, usage as namespace.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
const ROOT_FOLDER_ID
Definition: constants.php:32
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:27
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
withAction(URI|Signal|string $action)
withParent(IdentificationInterface $identification)
withVisibilityCallable(callable $is_visible)
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26