ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
17  protected $lng;
18 
22  protected $error;
23 
27  protected $access;
28 
29  const SEL_TYPE_CHECK = 1;
30  const SEL_TYPE_RADIO = 2;
31 
32  public $root_id = 0;
33  public $output = '';
34  public $ctrl = null;
35 
36  private $checked_items = array();
37  private $post_var = '';
38  private $form_items = array();
39  private $form_item_permission = 'read';
40  private $type = 0;
41 
48  public function __construct($a_type, $a_target, $a_session_variable)
49  {
50  global $DIC;
51 
52  $this->lng = $DIC->language();
53  $this->error = $DIC["ilErr"];
54  $this->access = $DIC->access();
55  $tree = $DIC->repositoryTree();
56  $ilCtrl = $DIC->ctrl();
57 
58  $this->setId("cont_paste_explorer");
59 
60  $this->ctrl = $ilCtrl;
61  $this->type = $a_type;
62 
63  parent::__construct($a_target);
64  $this->tree = $tree;
65  $this->root_id = $this->tree->readRootId();
66  $this->order_column = 'title';
67  $this->setSessionExpandVariable($a_session_variable);
68 
69  // reset filter
70  $this->filter = array();
71 
72  $this->addFilter('root');
73  $this->addFilter('crs');
74  $this->addFilter('grp');
75  $this->addFilter('cat');
76  $this->addFilter('fold');
77 
78  $this->addFormItemForType('root');
79  $this->addFormItemForType('crs');
80  $this->addFormItemForType('grp');
81  $this->addFormItemForType('cat');
82  $this->addFormItemForType('fold');
83 
84  $this->setFiltered(true);
86  }
87 
88  public function isClickable($a_type, $a_ref_id = 0, $a_obj_id = 0)
89  {
90  return false;
91  }
92 
93  public function addFormItemForType($type)
94  {
95  $this->form_items[$type] = true;
96  }
97  public function removeFormItemForType($type)
98  {
99  $this->form_items[$type] = false;
100  }
101  public function setCheckedItems($a_checked_items = array())
102  {
103  $this->checked_items = $a_checked_items;
104  }
105  public function isItemChecked($a_id)
106  {
107  return in_array($a_id, $this->checked_items) ? true : false;
108  }
109  public function setPostVar($a_post_var)
110  {
111  $this->post_var = $a_post_var;
112  }
113  public function getPostVar()
114  {
115  return $this->post_var;
116  }
117 
124  public function setRequiredFormItemPermission($a_form_item_permission)
125  {
126  $this->form_item_permission = $a_form_item_permission;
127  }
128 
134  {
136  }
137 
138  public function buildFormItem($a_node_id, $a_type)
139  {
140  // permission check
141  if (!$GLOBALS['ilAccess']->checkAccess($this->getRequiredFormItemPermission(), '', $a_node_id)) {
142  return '';
143  }
144 
145  if (
146  !array_key_exists($a_type, $this->form_items) ||
147  !$this->form_items[$a_type]
148  ) {
149  return '';
150  }
151 
152  $disabled = false;
153  if (is_array($_SESSION["clipboard"]["ref_ids"])) {
154  $disabled = in_array($a_node_id, $_SESSION["clipboard"]["ref_ids"]);
155  } elseif ((int) $_SESSION["clipboard"]["ref_ids"]) {
156  $disabled = $a_node_id == $_SESSION["clipboard"]["ref_ids"];
157  } elseif ($_SESSION["clipboard"]["cmd"] == 'copy' && $a_node_id == $_SESSION["clipboard"]["parent"]) {
158  $disabled = true;
159  }
160 
161  switch ($this->type) {
162  case self::SEL_TYPE_CHECK:
163  return ilUtil::formCheckbox((int) $this->isItemChecked($a_node_id), $this->post_var, $a_node_id, $disabled);
164  break;
165 
166  case self::SEL_TYPE_RADIO:
167  return ilUtil::formRadioButton((int) $this->isItemChecked($a_node_id), $this->post_var, $a_node_id, '', $disabled);
168  break;
169  }
170  }
171 
172  public function formatObject($tpl, $a_node_id, $a_option, $a_obj_id = 0)
173  {
174  $lng = $this->lng;
176 
177  if (!isset($a_node_id) or !is_array($a_option)) {
178  $ilErr->raiseError(get_class($this) . "::formatObject(): Missing parameter or wrong datatype! " .
179  "node_id: " . $a_node_id . " options:" . var_dump($a_option), $ilErr->WARNING);
180  }
181 
182  $pic = false;
183  foreach ($a_option["tab"] as $picture) {
184  if ($picture == 'plus') {
185  $tpl->setCurrentBlock("expander");
186  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
187  $target = $this->createTarget('+', $a_node_id);
188  $tpl->setVariable("LINK_NAME", $a_node_id);
189  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
190  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
191  $tpl->parseCurrentBlock();
192  $pic = true;
193  }
194 
195  if ($picture == 'minus' && $this->show_minus) {
196  $tpl->setCurrentBlock("expander");
197  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
198  $target = $this->createTarget('-', $a_node_id);
199  $tpl->setVariable("LINK_NAME", $a_node_id);
200  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
201  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
202  $tpl->parseCurrentBlock();
203  $pic = true;
204  }
205  }
206 
207  if (!$pic) {
208  $tpl->setCurrentBlock("blank");
209  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
210  $tpl->parseCurrentBlock();
211  }
212 
213  if ($this->output_icons) {
214  $tpl->setCurrentBlock("icon");
215 
216  $path = ilObject::_getIcon($a_obj_id, "tiny", $a_option["type"]);
217  $tpl->setVariable("ICON_IMAGE", $path);
218 
219  $tpl->setVariable("TARGET_ID", "iconid_" . $a_node_id);
220  $this->iconList[] = "iconid_" . $a_node_id;
221  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
222  $tpl->parseCurrentBlock();
223  }
224 
225  if (strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type']))) {
226  $tpl->setCurrentBlock('check');
227  $tpl->setVariable('OBJ_CHECK', $formItem);
228  $tpl->parseCurrentBlock();
229  }
230 
231  if ($this->isClickable($a_option["type"], $a_node_id, $a_obj_id)) { // output link
232  $tpl->setCurrentBlock("link");
233  //$target = (strpos($this->target, "?") === false) ?
234  // $this->target."?" : $this->target."&";
235  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
236  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
237 
238  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
239 
240  if ($style_class != "") {
241  $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
242  }
243 
244  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "") {
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"]),
252  $this->textwidth,
253  true
254  ));
255  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
256  if ($frame_target != "") {
257  $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
258  }
259  $tpl->parseCurrentBlock();
260  } else { // output text only
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  $obj_title = "<span class=\"ilHighlighted\">" . $obj_title . "</span>";
266  }
267 
268  $tpl->setCurrentBlock("text");
269  $tpl->setVariable("OBJ_TITLE", $obj_title);
270  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
271  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]),
272  $this->textwidth,
273  true
274  ));
275  $tpl->parseCurrentBlock();
276  }
277 
278  $tpl->setCurrentBlock("list_item");
279  $tpl->parseCurrentBlock();
280  $tpl->touchBlock("element");
281  }
282 
283  /*
284  * overwritten method from base class
285  * @access public
286  * @param integer obj_id
287  * @param integer array options
288  * @return string
289  */
290  public function formatHeader($tpl, $a_obj_id, $a_option)
291  {
292  $lng = $this->lng;
293  $tree = $this->tree;
294 
295  // custom icons
296  $path = ilObject::_getIcon($a_obj_id, "tiny", "root");
297 
298 
299  $tpl->setCurrentBlock("icon");
300  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
301  $title = $nd["title"];
302  if ($title == "ILIAS") {
303  $title = $lng->txt("repository");
304  }
305 
306  $tpl->setVariable("ICON_IMAGE", $path);
307  $tpl->setVariable("TXT_ALT_IMG", $title);
308  $tpl->parseCurrentBlock();
309 
310  if (strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type']))) {
311  $tpl->setCurrentBlock('check');
312  $tpl->setVariable('OBJ_CHECK', $formItem);
313  $tpl->parseCurrentBlock();
314  }
315 
316  $tpl->setVariable('OBJ_TITLE', $title);
317  }
318 
319  public function showChilds($a_ref_id, $a_obj_id = 0)
320  {
321  $ilAccess = $this->access;
322 
323  if ($a_ref_id == 0) {
324  return true;
325  }
326  // #11778 - ilAccessHandler::doConditionCheck()
327  if ($ilAccess->checkAccess("read", "", $a_ref_id)) {
328  return true;
329  } else {
330  return false;
331  }
332  }
333 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
global $ilErr
Definition: raiseError.php:16
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
$_SESSION["AccountId"]
buildLinkTarget($a_node_id, $a_type)
note: most of this stuff is used by ilCourseContentInterface too
setId($a_val)
Set id.
global $DIC
Definition: saml.php:7
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const IL_FM_POSITIVE
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
__construct($a_type, $a_target, $a_session_variable)
Constructor public.
$nd
Definition: error.php:10
getImage($a_name, $a_type="", $a_obj_id="")
get image path
formatObject($tpl, $a_node_id, $a_option, $a_obj_id=0)
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
setRequiredFormItemPermission($a_form_item_permission)
Set required perission for form item visibility.
setSessionExpandVariable($a_var_name="expand")
set name of expand session variable
addFilter($a_item)
adds item to the filter public
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