ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 = 0, $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("expander");
151  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
152  $target = $this->createTarget('+',$a_node_id);
153  $tpl->setVariable("LINK_NAME", $a_node_id);
154  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
155  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
156  $tpl->parseCurrentBlock();
157  $pic = true;
158  }
159 
160  if ($picture == 'minus' && $this->show_minus)
161  {
162  $tpl->setCurrentBlock("expander");
163  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
164  $target = $this->createTarget('-',$a_node_id);
165  $tpl->setVariable("LINK_NAME", $a_node_id);
166  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
167  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
168  $tpl->parseCurrentBlock();
169  $pic = true;
170  }
171  }
172 
173  if (!$pic)
174  {
175  $tpl->setCurrentBlock("blank");
176  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
177  $tpl->parseCurrentBlock();
178  }
179 
180  if ($this->output_icons)
181  {
182  $tpl->setCurrentBlock("icon");
183  $tpl->setVariable("ICON_IMAGE" , $this->getImage("icon_".$a_option["type"].".svg", $a_option["type"], $a_obj_id));
184 
185  $tpl->setVariable("TARGET_ID" , "iconid_".$a_node_id);
186  $this->iconList[] = "iconid_".$a_node_id;
187  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
188  $tpl->parseCurrentBlock();
189  }
190 
191  if(strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type'])))
192  {
193  $tpl->setCurrentBlock('check');
194  $tpl->setVariable('OBJ_CHECK', $formItem);
195  $tpl->parseCurrentBlock();
196  }
197 
198  if ($this->isClickable($a_option["type"], $a_node_id,$a_obj_id)) // output link
199  {
200  $tpl->setCurrentBlock("link");
201  //$target = (strpos($this->target, "?") === false) ?
202  // $this->target."?" : $this->target."&";
203  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
204  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
205 
206  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
207 
208  if ($style_class != "")
209  {
210  $tpl->setVariable("A_CLASS", ' class="'.$style_class.'" ' );
211  }
212 
213  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "")
214  {
215  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
216  }
217 
218  $tpl->setVariable("LINK_NAME", $a_node_id);
219  $tpl->setVariable("TITLE",
220  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
221  );
222  $tpl->setVariable("DESC", ilUtil::shortenText(
223  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]), $this->textwidth, true));
224  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
225  if ($frame_target != "")
226  {
227  $tpl->setVariable("TARGET", " target=\"".$frame_target."\"");
228  }
229  $tpl->parseCurrentBlock();
230  }
231  else // output text only
232  {
233  $tpl->setCurrentBlock("text");
234  $tpl->setVariable("OBJ_TITLE",
235  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]));
236  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
237  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]), $this->textwidth, true));
238  $tpl->parseCurrentBlock();
239  }
240 
241  $tpl->setCurrentBlock("list_item");
242  $tpl->parseCurrentBlock();
243  $tpl->touchBlock("element");
244  }
245 
246 
247 
248  /*
249  * overwritten method from base class
250  * @access public
251  * @param integer obj_id
252  * @param integer array options
253  * @return string
254  */
255  function formatHeader($tpl, $a_obj_id,$a_option)
256  {
257  global $lng, $ilias, $tree;
258 
259  // custom icons
260  $path = ilObject::_getIcon($a_obj_id, "tiny", "root");
261 
262 
263  $tpl->setCurrentBlock("icon");
264  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
265  $title = $nd["title"];
266  if ($title == "ILIAS")
267  {
268  $title = $lng->txt("repository");
269  }
270 
271  $tpl->setVariable("ICON_IMAGE", $path);
272  $tpl->setVariable("TXT_ALT_IMG", $title);
273  $tpl->parseCurrentBlock();
274 
275  if(strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type'])))
276  {
277  $tpl->setCurrentBlock('check');
278  $tpl->setVariable('OBJ_CHECK', $formItem);
279  $tpl->parseCurrentBlock();
280  }
281 
282  if($this->isMapped(ROOT_FOLDER_ID))
283  {
284  $tpl->setVariable(
285  'OBJ_TITLE',
286  '<font style="font-weight: bold">'.$title.'</font>'
287  );
288  }
289  else
290  {
291  $tpl->setVariable('OBJ_TITLE',$title);
292  }
293  }
294 
302  public function buildTitle($title, $a_obj_id, $a_type)
303  {
304  if($this->isMapped($a_obj_id))
305  {
306  return '<font style="font-weight: bold">'.$title.'</font>';
307  }
308  if($this->hasParentMapping($a_obj_id))
309  {
310  return '<font style="font-style: italic">'.$title.'</font>';
311  }
312  return $title;
313  }
314 
318  protected function initMappings()
319  {
320  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
321  $mappings = array();
322  foreach(ilECSCourseMappingRule::getRuleRefIds($this->getSid(), $this->getMid()) as $ref_id)
323  {
324  $mappings[$ref_id] = array();
325  }
326 
327  foreach($mappings as $ref_id => $tmp)
328  {
329  $this->mappings[$ref_id] = $GLOBALS['tree']->getPathId($ref_id,1);
330  }
331  return true;
332  }
333 
334  protected function isMapped($a_ref_id)
335  {
336  return array_key_exists($a_ref_id, $this->mappings);
337  }
338 
339  protected function hasParentMapping($a_ref_id)
340  {
341  foreach($this->mappings as $ref_id => $parent_nodes)
342  {
343  if(in_array($a_ref_id, $parent_nodes))
344  {
345  return true;
346  }
347  }
348  return false;
349  }
350 }
351 ?>
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
$path
Definition: aliased.php:25
buildFrameTarget($a_type, $a_child=0, $a_obj_id=0)
get frame target (may be overwritten by derived classes)
setFilterMode($a_mode=IL_FM_NEGATIVE)
set filter mode
getNodeStyleClass($a_id, $a_type)
get style class for node
buildLinkTarget($a_node_id, $a_type)
get link target (may be overwritten by derived classes)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
const IL_FM_POSITIVE
formatObject($tpl, $a_node_id, $a_option, $a_obj_id=0)
setOrderColumn($a_column)
set the order column public
setFiltered($a_bool)
active/deactivate the filter public
global $tpl
Definition: ilias.php:8
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:93
$nd
Definition: error.php:11
redirection script todo: (a better solution should control the processing via a xml file) ...
buildTitle($title, $a_obj_id, $a_type)
Format title (bold for direct mappings, italic for child mappings)
static getRuleRefIds($a_sid, $a_mid)
Create styles array
The data for the language used.
setRoot($a_root_id)
Set root node.
static formRadioButton($checked, $varname, $value, $onclick=null, $disabled=false)
??? public
Class ilExplorer class for explorer view in admin frame.
getImage($a_name, $a_type="", $a_obj_id="")
get image path (may be overwritten by derived classes)
isClickable($a_type, $a_ref_id=0, $a_obj_id=0)
no item is clickable
$ref_id
Definition: sahs_server.php:39
global $lng
Definition: privfeed.php:17
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