ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
61  $this->tree = $a_tree;
62  $this->root_id = $this->tree->readRootId();
63  $this->order_column = 'title';
64  $this->setSessionExpandVariable($a_session_variable);
65 
66  // reset filter
67  $this->filter = array();
68 
69  $this->addFilter('wsrt');
70  $this->addFilter('wfld');
71 
72  $this->addFormItemForType('wsrt');
73  $this->addFormItemForType('wfld');
74 
75  $this->setFiltered(true);
77  }
78 
79  public function showChilds($a_ref_id, $a_obj_id = 0)
80  {
81  if ($a_ref_id == 0 ||
82  $this->access->checkAccess('read', '', $a_ref_id))
83  {
84  return true;
85  }
86  return false;
87  }
88 
89  public function isVisible($a_ref_id,$a_type)
90  {
91  return true;
92  }
93 
94  public function sortNodes($a_nodes,$a_parent_obj_id)
95  {
96  return $a_nodes;
97  }
98 
99  public function isClickable($a_type, $a_ref_id, $a_obj_id = 0)
100  {
101  if(is_array($this->clickable) && in_array($a_type, $this->clickable) &&
102  $a_ref_id)
103  {
104  return true;
105  }
106  return false;
107  }
108 
109  public function addFormItemForType($type)
110  {
111  $this->form_items[$type] = true;
112  }
113  public function removeFormItemForType($type)
114  {
115  $this->form_items[$type] = false;
116  }
117  public function removeAllFormItemTypes()
118  {
119  $this->form_items = array();
120  }
121  public function setCheckedItems($a_checked_items = array())
122  {
123  $this->checked_items = $a_checked_items;
124  }
125  public function isItemChecked($a_id)
126  {
127  return in_array($a_id, $this->checked_items) ? true : false;
128  }
129  public function setPostVar($a_post_var)
130  {
131  $this->post_var = $a_post_var;
132  }
133  public function getPostVar()
134  {
135  return $this->post_var;
136  }
137 
138  public function buildFormItem($a_node_id, $a_type)
139  {
140  if(!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type])
141  {
142  return;
143  }
144 
145  switch($this->type)
146  {
147  case self::SEL_TYPE_CHECK:
148  return ilUtil::formCheckbox((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
149 
150  case self::SEL_TYPE_RADIO:
151  return ilUtil::formRadioButton((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
152  }
153  }
154 
155  function formatObject(&$tpl, $a_node_id, $a_option, $a_obj_id = 0)
156  {
157  global $lng;
158 
159  if (!isset($a_node_id) or !is_array($a_option))
160  {
161  $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
162  "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
163  }
164 
165  $pic = false;
166  foreach ($a_option["tab"] as $picture)
167  {
168  if ($picture == 'plus')
169  {
170  $tpl->setCurrentBlock("exp_desc");
171  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
172  $tpl->parseCurrentBlock();
173  $target = $this->createTarget('+',$a_node_id);
174  $tpl->setCurrentBlock("expander");
175  $tpl->setVariable("LINK_NAME", $a_node_id);
176  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
177  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
178  $tpl->parseCurrentBlock();
179  $pic = true;
180  }
181 
182  if ($picture == 'minus' && $this->show_minus)
183  {
184  $tpl->setCurrentBlock("exp_desc");
185  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
186  $tpl->parseCurrentBlock();
187  $target = $this->createTarget('-',$a_node_id);
188  $tpl->setCurrentBlock("expander");
189  $tpl->setVariable("LINK_NAME", $a_node_id);
190  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
191  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
192  $tpl->parseCurrentBlock();
193  $pic = true;
194  }
195  }
196 
197  if (!$pic)
198  {
199  $tpl->setCurrentBlock("blank");
200  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
201  $tpl->parseCurrentBlock();
202  }
203 
204  if ($this->output_icons)
205  {
206  $tpl->setCurrentBlock("icon");
207  $tpl->setVariable("ICON_IMAGE" , $this->getImage("icon_".$a_option["type"].".png", $a_option["type"], $a_obj_id));
208 
209  $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
210  $this->iconList[] = "iconid_".$a_node_id;
211  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
212  $tpl->parseCurrentBlock();
213  }
214 
215  if(strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type'])))
216  {
217  $tpl->setCurrentBlock('check');
218  $tpl->setVariable('OBJ_CHECK', $formItem);
219  $tpl->parseCurrentBlock();
220  }
221 
222  if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id)) // output link
223  {
224  $tpl->setCurrentBlock("link");
225  //$target = (strpos($this->target, "?") === false) ?
226  // $this->target."?" : $this->target."&";
227  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
228  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
229 
230  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
231 
232  if ($style_class != "")
233  {
234  $tpl->setVariable("A_CLASS", ' class="'.$style_class.'" ' );
235  }
236 
237  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
238  {
239  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
240  }
241 
242  $tpl->setVariable("LINK_NAME", $a_node_id);
243  $tpl->setVariable("TITLE", ilUtil::shortenText(
244  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
245  $this->textwidth, true));
246  $tpl->setVariable("DESC", ilUtil::shortenText(
247  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]), $this->textwidth, true));
248  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
249  if ($frame_target != "")
250  {
251  $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
252  }
253  $tpl->parseCurrentBlock();
254  }
255  else // output text only
256  {
257  $tpl->setCurrentBlock("text");
258  $tpl->setVariable("OBJ_TITLE", ilUtil::shortenText(
259  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]), $this->textwidth, true));
260  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
261  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]), $this->textwidth, true));
262  $tpl->parseCurrentBlock();
263  }
264 
265  $tpl->setCurrentBlock("list_item");
266  $tpl->parseCurrentBlock();
267  $tpl->touchBlock("element");
268  }
269 
270  /*
271  * overwritten method from base class
272  * @access public
273  * @param integer obj_id
274  * @param integer array options
275  * @return string
276  */
277  function formatHeader(&$tpl, $a_obj_id,$a_option)
278  {
279  global $lng;
280 
281  // custom icons
282  $path = ilObject::_getIcon($a_obj_id, "small", "wsrt");
283 
284  $tpl->setCurrentBlock("icon");
285  $title = $this->tree->getNodeData($this->root_id);
286  $title = $title["title"];
287  if(!$title)
288  {
289  $title = $lng->txt("personal_workspace");
290  }
291 
292  $tpl->setVariable("ICON_IMAGE", $path);
293  $tpl->setVariable("TXT_ALT_IMG", $title);
294  $tpl->parseCurrentBlock();
295 
296  if(strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type'])))
297  {
298  $tpl->setCurrentBlock('check');
299  $tpl->setVariable('OBJ_CHECK', $formItem);
300  $tpl->parseCurrentBlock();
301  }
302 
303  $tpl->setVariable('OBJ_TITLE', $title);
304  }
305 
306  function setTypeClickable($a_type)
307  {
308  $this->clickable[] = $a_type;
309  }
310 
311  function setCustomLinkTarget($a_target)
312  {
313  $this->custom_link_target = $a_target;
314  }
315 
316  function buildLinkTarget($a_node_id, $a_type)
317  {
318  if(!$this->custom_link_target)
319  {
320  return parent::buildLinkTarget($a_node_id, $a_type);
321  }
322 
323  $link = $this->custom_link_target."&".$this->target_get."=".$a_node_id;
324  return $link;
325  }
326 }
327 ?>