ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $tree,$lng;
52 
53  $this->tree = $tree;
54  $this->lng = $lng;
55  }
56 
63  public function getPath($a_startnode, $a_endnode)
64  {
65  $this->startnode = $a_startnode;
66  $this->endnode = $a_endnode;
67 
68  return $this->getHTML();
69  }
70 
76  public function enableTextOnly($a_status)
77  {
78  $this->textOnly = $a_status;
79  }
80 
85  public function textOnly()
86  {
87  return $this->textOnly;
88  }
89 
94  public function enableHideLeaf($a_status)
95  {
96  $this->hide_leaf = $a_status;
97  }
98 
99  public function hideLeaf()
100  {
101  return $this->hide_leaf;
102  }
108  public function setUseImages($a_status)
109  {
110  $this->useImages = $a_status;
111  }
112 
117  public function getUseImages()
118  {
119  return $this->useImages;
120  }
121 
126  public function enableDisplayCut($a_status)
127  {
128  $this->display_cut = $a_status;
129  }
130 
135  public function displayCut()
136  {
137  return $this->display_cut;
138  }
139 
144  protected function getHTML()
145  {
146  if ($this->textOnly()) {
147  $tpl = new ilTemplate('tpl.locator_text_only.html', true, true, "Services/Locator");
148 
149  $first = true;
150 
151  // Display cut
152  if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
153  $tpl->setCurrentBlock('locator_item');
154  $tpl->setVariable('ITEM', "...");
155  $tpl->parseCurrentBlock();
156 
157  $first = false;
158  }
159 
160  foreach ($this->getPathIds() as $ref_id) {
161  $obj_id = ilObject::_lookupObjId($ref_id);
162  $title = ilObject::_lookupTitle($obj_id);
163 
164  if ($first) {
165  if ($ref_id == ROOT_FOLDER_ID) {
166  $title = $this->lng->txt('repository');
167  }
168  } else {
169  $tpl->touchBlock('locator_separator_prefix');
170  }
171 
172  $tpl->setCurrentBlock('locator_item');
173  $tpl->setVariable('ITEM', $title);
174  $tpl->parseCurrentBlock();
175  $first = false;
176  }
177  return $tpl->get();
178  } else {
179  // With images and links
180  include_once './Services/Link/classes/class.ilLink.php';
181 
182  $tpl = new ilTemplate('tpl.locator.html', true, true, 'Services/Locator');
183 
184  $first = true;
185 
186  // Display cut
187  if ($this->displayCut() && $this->startnode != ROOT_FOLDER_ID) {
188  $tpl->setCurrentBlock('locator_item');
189  $tpl->setVariable('ITEM', "...");
190  $tpl->parseCurrentBlock();
191 
192  $first = false;
193  }
194 
195  foreach ($this->getPathIds() as $ref_id) {
196  $obj_id = ilObject::_lookupObjId($ref_id);
197  $title = ilObject::_lookupTitle($obj_id);
198  $type = ilObject::_lookupType($obj_id);
199 
200  if ($first) {
201  if ($ref_id == ROOT_FOLDER_ID) {
202  $title = $this->lng->txt('repository');
203  }
204  } else {
205  $tpl->touchBlock('locator_separator_prefix');
206  }
207  if ($this->getUseImages()) {
208  $tpl->setCurrentBlock('locator_img');
209  $tpl->setVariable('IMG_SRC', ilUtil::getTypeIconPath($type, $obj_id));
210  $tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $type));
211  $tpl->parseCurrentBlock();
212  }
213  $tpl->setCurrentBlock('locator_item');
214  $tpl->setVariable('LINK_ITEM', ilLink::_getLink($ref_id, $type));
215  $tpl->setVariable('ITEM', $title);
216  $tpl->parseCurrentBlock();
217  $first = false;
218  }
219  return $tpl->get();
220  }
221  }
222 
228  protected function getPathIds()
229  {
230  $path = $this->tree->getPathId($this->endnode, $this->startnode);
231  if ($this->hideLeaf()) {
232  unset($path[count($path) - 1]);
233  }
234  return $path ? $path : array();
235  }
236 }
Creates a path for a start and endnode.
getUseImages()
get use images
setUseImages($a_status)
set use images
$type
$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.
enableDisplayCut($a_status)
Display a cut with "...".
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
__construct()
Constructor.
getPath($a_startnode, $a_endnode)
get path