ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSNodeMappingLocalExplorer.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 include_once './Services/UIComponent/Explorer/classes/class.ilExplorer.php';
5 
13 {
14  const SEL_TYPE_CHECK = 1;
15  const SEL_TYPE_RADIO = 2;
16 
17  private $checked_items = array();
18  private $post_var = '';
19  private $form_items = array();
20  private $type = 0;
21 
22  private $sid = 0;
23  private $mid = 0;
24 
25  private $mappings = array();
26 
27  public function __construct($a_target, $a_sid, $a_mid)
28  {
29  global $tree;
30 
31  parent::__construct($a_target);
32 
33  $this->sid = $a_sid;
34  $this->mid = $a_mid;
35 
36  $this->type = self::SEL_TYPE_RADIO;
37 
38  $this->tree = $tree;
39  $this->setRoot($tree->readRootId());
40  $this->setOrderColumn('title');
41 
42 
43  // reset filter
44  $this->filter = array();
45 
46  $this->addFilter('root');
47  $this->addFilter('cat');
48 
49  $this->addFormItemForType('root');
50  $this->addFormItemForType('cat');
51 
52  $this->setFiltered(true);
54 
55  $this->initMappings();
56 
57  }
58 
59  public function getSid()
60  {
61  return $this->sid;
62  }
63 
64  public function getMid()
65  {
66  return $this->mid;
67  }
68 
76  public function isClickable($a_type, $a_ref_id, $a_obj_id = 0)
77  {
78  return false;
79  }
80 
85  public function addFormItemForType($type)
86  {
87  $this->form_items[$type] = true;
88  }
89 
90  public function removeFormItemForType($type)
91  {
92  $this->form_items[$type] = false;
93  }
94 
95  public function setCheckedItems($a_checked_items = array())
96  {
97  $this->checked_items = $a_checked_items;
98  }
99 
100  public function getCheckedItems()
101  {
102  return (array) $this->checked_items;
103  }
104 
105  public function isItemChecked($a_id)
106  {
107  return in_array($a_id, $this->checked_items) ? true : false;
108  }
109 
110  public function setPostVar($a_post_var)
111  {
112  $this->post_var = $a_post_var;
113  }
114  public function getPostVar()
115  {
116  return $this->post_var;
117  }
118 
119  public function buildFormItem($a_node_id, $a_type)
120  {
121  if(!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type]) return '';
122 
123  switch($this->type)
124  {
125  case self::SEL_TYPE_CHECK:
126  return ilUtil::formCheckbox((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
127  break;
128 
129  case self::SEL_TYPE_RADIO:
130  return ilUtil::formRadioButton((int)$this->isItemChecked($a_node_id), $this->post_var, $a_node_id,"document.getElementById('map').submit(); return false;");
131  break;
132  }
133  }
134 
135  function formatObject(&$tpl, $a_node_id, $a_option, $a_obj_id = 0)
136  {
137  global $lng;
138 
139  if (!isset($a_node_id) or !is_array($a_option))
140  {
141  $this->ilias->raiseError(get_class($this)."::formatObject(): Missing parameter or wrong datatype! ".
142  "node_id: ".$a_node_id." options:".var_dump($a_option),$this->ilias->error_obj->WARNING);
143  }
144 
145  $pic = false;
146  foreach ($a_option["tab"] as $picture)
147  {
148  if ($picture == 'plus')
149  {
150  $tpl->setCurrentBlock("exp_desc");
151  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
152  $tpl->parseCurrentBlock();
153  $target = $this->createTarget('+',$a_node_id);
154  $tpl->setCurrentBlock("expander");
155  $tpl->setVariable("LINK_NAME", $a_node_id);
156  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
157  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
158  $tpl->parseCurrentBlock();
159  $pic = true;
160  }
161 
162  if ($picture == 'minus' && $this->show_minus)
163  {
164  $tpl->setCurrentBlock("exp_desc");
165  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
166  $tpl->parseCurrentBlock();
167  $target = $this->createTarget('-',$a_node_id);
168  $tpl->setCurrentBlock("expander");
169  $tpl->setVariable("LINK_NAME", $a_node_id);
170  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
171  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
172  $tpl->parseCurrentBlock();
173  $pic = true;
174  }
175  }
176 
177  if (!$pic)
178  {
179  $tpl->setCurrentBlock("blank");
180  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
181  $tpl->parseCurrentBlock();
182  }
183 
184  if ($this->output_icons)
185  {
186  $tpl->setCurrentBlock("icon");
187  $tpl->setVariable("ICON_IMAGE" , $this->getImage("icon_".$a_option["type"]."_s.png", $a_option["type"], $a_obj_id));
188 
189  $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
190  $this->iconList[] = "iconid_".$a_node_id;
191  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
192  $tpl->parseCurrentBlock();
193  }
194 
195  if(strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type'])))
196  {
197  $tpl->setCurrentBlock('check');
198  $tpl->setVariable('OBJ_CHECK', $formItem);
199  $tpl->parseCurrentBlock();
200  }
201 
202  if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id)) // output link
203  {
204  $tpl->setCurrentBlock("link");
205  //$target = (strpos($this->target, "?") === false) ?
206  // $this->target."?" : $this->target."&";
207  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
208  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
209 
210  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
211 
212  if ($style_class != "")
213  {
214  $tpl->setVariable("A_CLASS", ' class="'.$style_class.'" ' );
215  }
216 
217  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
218  {
219  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
220  }
221 
222  $tpl->setVariable("LINK_NAME", $a_node_id);
223  $tpl->setVariable("TITLE",
224  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
225  );
226  $tpl->setVariable("DESC", ilUtil::shortenText(
227  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]), $this->textwidth, true));
228  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
229  if ($frame_target != "")
230  {
231  $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
232  }
233  $tpl->parseCurrentBlock();
234  }
235  else // output text only
236  {
237  $tpl->setCurrentBlock("text");
238  $tpl->setVariable("OBJ_TITLE",
239  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]));
240  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
241  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]), $this->textwidth, true));
242  $tpl->parseCurrentBlock();
243  }
244 
245  $tpl->setCurrentBlock("list_item");
246  $tpl->parseCurrentBlock();
247  $tpl->touchBlock("element");
248  }
249 
250 
251 
252  /*
253  * overwritten method from base class
254  * @access public
255  * @param integer obj_id
256  * @param integer array options
257  * @return string
258  */
259  function formatHeader(&$tpl, $a_obj_id,$a_option)
260  {
261  global $lng, $ilias, $tree;
262 
263  // custom icons
264  $path = ilObject::_getIcon($a_obj_id, "tiny", "root");
265 
266 
267  $tpl->setCurrentBlock("icon");
268  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
269  $title = $nd["title"];
270  if ($title == "ILIAS")
271  {
272  $title = $lng->txt("repository");
273  }
274 
275  $tpl->setVariable("ICON_IMAGE", $path);
276  $tpl->setVariable("TXT_ALT_IMG", $title);
277  $tpl->parseCurrentBlock();
278 
279  if(strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type'])))
280  {
281  $tpl->setCurrentBlock('check');
282  $tpl->setVariable('OBJ_CHECK', $formItem);
283  $tpl->parseCurrentBlock();
284  }
285 
286  if($this->isMapped(ROOT_FOLDER_ID))
287  {
288  $tpl->setVariable(
289  'OBJ_TITLE',
290  '<font style="font-weight: bold">'.$title.'</font>'
291  );
292  }
293  else
294  {
295  $tpl->setVariable('OBJ_TITLE',$title);
296  }
297  }
298 
306  public function buildTitle($title, $a_obj_id, $a_type)
307  {
308  if($this->isMapped($a_obj_id))
309  {
310  return '<font style="font-weight: bold">'.$title.'</font>';
311  }
312  if($this->hasParentMapping($a_obj_id))
313  {
314  return '<font style="font-style: italic">'.$title.'</font>';
315  }
316  return $title;
317  }
318 
322  protected function initMappings()
323  {
324  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
325  $mappings = array();
326  foreach(ilECSCourseMappingRule::getRuleRefIds($this->getSid(), $this->getMid()) as $ref_id)
327  {
328  $mappings[$ref_id] = array();
329  }
330 
331  foreach($mappings as $ref_id => $tmp)
332  {
333  $this->mappings[$ref_id] = $GLOBALS['tree']->getPathId($ref_id,1);
334  }
335  return true;
336  }
337 
338  protected function isMapped($a_ref_id)
339  {
340  return array_key_exists($a_ref_id, $this->mappings);
341  }
342 
343  protected function hasParentMapping($a_ref_id)
344  {
345  foreach($this->mappings as $ref_id => $parent_nodes)
346  {
347  if(in_array($a_ref_id, $parent_nodes))
348  {
349  return true;
350  }
351  }
352  return false;
353  }
354 }
355 ?>