ILIAS  release_8 Revision v8.24
class.ilPathGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
33{
34 private int $startnode;
35 private int $endnode;
36
37 private bool $textOnly = true;
38 private bool $useImages = false;
39 private bool $hide_leaf = true;
40 private bool $display_cut = false;
41
42 protected ilLanguage $lng;
43 protected ilTree $tree;
45
49 public function __construct()
50 {
51 global $DIC;
52
53 $this->startnode = (int) ROOT_FOLDER_ID;
54 $this->endnode = (int) ROOT_FOLDER_ID;
55 $this->tree = $DIC->repositoryTree();
56 $this->lng = $DIC->language();
57 $this->objectDefinition = $DIC['objDefinition'];
58 }
59
66 public function getPath(int $a_startnode, int $a_endnode): string
67 {
68 $this->startnode = $a_startnode;
69 $this->endnode = $a_endnode;
70
71 return $this->getHTML();
72 }
73
79 public function enableTextOnly(bool $a_status): void
80 {
81 $this->textOnly = $a_status;
82 }
83
84 public function textOnly(): bool
85 {
86 return $this->textOnly;
87 }
88
92 public function enableHideLeaf(bool $a_status): void
93 {
94 $this->hide_leaf = $a_status;
95 }
96
97 public function hideLeaf(): bool
98 {
99 return $this->hide_leaf;
100 }
101
102 public function setUseImages(bool $a_status): void
103 {
104 $this->useImages = $a_status;
105 }
106
111 public function getUseImages(): bool
112 {
113 return $this->useImages;
114 }
115
119 public function enableDisplayCut(bool $a_status): void
120 {
121 $this->display_cut = $a_status;
122 }
123
127 public function displayCut(): bool
128 {
129 return $this->display_cut;
130 }
131
135 protected function getHTML(): string
136 {
137 if ($this->textOnly()) {
138 $tpl = new ilTemplate('tpl.locator_text_only.html', true, true, "Services/Locator");
139
140 $first = true;
141
142 // Display cut
143 if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
144 $tpl->setCurrentBlock('locator_item');
145 $tpl->setVariable('ITEM', "...");
146 $tpl->parseCurrentBlock();
147
148 $first = false;
149 }
150
151 foreach ($this->getPathIds() as $ref_id) {
153 $title = $this->buildTitle($obj_id);
154
155 if ($first) {
156 if ($ref_id == ROOT_FOLDER_ID) {
157 $title = $this->lng->txt('repository');
158 }
159 } else {
160 $tpl->touchBlock('locator_separator_prefix');
161 }
162
163 $tpl->setCurrentBlock('locator_item');
164 $tpl->setVariable('ITEM', $title);
165 $tpl->parseCurrentBlock();
166 $first = false;
167 }
168 return $tpl->get();
169 } else {
170 // With images and links
171
172 $tpl = new ilTemplate('tpl.locator.html', true, true, 'Services/Locator');
173
174 $first = true;
175
176 // Display cut
177 if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
178 $tpl->setCurrentBlock('locator_item');
179 $tpl->setVariable('ITEM', "...");
180 $tpl->parseCurrentBlock();
181
182 $first = false;
183 }
184
185 foreach ($this->getPathIds() as $ref_id) {
187 $title = $this->buildTitle($obj_id);
188 $type = ilObject::_lookupType($obj_id);
189
190 if ($first) {
191 if ($ref_id == ROOT_FOLDER_ID) {
192 $title = $this->lng->txt('repository');
193 }
194 } else {
195 $tpl->touchBlock('locator_separator_prefix');
196 }
197 if ($this->getUseImages()) {
198 $tpl->setCurrentBlock('locator_img');
199 $tpl->setVariable('IMG_SRC', ilObject::_getIcon($obj_id, "small", $type));
200 $tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $type));
201 $tpl->parseCurrentBlock();
202 }
203
204 if (!$this->tree->isDeleted($ref_id)) {
205 $tpl->setCurrentBlock('locator_item');
206 $tpl->setVariable('LINK_ITEM', ilLink::_getLink($ref_id, $type));
207 $tpl->setVariable('ITEM', $title);
208 $tpl->parseCurrentBlock();
209 } else {
210 $tpl->setCurrentBlock('locator_item');
211 $tpl->setVariable('ITEM_READ_ONLY', $title);
212 $tpl->parseCurrentBlock();
213 }
214
215 $first = false;
216 }
217 $tpl->setVariable("TXT_BREADCRUMBS", $this->lng->txt("breadcrumb_navigation"));
218 return $tpl->get();
219 }
220 }
221
222 protected function buildTitle(int $a_obj_id): string
223 {
224 $type = ilObject::_lookupType($a_obj_id);
225 if ($this->objectDefinition->isAdministrationObject($type)) {
226 return $this->lng->txt('obj_' . $type);
227 }
228 return ilObject::_lookupTitle($a_obj_id);
229 }
230
234 protected function getPathIds(): array
235 {
236 $path = $this->tree->getPathId($this->endnode, $this->startnode);
237 if ($this->hideLeaf() && count($path)) {
238 unset($path[count($path) - 1]);
239 }
240 return $path;
241 }
242}
language handling
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Creates a path for a start and endnode.
getUseImages()
get use images
getHTML()
get html
getPath(int $a_startnode, int $a_endnode)
get path
ilLanguage $lng
displayCut()
Display a cut with "...".
setUseImages(bool $a_status)
enableDisplayCut(bool $a_status)
Display a cut with "...".
__construct()
Constructor.
enableTextOnly(bool $a_status)
render path as text only
buildTitle(int $a_obj_id)
ilObjectDefinition $objectDefinition
enableHideLeaf(bool $a_status)
Hide leaf node in path.
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$ref_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:32
$type