ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
RepositoryMainBarProvider.php
Go to the documentation of this file.
1 <?php namespace ILIAS\Repository\Provider;
2 
9 use ilLink;
10 use ilObject;
11 use ilUtil;
13 
28 {
29 
30 
34  public function getStaticTopItems() : array
35  {
36  return [];
37  }
38 
39 
43  public function getStaticSubItems() : array
44  {
45  $top = StandardTopItemsProvider::getInstance()->getRepositoryIdentification();
46  $access_helper = BasicAccessCheckClosures::getInstance();
47 
48  $title = $this->getHomeItem()->getTitle();
49  $icon = $this->dic->ui()->factory()->symbol()->icon()->standard(Standard::ROOT, $title)->withIsOutlined(true);
50 
51  // Home
52  $entries[] = $this->getHomeItem()
53  ->withVisibilityCallable($access_helper->isRepositoryVisible())
54  ->withParent($top)
55  ->withSymbol($icon)
56  ->withPosition(10);
57 
58  // Tree-View
59  $title = $this->dic->language()->txt("mm_rep_tree_view");
60 
61  $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("outlined/icon_reptr.svg"), $title);
62 
63  /*
64  if ($_GET["baseClass"] == "ilRepositoryGUI") {
65  $entries[] = $this->mainmenu->link($this->if->identifier('tree_view'))
66  ->withAction($link)
67  ->withParent($top)
68  ->withPosition(30)
69  ->withSymbol($icon)
70  ->withTitle($title);
71  }*/
72 
74  $ref_id = (int) $_GET["ref_id"];
76  $asynch = ($top_node === 0);
77  $entries[]
78  = $this->mainmenu->complex($this->if->identifier('rep_tree_view'))
79  ->withVisibilityCallable($access_helper->isRepositoryVisible())
80  ->withContentWrapper(function () use ($ref_id) {
81  return $this->dic->ui()->factory()->legacy($this->renderRepoTree($ref_id));
82  })
83  ->withSupportsAsynchronousLoading($asynch)
84  ->withTitle($title)
85  ->withSymbol($icon)
86  ->withParent($top)
87  ->withPosition(20);
88 
89  $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("outlined/icon_lstv.svg"), $title);
90 
91  $p = $this;
92  $entries[] = $this->mainmenu
93  ->complex($this->if->identifier('last_visited'))
94  ->withTitle($this->dic->language()->txt('last_visited'))
95  ->withSupportsAsynchronousLoading(true)
96  ->withVisibilityCallable($access_helper->isUserLoggedIn($access_helper->isRepositoryReadable()))
97  ->withPosition(30)
98  ->withSymbol($icon)
99  ->withParent($top)
100  ->withContentWrapper(function () use ($p) {
101  return $this->dic->ui()->factory()->legacy($p->renderLastVisited());
102  });
103 
104 
105  return $entries;
106  }
107 
108 
109  private function getHomeItem() : Link
110  {
111  $dic = $this->dic;
112 
113  $title = function () use ($dic) : string {
114  try {
115  $nd = $dic['tree']->getNodeData(ROOT_FOLDER_ID);
116  $title = ($nd["title"] === "ILIAS" ? $dic->language()->txt("repository") : $nd["title"]);
117  $icon = ilUtil::img(ilObject::_getIcon(ilObject::_lookupObjId(1), "tiny"));
118  } catch (InvalidArgumentException $e) {
119  return "";
120  }
121 
122  return $title . " - " . $dic->language()->txt("rep_main_page");
123  };
124 
125  $action = function () : string {
126  try {
127  $static_link = ilLink::_getStaticLink(1, 'root', true);
128  } catch (InvalidArgumentException $e) {
129  return "";
130  }
131 
132  return $static_link;
133  };
134 
135  return $this->mainmenu->link($this->if->identifier('rep_main_page'))
136  ->withTitle($title())
137  ->withAction($action());
138  }
139 
140 
141 
147  protected function renderLastVisited()
148  {
149  $nav_items = [];
150  if (isset($this->dic['ilNavigationHistory'])) {
151  $nav_items = $this->dic['ilNavigationHistory']->getItems();
152  }
153  reset($nav_items);
154  $cnt = 0;
155  $first = true;
156  $item_groups = [];
157  $items = [];
158 
159  $f = $this->dic->ui()->factory();
160  foreach ($nav_items as $k => $nav_item) {
161  if ($cnt++ >= 10) {
162  break;
163  }
164 
165  if (!isset($nav_item["ref_id"]) || !isset($_GET["ref_id"])
166  || ($nav_item["ref_id"] != $_GET["ref_id"] || !$first)
167  ) { // do not list current item
168  $ititle = ilUtil::shortenText(strip_tags($nav_item["title"]), 50, true); // #11023
169  $obj_id = ilObject::_lookupObjectId($nav_item["ref_id"]);
170  $items[] = $f->item()->standard(
171  $f->link()->standard($ititle, $nav_item["link"])
172  )->withLeadIcon($f->symbol()->icon()->custom(ilObject::_getIcon($obj_id), $ititle));
173  }
174  $first = false;
175  }
176 
177  if (count($items) > 0) {
178  $item_groups[] = $f->item()->group("", $items);
179  $panel = $f->panel()->secondary()->listing("", $item_groups);
180  return $this->dic->ui()->renderer()->render([$panel]);
181  }
182 
183  return $this->dic->ui()->renderer()->render($this->getNoLastVisitedMessage());
184  }
185 
191  public function getNoLastVisitedMessage() : \ILIAS\UI\Component\MessageBox\MessageBox
192  {
193  global $DIC;
194 
195  $lng = $DIC->language();
196  $ui = $DIC->ui();
197  $lng->loadLanguageModule("rep");
198  $txt = $lng->txt("rep_no_last_visited_mess");
199  $mbox = $ui->factory()->messageBox()->info($txt);
200 
201  return $mbox;
202  }
203 
204 
205 
211  protected function renderRepoTree(int $ref_id)
212  {
213  global $DIC;
214  $tree = $DIC->repositoryTree();
215  if ($_GET["baseClass"] == "ilAdministrationGUI" || $ref_id <= 0 || !$tree->isInTree($ref_id)) {
216  $ref_id = $tree->readRootId();
217  }
218  $DIC->ctrl()->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
219  $exp = new \ilRepositoryExplorerGUI("ilrepositorygui", "showRepTree");
220  $exp->setSkipRootNode(true);
221  return $exp->getHTML()."<script>".$exp->getOnLoadCode()."</script>";
222  }
223 }
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
Class Factory.
$_GET["client_id"]
Class ChatMainBarProvider .
static init($a_main_tpl=null)
Init JS.
static _lookupObjectId($a_ref_id)
lookup object id
$nd
Definition: error.php:12
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
$lng
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _lookupObjId($a_id)
$txt
Definition: error.php:13
static img($a_src, $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
$DIC
Definition: xapitoken.php:46