ILIAS  eassessment Revision 61809
 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 $type = 0;
25 
32  public function __construct($a_type, $a_target, $a_session_variable)
33  {
34  global $tree, $ilCtrl;
35 
36  $this->ctrl = $ilCtrl;
37  $this->type = $a_type;
38 
39  parent::__construct($a_target);
40  $this->tree = $tree;
41  $this->root_id = $this->tree->readRootId();
42  $this->order_column = 'title';
43  $this->setSessionExpandVariable($a_session_variable);
44 
45  // reset filter
46  $this->filter = array();
47 
48  $this->addFilter('root');
49  $this->addFilter('crs');
50  $this->addFilter('grp');
51  $this->addFilter('cat');
52  $this->addFilter('fold');
53 
54  $this->addFormItemForType('root');
55  $this->addFormItemForType('crs');
56  $this->addFormItemForType('grp');
57  $this->addFormItemForType('cat');
58  $this->addFormItemForType('fold');
59 
60  $this->setFiltered(true);
62  }
63 
64  public function isClickable($a_type, $a_ref_id, $a_obj_id = 0)
65  {
66  return false;
67  }
68 
69  public function addFormItemForType($type)
70  {
71  $this->form_items[$type] = true;
72  }
73  public function removeFormItemForType($type)
74  {
75  $this->form_items[$type] = false;
76  }
77  public function setCheckedItems($a_checked_items = array())
78  {
79  $this->checked_items = $a_checked_items;
80  }
81  public function isItemChecked($a_id)
82  {
83  return in_array($a_id, $this->checked_items) ? true : false;
84  }
85  public function setPostVar($a_post_var)
86  {
87  $this->post_var = $a_post_var;
88  }
89  public function getPostVar()
90  {
91  return $this->post_var;
92  }
93 
94  public function buildFormItem($a_node_id, $a_type)
95  {
96  if(!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type]) return '';
97 
98  switch($this->type)
99  {
100  case self::SEL_TYPE_CHECK:
101  return ilUtil::formCheckbox((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
102  break;
103 
104  case self::SEL_TYPE_RADIO:
105  return ilUtil::formRadioButton((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
106  break;
107  }
108  }
109 
110  function formatObject(&$tpl, $a_node_id, $a_option, $a_obj_id = 0)
111  {
112  global $lng;
113 
114  if (!isset($a_node_id) or !is_array($a_option))
115  {
116  $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
117  "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
118  }
119 
120  $pic = false;
121  foreach ($a_option["tab"] as $picture)
122  {
123  if ($picture == 'plus')
124  {
125  $tpl->setCurrentBlock("exp_desc");
126  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
127  $tpl->parseCurrentBlock();
128  $target = $this->createTarget('+',$a_node_id);
129  $tpl->setCurrentBlock("expander");
130  $tpl->setVariable("LINK_NAME", $a_node_id);
131  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
132  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.gif"));
133  $tpl->parseCurrentBlock();
134  $pic = true;
135  }
136 
137  if ($picture == 'minus' && $this->show_minus)
138  {
139  $tpl->setCurrentBlock("exp_desc");
140  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
141  $tpl->parseCurrentBlock();
142  $target = $this->createTarget('-',$a_node_id);
143  $tpl->setCurrentBlock("expander");
144  $tpl->setVariable("LINK_NAME", $a_node_id);
145  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
146  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.gif"));
147  $tpl->parseCurrentBlock();
148  $pic = true;
149  }
150  }
151 
152  if (!$pic)
153  {
154  $tpl->setCurrentBlock("blank");
155  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.gif"));
156  $tpl->parseCurrentBlock();
157  }
158 
159  if ($this->output_icons)
160  {
161  $tpl->setCurrentBlock("icon");
162  $tpl->setVariable("ICON_IMAGE" , $this->getImage("icon_".$a_option["type"].".gif", $a_option["type"], $a_obj_id));
163 
164  $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
165  $this->iconList[] = "iconid_".$a_node_id;
166  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
167  $tpl->parseCurrentBlock();
168  }
169 
170  if(strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type'])))
171  {
172  $tpl->setCurrentBlock('check');
173  $tpl->setVariable('OBJ_CHECK', $formItem);
174  $tpl->parseCurrentBlock();
175  }
176 
177  if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id)) // output link
178  {
179  $tpl->setCurrentBlock("link");
180  //$target = (strpos($this->target, "?") === false) ?
181  // $this->target."?" : $this->target."&";
182  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
183  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
184 
185  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
186 
187  if ($style_class != "")
188  {
189  $tpl->setVariable("A_CLASS", ' class="'.$style_class.'" ' );
190  }
191 
192  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
193  {
194  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
195  }
196 
197  $tpl->setVariable("LINK_NAME", $a_node_id);
198  $tpl->setVariable("TITLE", ilUtil::shortenText(
199  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
200  $this->textwidth, true));
201  $tpl->setVariable("DESC", ilUtil::shortenText(
202  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]), $this->textwidth, true));
203  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
204  if ($frame_target != "")
205  {
206  $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
207  }
208  $tpl->parseCurrentBlock();
209  }
210  else // output text only
211  {
212  $tpl->setCurrentBlock("text");
213  $tpl->setVariable("OBJ_TITLE", ilUtil::shortenText(
214  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]), $this->textwidth, true));
215  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
216  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]), $this->textwidth, true));
217  $tpl->parseCurrentBlock();
218  }
219 
220  $tpl->setCurrentBlock("list_item");
221  $tpl->parseCurrentBlock();
222  $tpl->touchBlock("element");
223  }
224 
225  /*
226  * overwritten method from base class
227  * @access public
228  * @param integer obj_id
229  * @param integer array options
230  * @return string
231  */
232  function formatHeader(&$tpl, $a_obj_id,$a_option)
233  {
234  global $lng, $ilias, $tree;
235 
236  // custom icons
237  $path = ilObject::_getIcon($a_obj_id, "small", "root");
238 
239 
240  $tpl->setCurrentBlock("icon");
241  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
242  $title = $nd["title"];
243  if ($title == "ILIAS")
244  {
245  $title = $lng->txt("repository");
246  }
247 
248  $tpl->setVariable("ICON_IMAGE", $path);
249  $tpl->setVariable("TXT_ALT_IMG", $title);
250  $tpl->parseCurrentBlock();
251 
252  if(strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type'])))
253  {
254  $tpl->setCurrentBlock('check');
255  $tpl->setVariable('OBJ_CHECK', $formItem);
256  $tpl->parseCurrentBlock();
257  }
258 
259  $tpl->setVariable('OBJ_TITLE', $title);
260  }
261 }
262 ?>