ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPathGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 class ilPathGUI
34 {
35  private $startnode = ROOT_FOLDER_ID;
36  private $endnode = ROOT_FOLDER_ID;
37 
38  private $textOnly = true;
39  private $useImages = false;
40  private $hide_leaf = true;
41  private $display_cut = false;
42 
43  protected $lng = null;
44  protected $tree = null;
45 
49  public function __construct()
50  {
51  global $DIC;
52 
53  $tree = $DIC['tree'];
54  $lng = $DIC['lng'];
55 
56  $this->tree = $tree;
57  $this->lng = $lng;
58  }
59 
66  public function getPath($a_startnode, $a_endnode)
67  {
68  $this->startnode = $a_startnode;
69  $this->endnode = $a_endnode;
70 
71  return $this->getHTML();
72  }
73 
79  public function enableTextOnly($a_status)
80  {
81  $this->textOnly = $a_status;
82  }
83 
88  public function textOnly()
89  {
90  return $this->textOnly;
91  }
92 
97  public function enableHideLeaf($a_status)
98  {
99  $this->hide_leaf = $a_status;
100  }
101 
102  public function hideLeaf()
103  {
104  return $this->hide_leaf;
105  }
111  public function setUseImages($a_status)
112  {
113  $this->useImages = $a_status;
114  }
115 
120  public function getUseImages()
121  {
122  return $this->useImages;
123  }
124 
129  public function enableDisplayCut($a_status)
130  {
131  $this->display_cut = $a_status;
132  }
133 
138  public function displayCut()
139  {
140  return $this->display_cut;
141  }
142 
147  protected function getHTML()
148  {
149  if ($this->textOnly()) {
150  $tpl = new ilTemplate('tpl.locator_text_only.html', true, true, "Services/Locator");
151 
152  $first = true;
153 
154  // Display cut
155  if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
156  $tpl->setCurrentBlock('locator_item');
157  $tpl->setVariable('ITEM', "...");
158  $tpl->parseCurrentBlock();
159 
160  $first = false;
161  }
162 
163  foreach ($this->getPathIds() as $ref_id) {
164  $obj_id = ilObject::_lookupObjId($ref_id);
165  $title = $this->buildTitle($obj_id);
166 
167  if ($first) {
168  if ($ref_id == ROOT_FOLDER_ID) {
169  $title = $this->lng->txt('repository');
170  }
171  } else {
172  $tpl->touchBlock('locator_separator_prefix');
173  }
174 
175  $tpl->setCurrentBlock('locator_item');
176  $tpl->setVariable('ITEM', $title);
177  $tpl->parseCurrentBlock();
178  $first = false;
179  }
180  return $tpl->get();
181  } else {
182  // With images and links
183  include_once './Services/Link/classes/class.ilLink.php';
184 
185  $tpl = new ilTemplate('tpl.locator.html', true, true, 'Services/Locator');
186 
187  $first = true;
188 
189  // Display cut
190  if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
191  $tpl->setCurrentBlock('locator_item');
192  $tpl->setVariable('ITEM', "...");
193  $tpl->parseCurrentBlock();
194 
195  $first = false;
196  }
197 
198  foreach ($this->getPathIds() as $ref_id) {
199  $obj_id = ilObject::_lookupObjId($ref_id);
200  $title = $this->buildTitle($obj_id);
201  $type = ilObject::_lookupType($obj_id);
202 
203  if ($first) {
204  if ($ref_id == ROOT_FOLDER_ID) {
205  $title = $this->lng->txt('repository');
206  }
207  } else {
208  $tpl->touchBlock('locator_separator_prefix');
209  }
210  if ($this->getUseImages()) {
211  $tpl->setCurrentBlock('locator_img');
212  $tpl->setVariable('IMG_SRC', ilUtil::getTypeIconPath($type, $obj_id));
213  $tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $type));
214  $tpl->parseCurrentBlock();
215  }
216  $tpl->setCurrentBlock('locator_item');
217  $tpl->setVariable('LINK_ITEM', ilLink::_getLink($ref_id, $type));
218  $tpl->setVariable('ITEM', $title);
219  $tpl->parseCurrentBlock();
220  $first = false;
221  }
222  return $tpl->get();
223  }
224  }
225 
230  protected function buildTitle($a_obj_id)
231  {
232  return ilObject::_lookupTitle($a_obj_id);
233  }
234 
240  protected function getPathIds()
241  {
242  $path = $this->tree->getPathId($this->endnode, $this->startnode);
243  if ($this->hideLeaf()) {
244  unset($path[count($path) - 1]);
245  }
246  return $path ? $path : array();
247  }
248 }
Creates a path for a start and endnode.
getUseImages()
get use images
$path
Definition: aliased.php:25
setUseImages($a_status)
set use images
$type
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
displayCut()
Display a cut with "...".
static _lookupTitle($a_id)
lookup object title
enableTextOnly($a_status)
render path as text only
textOnly()
show text only
static getTypeIconPath($a_type, $a_obj_id, $a_size='small')
Get type icon path path Return image path for icon_xxx.pngs Or (if enabled) path to custom icon Depre...
getHTML()
get html
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
enableHideLeaf($a_status)
Hide leaf node in path.
buildTitle($a_obj_id)
enableDisplayCut($a_status)
Display a cut with "...".
static _lookupType($a_id, $a_reference=false)
lookup object type
__construct()
Constructor.
getPath($a_startnode, $a_endnode)
get path