ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPathGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 class ilPathGUI
28 {
29  private int $startnode;
30  private int $endnode;
31 
32  private bool $textOnly = true;
33  private bool $useImages = false;
34  private bool $hide_leaf = true;
35  private bool $display_cut = false;
36 
37  protected ilLanguage $lng;
38  protected ilTree $tree;
41 
45  public function __construct()
46  {
47  global $DIC;
48 
49  $this->startnode = (int) ROOT_FOLDER_ID;
50  $this->endnode = (int) ROOT_FOLDER_ID;
51  $this->tree = $DIC->repositoryTree();
52  $this->lng = $DIC->language();
53  $this->ctrl = $DIC['ilCtrl'];
54  $this->objectDefinition = $DIC['objDefinition'];
55  }
56 
63  public function getPath(int $a_startnode, int $a_endnode): string
64  {
65  $this->startnode = $a_startnode;
66  $this->endnode = $a_endnode;
67 
68  return $this->getHTML();
69  }
70 
76  public function enableTextOnly(bool $a_status): void
77  {
78  $this->textOnly = $a_status;
79  }
80 
81  public function textOnly(): bool
82  {
83  return $this->textOnly;
84  }
85 
89  public function enableHideLeaf(bool $a_status): void
90  {
91  $this->hide_leaf = $a_status;
92  }
93 
94  public function hideLeaf(): bool
95  {
96  return $this->hide_leaf;
97  }
98 
99  public function setUseImages(bool $a_status): void
100  {
101  $this->useImages = $a_status;
102  }
103 
108  public function getUseImages(): bool
109  {
110  return $this->useImages;
111  }
112 
116  public function enableDisplayCut(bool $a_status): void
117  {
118  $this->display_cut = $a_status;
119  }
120 
124  public function displayCut(): bool
125  {
126  return $this->display_cut;
127  }
128 
132  protected function getHTML(): string
133  {
134  if ($this->textOnly()) {
135  $tpl = new ilTemplate('tpl.locator_text_only.html', true, true, "Services/Locator");
136 
137  $first = true;
138 
139  // Display cut
140  if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
141  $tpl->setCurrentBlock('locator_item');
142  $tpl->setVariable('ITEM', "...");
143  $tpl->parseCurrentBlock();
144 
145  $first = false;
146  }
147 
148  foreach ($this->getPathIds() as $ref_id) {
149  $obj_id = ilObject::_lookupObjId($ref_id);
150  $title = $this->buildTitle($obj_id);
151 
152  if ($first) {
153  if ($ref_id == ROOT_FOLDER_ID) {
154  $title = $this->lng->txt('repository');
155  }
156  } else {
157  $tpl->touchBlock('locator_separator_prefix');
158  }
159 
160  $tpl->setCurrentBlock('locator_item');
161  $tpl->setVariable('ITEM', $title);
162  $tpl->parseCurrentBlock();
163  $first = false;
164  }
165  return $tpl->get();
166  } else {
167  // With images and links
168 
169  $tpl = new ilTemplate('tpl.locator.html', true, true, 'Services/Locator');
170 
171  $first = true;
172 
173  // Display cut
174  if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
175  $tpl->setCurrentBlock('locator_item');
176  $tpl->setVariable('ITEM', "...");
177  $tpl->parseCurrentBlock();
178 
179  $first = false;
180  }
181 
182  foreach ($this->getPathIds() as $ref_id) {
183  $obj_id = ilObject::_lookupObjId($ref_id);
184  $title = $this->buildTitle($obj_id);
185  $type = ilObject::_lookupType($obj_id);
186 
187  if ($first) {
188  if ($ref_id == ROOT_FOLDER_ID) {
189  $title = $this->lng->txt('repository');
190  }
191  } else {
192  $tpl->touchBlock('locator_separator_prefix');
193  }
194  if ($this->getUseImages()) {
195  $tpl->setCurrentBlock('locator_img');
196  $tpl->setVariable('IMG_SRC', ilObject::_getIcon($obj_id, "small", $type));
197  $tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $type));
198  $tpl->parseCurrentBlock();
199  }
200 
201  if (!$this->tree->isDeleted($ref_id)) {
202  $tpl->setCurrentBlock('locator_item');
203  $tpl->setVariable('LINK_ITEM', $this->buildLink($ref_id, $type));
204  $tpl->setVariable('ITEM', $title);
205  $tpl->parseCurrentBlock();
206  } else {
207  $tpl->setCurrentBlock('locator_item');
208  $tpl->setVariable('ITEM_READ_ONLY', $title);
209  $tpl->parseCurrentBlock();
210  }
211 
212  $first = false;
213  }
214  $tpl->setVariable("TXT_BREADCRUMBS", $this->lng->txt("breadcrumb_navigation"));
215  return $tpl->get();
216  }
217  }
218 
219  protected function buildTitle(int $a_obj_id): string
220  {
221  $type = ilObject::_lookupType($a_obj_id);
222  if ($this->objectDefinition->isAdministrationObject($type)) {
223  return $this->lng->txt('obj_' . $type);
224  }
225  return ilObject::_lookupTitle($a_obj_id);
226  }
227 
228  protected function buildLink(int $ref_id, string $type): string
229  {
230  if ($this->objectDefinition->isAdministrationObject($type)) {
231  $current_parameters = $this->ctrl->getParameterArrayByClass(ilAdministrationGUI::class);
232  $this->ctrl->setParameterByClass(ilAdministrationGUI::class, 'ref_id', $ref_id);
233  $link = $this->ctrl->getLinkTargetByClass(ilAdministrationGUI::class, 'jump');
234  $this->ctrl->clearParameterByClass(ilAdministrationGUI::class, 'ref_id');
235  if (isset($current_parameters['ref_id'])) {
236  $this->ctrl->setParameterByClass(ilAdministrationGUI::class, 'ref_id', $current_parameters['ref_id']);
237  }
238  return $link;
239  }
240  return ilLink::_getLink($ref_id, $type);
241  }
242 
246  protected function getPathIds(): array
247  {
248  $path = $this->tree->getPathId($this->endnode, $this->startnode);
249  if ($this->hideLeaf() && count($path)) {
250  unset($path[count($path) - 1]);
251  }
252  return $path;
253  }
254 }
Creates a path for a start and endnode.
getUseImages()
get use images
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
enableTextOnly(bool $a_status)
render path as text only
const ROOT_FOLDER_ID
Definition: constants.php:32
displayCut()
Display a cut with "...".
setUseImages(bool $a_status)
$path
Definition: ltiservices.php:32
enableDisplayCut(bool $a_status)
Display a cut with "...".
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
getHTML()
get html
ilObjectDefinition $objectDefinition
$ref_id
Definition: ltiauth.php:67
ilCtrlInterface $ctrl
static _lookupTitle(int $obj_id)
enableHideLeaf(bool $a_status)
Hide leaf node in path.
buildLink(int $ref_id, string $type)
ilLanguage $lng
getPath(int $a_startnode, int $a_endnode)
get path
__construct()
Constructor.
buildTitle(int $a_obj_id)
static _lookupType(int $id, bool $reference=false)