ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilWorkspaceExplorer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Repository/classes/class.ilRepositoryExplorer.php';
5 
6 /*
7  * Explorer for workspace tree (used in move action per item)
8  *
9  * @author Jörg Lützenkirchen <luetzenkirchen@leifos.com>
10  *
11  */
13 {
14  const SEL_TYPE_CHECK = 1;
15  const SEL_TYPE_RADIO = 2;
16 
17  public $root_id = 0;
18  public $output = '';
19  public $ctrl = null;
20  public $access = null;
21 
22  private $checked_items = array();
23  private $post_var = '';
24  private $form_items = array();
25  private $type = 0;
26 
27  protected $clickable = array();
29 
38  public function __construct($a_type, $a_target, $a_session_variable, ilWorkspaceTree $a_tree, ilWorkspaceAccessHandler $a_access_handler)
39  {
40  global $ilCtrl;
41 
42  $this->ctrl = $ilCtrl;
43  $this->type = $a_type;
44  $this->access = $a_access_handler;
45 
46  parent::__construct($a_target);
47 
48  // #11173
49  if(!$a_tree->readRootId())
50  {
51  // create (workspace) root folder
52  $root = ilObjectFactory::getClassByType("wsrt");
53  $root = new $root(null);
54  $root->create();
55 
56  $root_id = $a_tree->createReference($root->getId());
57  $a_tree->addTree($a_tree->getTreeId(), $root_id);
58  $a_tree->setRootId($root_id);
59  }
60  $this->tree = $a_tree;
61  $this->root_id = $this->tree->readRootId();
62  $this->order_column = 'title';
63  $this->setSessionExpandVariable($a_session_variable);
64 
65  // reset filter
66  $this->filter = array();
67 
68  $this->addFilter('wsrt');
69  $this->addFilter('wfld');
70 
71  $this->addFormItemForType('wsrt');
72  $this->addFormItemForType('wfld');
73 
74  $this->setFiltered(true);
76  }
77 
78  public function showChilds($a_ref_id, $a_obj_id = 0)
79  {
80  if ($a_ref_id == 0 ||
81  $this->access->checkAccess('read', '', $a_ref_id))
82  {
83  return true;
84  }
85  return false;
86  }
87 
88  public function isVisible($a_ref_id,$a_type)
89  {
90  return true;
91  }
92 
93  public function sortNodes($a_nodes,$a_parent_obj_id)
94  {
95  return $a_nodes;
96  }
97 
98  public function isClickable($a_type, $a_ref_id = 0, $a_obj_id = 0)
99  {
100  if(is_array($this->clickable) && in_array($a_type, $this->clickable) &&
101  $a_ref_id)
102  {
103  return true;
104  }
105  return false;
106  }
107 
108  public function addFormItemForType($type)
109  {
110  $this->form_items[$type] = true;
111  }
112  public function removeFormItemForType($type)
113  {
114  $this->form_items[$type] = false;
115  }
116  public function removeAllFormItemTypes()
117  {
118  $this->form_items = array();
119  }
120  public function setCheckedItems($a_checked_items = array())
121  {
122  $this->checked_items = $a_checked_items;
123  }
124  public function isItemChecked($a_id)
125  {
126  return in_array($a_id, $this->checked_items) ? true : false;
127  }
128  public function setPostVar($a_post_var)
129  {
130  $this->post_var = $a_post_var;
131  }
132  public function getPostVar()
133  {
134  return $this->post_var;
135  }
136 
137  public function buildFormItem($a_node_id, $a_type)
138  {
139  if(!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type])
140  {
141  return;
142  }
143 
144  switch($this->type)
145  {
146  case self::SEL_TYPE_CHECK:
147  return ilUtil::formCheckbox((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
148 
149  case self::SEL_TYPE_RADIO:
150  return ilUtil::formRadioButton((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
151  }
152  }
153 
154  function formatObject($tpl, $a_node_id, $a_option, $a_obj_id = 0)
155  {
156  global $lng;
157 
158  if (!isset($a_node_id) or !is_array($a_option))
159  {
160  require_once './Services/Exceptions/classes/class.ilException.php';
161  throw new ilException("Missing parameter or wrong datatype! ".
162  "node_id: ".$a_node_id." options:".var_dump($a_option));
163  }
164 
165  $pic = false;
166  foreach ($a_option["tab"] as $picture)
167  {
168  if ($picture == 'plus')
169  {
170  $tpl->setCurrentBlock("expander");
171  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
172  $target = $this->createTarget('+',$a_node_id);
173  $tpl->setVariable("LINK_NAME", $a_node_id);
174  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
175  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
176  $tpl->parseCurrentBlock();
177  $pic = true;
178  }
179 
180  if ($picture == 'minus' && $this->show_minus)
181  {
182  $tpl->setCurrentBlock("expander");
183  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
184  $target = $this->createTarget('-',$a_node_id);
185  $tpl->setVariable("LINK_NAME", $a_node_id);
186  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
187  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
188  $tpl->parseCurrentBlock();
189  $pic = true;
190  }
191  }
192 
193  if (!$pic)
194  {
195  $tpl->setCurrentBlock("blank");
196  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
197  $tpl->parseCurrentBlock();
198  }
199 
200  if ($this->output_icons)
201  {
202  $tpl->setCurrentBlock("icon");
203  $tpl->setVariable("ICON_IMAGE" , $this->getImage("icon_".$a_option["type"].".svg", $a_option["type"], $a_obj_id));
204 
205  $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
206  $this->iconList[] = "iconid_".$a_node_id;
207  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
208  $tpl->parseCurrentBlock();
209  }
210 
211  if(strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type'])))
212  {
213  $tpl->setCurrentBlock('check');
214  $tpl->setVariable('OBJ_CHECK', $formItem);
215  $tpl->parseCurrentBlock();
216  }
217 
218  if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id)) // output link
219  {
220  $tpl->setCurrentBlock("link");
221  //$target = (strpos($this->target, "?") === false) ?
222  // $this->target."?" : $this->target."&";
223  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
224  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
225 
226  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
227 
228  if ($style_class != "")
229  {
230  $tpl->setVariable("A_CLASS", ' class="'.$style_class.'" ' );
231  }
232 
233  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
234  {
235  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
236  }
237 
238  $tpl->setVariable("LINK_NAME", $a_node_id);
239  $tpl->setVariable("TITLE", ilUtil::shortenText(
240  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
241  $this->textwidth, true));
242  $tpl->setVariable("DESC", ilUtil::shortenText(
243  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]), $this->textwidth, true));
244  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
245  if ($frame_target != "")
246  {
247  $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
248  }
249  $tpl->parseCurrentBlock();
250  }
251  else // output text only
252  {
253  $tpl->setCurrentBlock("text");
254  $tpl->setVariable("OBJ_TITLE", ilUtil::shortenText(
255  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]), $this->textwidth, true));
256  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
257  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]), $this->textwidth, true));
258  $tpl->parseCurrentBlock();
259  }
260 
261  $tpl->setCurrentBlock("list_item");
262  $tpl->parseCurrentBlock();
263  $tpl->touchBlock("element");
264  }
265 
266  /*
267  * overwritten method from base class
268  * @access public
269  * @param integer obj_id
270  * @param integer array options
271  * @return string
272  */
273  function formatHeader($tpl, $a_obj_id,$a_option)
274  {
275  global $lng;
276 
277  // custom icons
278  $path = ilObject::_getIcon($a_obj_id, "small", "wsrt");
279 
280  $tpl->setCurrentBlock("icon");
281  $title = $this->tree->getNodeData($this->root_id);
282  $title = $title["title"];
283  if(!$title)
284  {
285  $title = $lng->txt("personal_workspace");
286  }
287 
288  $tpl->setVariable("ICON_IMAGE", $path);
289  $tpl->setVariable("TXT_ALT_IMG", $title);
290  $tpl->parseCurrentBlock();
291 
292  if(strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type'])))
293  {
294  $tpl->setCurrentBlock('check');
295  $tpl->setVariable('OBJ_CHECK', $formItem);
296  $tpl->parseCurrentBlock();
297  }
298 
299  $tpl->setVariable('OBJ_TITLE', $title);
300  }
301 
303  {
304  $this->clickable[] = $a_type;
305  }
306 
307  function setCustomLinkTarget($a_target)
308  {
309  $this->custom_link_target = $a_target;
310  }
311 
312  function buildLinkTarget($a_node_id, $a_type)
313  {
314  if(!$this->custom_link_target)
315  {
316  return parent::buildLinkTarget($a_node_id, $a_type);
317  }
318 
319  $link = $this->custom_link_target."&".$this->target_get."=".$a_node_id;
320  return $link;
321  }
322 }
323 ?>
static getClassByType($a_obj_type)
Get class by type.
sortNodes($a_nodes, $a_parent_obj_id)
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
$path
Definition: aliased.php:25
formatObject($tpl, $a_node_id, $a_option, $a_obj_id=0)
Base class for ILIAS Exception handling.
setFilterMode($a_mode=IL_FM_NEGATIVE)
set filter mode
getNodeStyleClass($a_id, $a_type)
get style class for node
showChilds($a_ref_id, $a_obj_id=0)
buildLinkTarget($a_node_id, $a_type)
createReference($a_object_id)
Create workspace reference for object.
formatHeader($tpl, $a_obj_id, $a_option)
getTreeId()
get tree id public
isClickable($a_type, $a_ref_id=0, $a_obj_id=0)
Access handler for personal workspace.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
const IL_FM_POSITIVE
Tree handler for personal workspace.
setFiltered($a_bool)
active/deactivate the filter public
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
createTarget($a_type, $a_node_id, $a_highlighted_subtree=false, $a_append_anch=true)
Creates Get Parameter private.
buildOnClick($a_node_id, $a_type, $a_title)
get onclick event handling (may be overwritten by derived classes)
$a_type
Definition: workflow.php:93
buildFormItem($a_node_id, $a_type)
__construct($a_type, $a_target, $a_session_variable, ilWorkspaceTree $a_tree, ilWorkspaceAccessHandler $a_access_handler)
Constructor public.
getImage($a_name, $a_type="", $a_obj_id="")
get image path
setCheckedItems($a_checked_items=array())
setRootId($a_root_id)
buildFrameTarget($a_type, $a_child=0, $a_obj_id=0)
STATIC, do not use $this inside!
Create styles array
The data for the language used.
static formRadioButton($checked, $varname, $value, $onclick=null, $disabled=false)
??? public
buildTitle($a_title, $a_id, $a_type)
standard implementation for title, may be overwritten by derived classes
isVisible($a_ref_id, $a_type)
global $lng
Definition: privfeed.php:17
setSessionExpandVariable($a_var_name="expand")
set name of expand session variable
addFilter($a_item)
adds item to the filter public
addTree($a_tree_id, $a_node_id=-1)
create a new tree to do: ???
buildDescription($a_desc, $a_id, $a_type)
standard implementation for description, may be overwritten by derived classes
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public
readRootId()
read root id from database