ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function getSid()
59  {
60  return $this->sid;
61  }
62 
63  public function getMid()
64  {
65  return $this->mid;
66  }
67 
75  public function isClickable($a_type, $a_ref_id = 0, $a_obj_id = 0)
76  {
77  return false;
78  }
79 
84  public function addFormItemForType($type)
85  {
86  $this->form_items[$type] = true;
87  }
88 
89  public function removeFormItemForType($type)
90  {
91  $this->form_items[$type] = false;
92  }
93 
94  public function setCheckedItems($a_checked_items = array())
95  {
96  $this->checked_items = $a_checked_items;
97  }
98 
99  public function getCheckedItems()
100  {
101  return (array) $this->checked_items;
102  }
103 
104  public function isItemChecked($a_id)
105  {
106  return in_array($a_id, $this->checked_items) ? true : false;
107  }
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 
118  public function buildFormItem($a_node_id, $a_type)
119  {
120  if (!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type]) {
121  return '';
122  }
123 
124  switch ($this->type) {
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  public 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  $this->ilias->raiseError(get_class($this) . "::formatObject(): Missing parameter or wrong datatype! " .
141  "node_id: " . $a_node_id . " options:" . var_dump($a_option), $this->ilias->error_obj->WARNING);
142  }
143 
144  $pic = false;
145  foreach ($a_option["tab"] as $picture) {
146  if ($picture == 'plus') {
147  $tpl->setCurrentBlock("expander");
148  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
149  $target = $this->createTarget('+', $a_node_id);
150  $tpl->setVariable("LINK_NAME", $a_node_id);
151  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
152  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
153  $tpl->parseCurrentBlock();
154  $pic = true;
155  }
156 
157  if ($picture == 'minus' && $this->show_minus) {
158  $tpl->setCurrentBlock("expander");
159  $tpl->setVariable("EXP_DESC", $lng->txt("collapse"));
160  $target = $this->createTarget('-', $a_node_id);
161  $tpl->setVariable("LINK_NAME", $a_node_id);
162  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
163  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
164  $tpl->parseCurrentBlock();
165  $pic = true;
166  }
167  }
168 
169  if (!$pic) {
170  $tpl->setCurrentBlock("blank");
171  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
172  $tpl->parseCurrentBlock();
173  }
174 
175  if ($this->output_icons) {
176  $tpl->setCurrentBlock("icon");
177  $tpl->setVariable("ICON_IMAGE", $this->getImage("icon_" . $a_option["type"] . ".svg", $a_option["type"], $a_obj_id));
178 
179  $tpl->setVariable("TARGET_ID", "iconid_" . $a_node_id);
180  $this->iconList[] = "iconid_" . $a_node_id;
181  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
182  $tpl->parseCurrentBlock();
183  }
184 
185  if (strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type']))) {
186  $tpl->setCurrentBlock('check');
187  $tpl->setVariable('OBJ_CHECK', $formItem);
188  $tpl->parseCurrentBlock();
189  }
190 
191  if ($this->isClickable($a_option["type"], $a_node_id, $a_obj_id)) { // output link
192  $tpl->setCurrentBlock("link");
193  //$target = (strpos($this->target, "?") === false) ?
194  // $this->target."?" : $this->target."&";
195  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
196  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
197 
198  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
199 
200  if ($style_class != "") {
201  $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
202  }
203 
204  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "") {
205  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
206  }
207 
208  $tpl->setVariable("LINK_NAME", $a_node_id);
209  $tpl->setVariable(
210  "TITLE",
211  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
212  );
213  $tpl->setVariable("DESC", ilUtil::shortenText(
214  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]),
215  $this->textwidth,
216  true
217  ));
218  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
219  if ($frame_target != "") {
220  $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
221  }
222  $tpl->parseCurrentBlock();
223  } else { // output text only
224  $tpl->setCurrentBlock("text");
225  $tpl->setVariable(
226  "OBJ_TITLE",
227  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
228  );
229  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
230  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]),
231  $this->textwidth,
232  true
233  ));
234  $tpl->parseCurrentBlock();
235  }
236 
237  $tpl->setCurrentBlock("list_item");
238  $tpl->parseCurrentBlock();
239  $tpl->touchBlock("element");
240  }
241 
242 
243 
244  /*
245  * overwritten method from base class
246  * @access public
247  * @param integer obj_id
248  * @param integer array options
249  * @return string
250  */
251  public function formatHeader($tpl, $a_obj_id, $a_option)
252  {
253  global $lng, $ilias, $tree;
254 
255  // custom icons
256  $path = ilObject::_getIcon($a_obj_id, "tiny", "root");
257 
258 
259  $tpl->setCurrentBlock("icon");
260  $nd = $tree->getNodeData(ROOT_FOLDER_ID);
261  $title = $nd["title"];
262  if ($title == "ILIAS") {
263  $title = $lng->txt("repository");
264  }
265 
266  $tpl->setVariable("ICON_IMAGE", $path);
267  $tpl->setVariable("TXT_ALT_IMG", $title);
268  $tpl->parseCurrentBlock();
269 
270  if (strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type']))) {
271  $tpl->setCurrentBlock('check');
272  $tpl->setVariable('OBJ_CHECK', $formItem);
273  $tpl->parseCurrentBlock();
274  }
275 
276  if ($this->isMapped(ROOT_FOLDER_ID)) {
277  $tpl->setVariable(
278  'OBJ_TITLE',
279  '<font style="font-weight: bold">' . $title . '</font>'
280  );
281  } else {
282  $tpl->setVariable('OBJ_TITLE', $title);
283  }
284  }
285 
293  public function buildTitle($title, $a_obj_id, $a_type)
294  {
295  if ($this->isMapped($a_obj_id)) {
296  return '<font style="font-weight: bold">' . $title . '</font>';
297  }
298  if ($this->hasParentMapping($a_obj_id)) {
299  return '<font style="font-style: italic">' . $title . '</font>';
300  }
301  return $title;
302  }
303 
307  protected function initMappings()
308  {
309  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
310  $mappings = array();
311  foreach (ilECSCourseMappingRule::getRuleRefIds($this->getSid(), $this->getMid()) as $ref_id) {
312  $mappings[$ref_id] = array();
313  }
314 
315  foreach ($mappings as $ref_id => $tmp) {
316  $this->mappings[$ref_id] = $GLOBALS['tree']->getPathId($ref_id, 1);
317  }
318  return true;
319  }
320 
321  protected function isMapped($a_ref_id)
322  {
323  return array_key_exists($a_ref_id, $this->mappings);
324  }
325 
326  protected function hasParentMapping($a_ref_id)
327  {
328  foreach ($this->mappings as $ref_id => $parent_nodes) {
329  if (in_array($a_ref_id, $parent_nodes)) {
330  return true;
331  }
332  }
333  return false;
334  }
335 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
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.
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
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
$nd
Definition: error.php:10
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
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