ILIAS  release_8 Revision v8.24
RepositoryMainBarProvider.php
Go to the documentation of this file.
1<?php
2
20
26use ilLink;
27use ilObject;
28use ilUtil;
29use InvalidArgumentException;
33use ilStr;
36
51{
53
54 public function __construct(Container $dic)
55 {
57 $this->request = $dic->repository()->internal()->gui()->standardRequest();
58 }
59
60 public function getStaticTopItems(): array
61 {
62 return [];
63 }
64
65 public function getStaticSubItems(): array
66 {
68 $f = $this->dic->ui()->factory();
69
70 $top = StandardTopItemsProvider::getInstance()->getRepositoryIdentification();
72
73 $title = $this->getHomeItem()->getTitle();
74 $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::ROOT, $title);
75
76 // Home
77 $entries[] = $this->getHomeItem()
78 ->withVisibilityCallable($access_helper->isRepositoryVisible())
79 ->withParent($top)
80 ->withSymbol($icon)
81 ->withPosition(10);
82
83 // Tree-View
84 $title = $this->dic->language()->txt("mm_rep_tree_view");
85
86 $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("icon_reptr.svg"), $title);
87
89 $ref_id = $this->request->getRefId();
91 $asynch = ($top_node === 0);
92 $entries[]
93 = $this->mainmenu->complex($this->if->identifier('rep_tree_view'))
94 ->withVisibilityCallable($access_helper->isRepositoryVisible())
95 ->withContentWrapper(function () use ($ref_id): Legacy {
96 return $this->dic->ui()->factory()->legacy($this->renderRepoTree($ref_id));
97 })
98 ->withSupportsAsynchronousLoading($asynch)
99 ->withTitle($title)
100 ->withSymbol($icon)
101 ->withParent($top)
102 ->withPosition(20);
103
104 $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("icon_lstv.svg"), $title);
105
106 $p = $this;
107 $entries[] = $this->mainmenu
108 ->complex($this->if->identifier('last_visited'))
109 ->withTitle($this->dic->language()->txt('last_visited'))
110 ->withSupportsAsynchronousLoading(true)
111 ->withVisibilityCallable($access_helper->isUserLoggedIn($access_helper->isRepositoryReadable()))
112 ->withPosition(30)
113 ->withSymbol($icon)
114 ->withParent($top)
115 ->withContentWrapper(function () use ($p): Legacy {
116 return $this->dic->ui()->factory()->legacy($p->renderLastVisited());
117 });
118
119 $title = $this->dic->language()->txt("mm_favorites");
120 $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(ilUtil::getImagePath("icon_fav.svg"), $title);
121 $entries[] = $this->mainmenu->complex($this->if->identifier('mm_pd_sel_items'))
122 ->withSupportsAsynchronousLoading(true)
123 ->withTitle($title)
124 ->withSymbol($icon)
125 ->withContentWrapper(function () use ($f): Legacy {
126 $fav_list = new \ilFavouritesListGUI();
127
128 return $f->legacy($fav_list->render());
129 })
130 ->withParent(StandardTopItemsProvider::getInstance()->getPersonalWorkspaceIdentification())
131 ->withPosition(10)
132 ->withAvailableCallable(
133 function () use ($dic): bool {
134 return (bool) $dic->settings()->get('rep_favourites', "0");
135 }
136 )
137 ->withVisibilityCallable(
138 $access_helper->isUserLoggedIn($access_helper->isRepositoryReadable(
139 static function () use ($dic): bool {
140 return true;
141 $pdItemsViewSettings = new ilPDSelectedItemsBlockViewSettings($dic->user());
142
143 return $pdItemsViewSettings->allViewsEnabled() || $pdItemsViewSettings->enabledSelectedItems();
144 }
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 = static function (): string {
169 try {
170 $static_link = ilLink::_getStaticLink(1, 'root', true);
171 } catch (InvalidArgumentException $e) {
172 return "";
173 }
174
175 return $static_link;
176 };
177
178 return $this->mainmenu->link($this->if->identifier('rep_main_page'))
179 ->withTitle($title())
180 ->withAction($action());
181 }
182
183 protected function renderLastVisited(): string
184 {
185 $nav_items = [];
186 if (isset($this->dic['ilNavigationHistory'])) {
187 $nav_items = $this->dic['ilNavigationHistory']->getItems();
188 }
189 reset($nav_items);
190 $cnt = 0;
191 $first = true;
192 $item_groups = [];
193 $items = [];
194
195 $f = $this->dic->ui()->factory();
196 foreach ($nav_items as $k => $nav_item) {
197 if ($cnt++ >= 10) {
198 break;
199 }
200
201 if (!isset($nav_item["ref_id"]) || $this->request->getRefId() === 0
202 || ((int) $nav_item["ref_id"] !== $this->request->getRefId() || !$first)
203 ) { // do not list current item
204 $ititle = ilStr::shortenTextExtended(strip_tags($nav_item["title"]), 50, true); // #11023
205 $obj_id = ilObject::_lookupObjectId((int) $nav_item["ref_id"]);
206 $icon = $f->symbol()->icon()->custom(ilObject::_getIcon($obj_id), $ititle);
207 $icon->setLabel("");
208 $items[] = $f->item()->standard(
209 $f->link()->standard($ititle, $nav_item["link"])
210 )->withLeadIcon($icon);
211 }
212 $first = false;
213 }
214
215 if (count($items) > 0) {
216 $item_groups[] = $f->item()->group("", $items);
217 $panel = $f->panel()->secondary()->listing("", $item_groups);
218 return $this->dic->ui()->renderer()->render([$panel]);
219 }
220
221 return $this->dic->ui()->renderer()->render($this->getNoLastVisitedMessage());
222 }
223
224 // No favourites message box
226 {
227 global $DIC;
228
229 $lng = $DIC->language();
230 $ui = $DIC->ui();
231 $lng->loadLanguageModule("rep");
232 $txt = $lng->txt("rep_no_last_visited_mess");
233 $mbox = $ui->factory()->messageBox()->info($txt);
234
235 return $mbox;
236 }
237
238 protected function renderRepoTree(int $ref_id): string
239 {
240 global $DIC;
241 $tree = $DIC->repositoryTree();
242 if ($ref_id <= 0 || $this->request->getBaseClass() === "ilAdministrationGUI" || !$tree->isInTree($ref_id)) {
243 $ref_id = $tree->readRootId();
244 }
245 $DIC->ctrl()->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
246 $exp = new \ilRepositoryExplorerGUI("ilrepositorygui", "showRepTree");
247 $exp->setSkipRootNode(true);
248 return $exp->getHTML() . "<script>" . $exp->getOnLoadCode() . "</script>";
249 }
250}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
user()
Get the current user.
Definition: Container.php:62
language()
Get interface to the i18n service.
Definition: Container.php:86
settings()
Get the interface to the settings.
Definition: Container.php:126
static init(ilGlobalTemplateInterface $a_main_tpl=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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:23
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 $img, 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.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const ROOT_FOLDER_ID
Definition: constants.php:32
$nd
Definition: error.php:12
$txt
Definition: error.php:13
global $DIC
Definition: feed.php:28
if(isset($_FILES['img_file']) &&is_array($_FILES['img_file'])) $panel
Definition: imgupload.php:198
This describes the specific behavior of an ILIAS standard icon.
Definition: Standard.php:27
$ref_id
Definition: ltiauth.php:67
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lng