ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPasteIntoMultipleItemsExplorer.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 * ilPasteIntoMultipleItemsExplorer Explorer
8 *
9 * @author Michael Jansen <mjansen@databay.de>
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 
21  private $checked_items = array();
22  private $post_var = '';
23  private $form_items = array();
24  private $form_item_permission = 'read';
25  private $type = 0;
26 
33  public function __construct($a_type, $a_target, $a_session_variable)
34  {
35  global $tree, $ilCtrl;
36 
37  $this->setId("cont_paste_explorer");
38 
39  $this->ctrl = $ilCtrl;
40  $this->type = $a_type;
41 
42  parent::__construct($a_target);
43  $this->tree = $tree;
44  $this->root_id = $this->tree->readRootId();
45  $this->order_column = 'title';
46  $this->setSessionExpandVariable($a_session_variable);
47 
48  // reset filter
49  $this->filter = array();
50 
51  $this->addFilter('root');
52  $this->addFilter('crs');
53  $this->addFilter('grp');
54  $this->addFilter('cat');
55  $this->addFilter('fold');
56 
57  $this->addFormItemForType('root');
58  $this->addFormItemForType('crs');
59  $this->addFormItemForType('grp');
60  $this->addFormItemForType('cat');
61  $this->addFormItemForType('fold');
62 
63  $this->setFiltered(true);
65  }
66 
67  public function isClickable($a_type, $a_ref_id, $a_obj_id = 0)
68  {
69  return false;
70  }
71 
72  public function addFormItemForType($type)
73  {
74  $this->form_items[$type] = true;
75  }
76  public function removeFormItemForType($type)
77  {
78  $this->form_items[$type] = false;
79  }
80  public function setCheckedItems($a_checked_items = array())
81  {
82  $this->checked_items = $a_checked_items;
83  }
84  public function isItemChecked($a_id)
85  {
86  return in_array($a_id, $this->checked_items) ? true : false;
87  }
88  public function setPostVar($a_post_var)
89  {
90  $this->post_var = $a_post_var;
91  }
92  public function getPostVar()
93  {
94  return $this->post_var;
95  }
96 
103  public function setRequiredFormItemPermission($a_form_item_permission)
104  {
105  $this->form_item_permission = $a_form_item_permission;
106  }
107 
113  {
115  }
116 
117  public function buildFormItem($a_node_id, $a_type)
118  {
119  // permission check
120  if(!$GLOBALS['ilAccess']->checkAccess($this->getRequiredFormItemPermission(),'',$a_node_id))
121  {
122  return '';
123  }
124 
125  if(
126  !array_key_exists($a_type, $this->form_items) ||
127  !$this->form_items[$a_type]
128  )
129  {
130  return '';
131  }
132  $disabled = false;
133  if(is_array($_SESSION["clipboard"]["ref_ids"]))
134  {
135  $disabled = in_array($a_node_id, $_SESSION["clipboard"]["ref_ids"]);
136  }
137  else if((int)$_SESSION["clipboard"]["ref_ids"])
138  {
139  $disabled = $a_node_id == $_SESSION["clipboard"]["ref_ids"];
140  }
141  else if($_SESSION["clipboard"]["cmd"] == 'copy' && $a_node_id == $_SESSION["clipboard"]["parent"])
142  {
143 
144  $disabled = true;
145  }
146 
147  switch($this->type)
148  {
149  case self::SEL_TYPE_CHECK:
150  return ilUtil::formCheckbox((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id, $disabled);
151  break;
152 
153  case self::SEL_TYPE_RADIO:
154  return ilUtil::formDisabledRadioButton((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id, $disabled);
155  break;
156  }
157  }
158 
159  function formatObject(&$tpl, $a_node_id, $a_option, $a_obj_id = 0)
160  {
161  global $lng;
162 
163  if (!isset($a_node_id) or !is_array($a_option))
164  {
165  $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
166  "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
167  }
168 
169  $pic = false;
170  foreach ($a_option["tab"] as $picture)
171  {
172  if ($picture == 'plus')
173  {
174  $tpl->setCurrentBlock("exp_desc");
175  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
176  $tpl->parseCurrentBlock();
177  $target = $this->createTarget('+',$a_node_id);
178  $tpl->setCurrentBlock("expander");
179  $tpl->setVariable("LINK_NAME", $a_node_id);
180  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
181  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
182  $tpl->parseCurrentBlock();
183  $pic = true;
184  }
185 
186  if ($picture == 'minus' && $this->show_minus)
187  {
188  $tpl->setCurrentBlock("exp_desc");
189  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
190  $tpl->parseCurrentBlock();
191  $target = $this->createTarget('-',$a_node_id);
192  $tpl->setCurrentBlock("expander");
193  $tpl->setVariable("LINK_NAME", $a_node_id);
194  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
195  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
196  $tpl->parseCurrentBlock();
197  $pic = true;
198  }
199  }
200 
201  if (!$pic)
202  {
203  $tpl->setCurrentBlock("blank");
204  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
205  $tpl->parseCurrentBlock();
206  }
207 
208  if ($this->output_icons)
209  {
210  $tpl->setCurrentBlock("icon");
211 
212  $path = ilObject::_getIcon($a_obj_id, "tiny", $a_option["type"]);
213  $tpl->setVariable("ICON_IMAGE", $path);
214 
215  $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
216  $this->iconList[] = "iconid_".$a_node_id;
217  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
218  $tpl->parseCurrentBlock();
219  }
220 
221  if(strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type'])))
222  {
223  $tpl->setCurrentBlock('check');
224  $tpl->setVariable('OBJ_CHECK', $formItem);
225  $tpl->parseCurrentBlock();
226  }
227 
228  if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id)) // output link
229  {
230  $tpl->setCurrentBlock("link");
231  //$target = (strpos($this->target, "?") === false) ?
232  // $this->target."?" : $this->target."&";
233  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
234  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
235 
236  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
237 
238  if ($style_class != "")
239  {
240  $tpl->setVariable("A_CLASS", ' class="'.$style_class.'" ' );
241  }
242 
243  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
244  {
245  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
246  }
247 
248  $tpl->setVariable("LINK_NAME", $a_node_id);
249  $tpl->setVariable("TITLE", $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]));
250  $tpl->setVariable("DESC", ilUtil::shortenText(
251  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]), $this->textwidth, true));
252  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
253  if ($frame_target != "")
254  {
255  $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
256  }
257  $tpl->parseCurrentBlock();
258  }
259  else // output text only
260  {
261  $obj_title = $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]);
262 
263  // highlight current node
264  if($a_node_id == $this->highlighted)
265  {
266  $obj_title = "<span class=\"ilHighlighted\">".$obj_title."</span>";
267  }
268 
269  $tpl->setCurrentBlock("text");
270  $tpl->setVariable("OBJ_TITLE", $obj_title);
271  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
272  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]), $this->textwidth, true));
273  $tpl->parseCurrentBlock();
274  }
275 
276  $tpl->setCurrentBlock("list_item");
277  $tpl->parseCurrentBlock();
278  $tpl->touchBlock("element");
279  }
280 
281  /*
282  * overwritten method from base class
283  * @access public
284  * @param integer obj_id
285  * @param integer array options
286  * @return string
287  */
288  function formatHeader(&$tpl, $a_obj_id,$a_option)
289  {
290  global $lng, $ilias, $tree;
291 
292  // custom icons
293  $path = ilObject::_getIcon($a_obj_id, "tiny", "root");
294 
295 
296  $tpl->setCurrentBlock("icon");
297  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
298  $title = $nd["title"];
299  if ($title == "ILIAS")
300  {
301  $title = $lng->txt("repository");
302  }
303 
304  $tpl->setVariable("ICON_IMAGE", $path);
305  $tpl->setVariable("TXT_ALT_IMG", $title);
306  $tpl->parseCurrentBlock();
307 
308  if(strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type'])))
309  {
310  $tpl->setCurrentBlock('check');
311  $tpl->setVariable('OBJ_CHECK', $formItem);
312  $tpl->parseCurrentBlock();
313  }
314 
315  $tpl->setVariable('OBJ_TITLE', $title);
316  }
317 
318  function showChilds($a_ref_id,$a_obj_id = 0)
319  {
320  global $ilAccess;
321 
322  if ($a_ref_id == 0)
323  {
324  return true;
325  }
326  // #11778 - ilAccessHandler::doConditionCheck()
327  if ($ilAccess->checkAccess("read", "", $a_ref_id))
328  {
329  return true;
330  }
331  else
332  {
333  return false;
334  }
335  }
336 
337  // overwrite this due to bug 12896
338  function isVisible($a_ref_id,$a_type)
339  {
340  global $ilAccess;
341 
342  if(!$ilAccess->checkAccess('visible', '', $a_ref_id))
343  {
344  return false;
345  }
346  return true;
347  }
348 
349 }
350 
351 ?>