ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
17  protected $lng;
18 
19  const SEL_TYPE_CHECK = 1;
20  const SEL_TYPE_RADIO = 2;
21 
22  public $root_id = 0;
23  public $output = '';
24  public $ctrl = null;
25  public $access = null;
26 
27  private $checked_items = array();
28  private $post_var = '';
29  private $form_items = array();
30  private $type = 0;
31 
32  protected $clickable = array();
34 
44  public function __construct($a_type, $a_target, $a_session_variable, ilWorkspaceTree $a_tree, ilWorkspaceAccessHandler $a_access_handler)
45  {
46  global $DIC;
47 
48  $this->lng = $DIC->language();
49  $ilCtrl = $DIC->ctrl();
50 
51  $this->ctrl = $ilCtrl;
52  $this->type = $a_type;
53  $this->access = $a_access_handler;
54 
55  parent::__construct($a_target);
56 
57  // #11173
58  if (!$a_tree->readRootId()) {
59  // create (workspace) root folder
60  $root = ilObjectFactory::getClassByType("wsrt");
61  $root = new $root(null);
62  $root->create();
63 
64  $root_id = $a_tree->createReference($root->getId());
65  $a_tree->addTree($a_tree->getTreeId(), $root_id);
66  $a_tree->setRootId($root_id);
67  }
68  $this->tree = $a_tree;
69  $this->root_id = $this->tree->readRootId();
70  $this->order_column = 'title';
71  $this->setSessionExpandVariable($a_session_variable);
72 
73  // reset filter
74  $this->filter = array();
75 
76  $this->addFilter('wsrt');
77  $this->addFilter('wfld');
78 
79  $this->addFormItemForType('wsrt');
80  $this->addFormItemForType('wfld');
81 
82  $this->setFiltered(true);
84  }
85 
86  public function showChilds($a_ref_id, $a_obj_id = 0)
87  {
88  if ($a_ref_id == 0 ||
89  $this->access->checkAccess('read', '', $a_ref_id)) {
90  return true;
91  }
92  return false;
93  }
94 
95  public function isVisible($a_ref_id, $a_type)
96  {
97  return true;
98  }
99 
100  public function sortNodes($a_nodes, $a_parent_obj_id)
101  {
102  return $a_nodes;
103  }
104 
105  public function isClickable($a_type, $a_ref_id = 0, $a_obj_id = 0)
106  {
107  if (is_array($this->clickable) && in_array($a_type, $this->clickable) &&
108  $a_ref_id) {
109  return true;
110  }
111  return false;
112  }
113 
114  public function addFormItemForType($type)
115  {
116  $this->form_items[$type] = true;
117  }
118  public function removeFormItemForType($type)
119  {
120  $this->form_items[$type] = false;
121  }
122  public function removeAllFormItemTypes()
123  {
124  $this->form_items = array();
125  }
126  public function setCheckedItems($a_checked_items = array())
127  {
128  $this->checked_items = $a_checked_items;
129  }
130  public function isItemChecked($a_id)
131  {
132  return in_array($a_id, $this->checked_items) ? true : false;
133  }
134  public function setPostVar($a_post_var)
135  {
136  $this->post_var = $a_post_var;
137  }
138  public function getPostVar()
139  {
140  return $this->post_var;
141  }
142 
143  public function buildFormItem($a_node_id, $a_type)
144  {
145  if (!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type]) {
146  return;
147  }
148 
149  switch ($this->type) {
150  case self::SEL_TYPE_CHECK:
151  return ilUtil::formCheckbox((int) $this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
152 
153  case self::SEL_TYPE_RADIO:
154  return ilUtil::formRadioButton((int) $this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
155  }
156  }
157 
158  public function formatObject($tpl, $a_node_id, $a_option, $a_obj_id = 0)
159  {
160  $lng = $this->lng;
161 
162  if (!isset($a_node_id) or !is_array($a_option)) {
163  require_once './Services/Exceptions/classes/class.ilException.php';
164  throw new ilException("Missing parameter or wrong datatype! " .
165  "node_id: " . $a_node_id . " options:" . var_dump($a_option));
166  }
167 
168  $pic = false;
169  foreach ($a_option["tab"] as $picture) {
170  if ($picture == 'plus') {
171  $tpl->setCurrentBlock("expander");
172  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
173  $target = $this->createTarget('+', $a_node_id);
174  $tpl->setVariable("LINK_NAME", $a_node_id);
175  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
176  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
177  $tpl->parseCurrentBlock();
178  $pic = true;
179  }
180 
181  if ($picture == 'minus' && $this->show_minus) {
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  $tpl->setCurrentBlock("blank");
195  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
196  $tpl->parseCurrentBlock();
197  }
198 
199  if ($this->output_icons) {
200  $tpl->setCurrentBlock("icon");
201  $tpl->setVariable("ICON_IMAGE", $this->getImage("icon_" . $a_option["type"] . ".svg", $a_option["type"], $a_obj_id));
202 
203  $tpl->setVariable("TARGET_ID", "iconid_" . $a_node_id);
204  $this->iconList[] = "iconid_" . $a_node_id;
205  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
206  $tpl->parseCurrentBlock();
207  }
208 
209  if (strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type']))) {
210  $tpl->setCurrentBlock('check');
211  $tpl->setVariable('OBJ_CHECK', $formItem);
212  $tpl->parseCurrentBlock();
213  }
214 
215  if ($this->isClickable($a_option["type"], $a_node_id, $a_obj_id)) { // output link
216  $tpl->setCurrentBlock("link");
217  //$target = (strpos($this->target, "?") === false) ?
218  // $this->target."?" : $this->target."&";
219  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
220  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
221 
222  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
223 
224  if ($style_class != "") {
225  $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
226  }
227 
228  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "") {
229  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
230  }
231 
232  $tpl->setVariable("LINK_NAME", $a_node_id);
233  $tpl->setVariable("TITLE", ilUtil::shortenText(
234  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
235  $this->textwidth,
236  true
237  ));
238  $tpl->setVariable("DESC", ilUtil::shortenText(
239  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]),
240  $this->textwidth,
241  true
242  ));
243  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
244  if ($frame_target != "") {
245  $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
246  }
247  $tpl->parseCurrentBlock();
248  } else { // output text only
249  $tpl->setCurrentBlock("text");
250  $tpl->setVariable("OBJ_TITLE", ilUtil::shortenText(
251  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
252  $this->textwidth,
253  true
254  ));
255  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
256  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]),
257  $this->textwidth,
258  true
259  ));
260  $tpl->parseCurrentBlock();
261  }
262 
263  $tpl->setCurrentBlock("list_item");
264  $tpl->parseCurrentBlock();
265  $tpl->touchBlock("element");
266  }
267 
268  /*
269  * overwritten method from base class
270  * @access public
271  * @param integer obj_id
272  * @param integer array options
273  * @return string
274  */
275  public function formatHeader($tpl, $a_obj_id, $a_option)
276  {
277  $lng = $this->lng;
278 
279  // custom icons
280  $path = ilObject::_getIcon($a_obj_id, "small", "wsrt");
281 
282  $tpl->setCurrentBlock("icon");
283  $title = $this->tree->getNodeData($this->root_id);
284  $title = $title["title"];
285  if (!$title) {
286  $title = $lng->txt("personal_workspace");
287  }
288 
289  $tpl->setVariable("ICON_IMAGE", $path);
290  $tpl->setVariable("TXT_ALT_IMG", $title);
291  $tpl->parseCurrentBlock();
292 
293  if (strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type']))) {
294  $tpl->setCurrentBlock('check');
295  $tpl->setVariable('OBJ_CHECK', $formItem);
296  $tpl->parseCurrentBlock();
297  }
298 
299  $tpl->setVariable('OBJ_TITLE', $title);
300  }
301 
302  public function setTypeClickable($a_type)
303  {
304  $this->clickable[] = $a_type;
305  }
306 
307  public function setCustomLinkTarget($a_target)
308  {
309  $this->custom_link_target = $a_target;
310  }
311 
312  public function buildLinkTarget($a_node_id, $a_type)
313  {
314  if (!$this->custom_link_target) {
315  return parent::buildLinkTarget($a_node_id, $a_type);
316  }
317 
318  $link = $this->custom_link_target . "&" . $this->target_get . "=" . $a_node_id;
319  return $link;
320  }
321 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static getClassByType($a_obj_type)
Get class by type.
sortNodes($a_nodes, $a_parent_obj_id)
formatObject($tpl, $a_node_id, $a_option, $a_obj_id=0)
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
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)
global $DIC
Definition: saml.php:7
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.
const IL_FM_POSITIVE
Tree handler for personal workspace.
setFiltered($a_bool)
active/deactivate the filter public
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:92
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)
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