ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
30 
31  $tree = $DIC['tree'];
32 
33  parent::__construct($a_target);
34 
35  $this->sid = $a_sid;
36  $this->mid = $a_mid;
37 
38  $this->type = self::SEL_TYPE_RADIO;
39 
40  $this->tree = $tree;
41  $this->setRoot($tree->readRootId());
42  $this->setOrderColumn('title');
43 
44 
45  // reset filter
46  $this->filter = array();
47 
48  $this->addFilter('root');
49  $this->addFilter('cat');
50 
51  $this->addFormItemForType('root');
52  $this->addFormItemForType('cat');
53 
54  $this->setFiltered(true);
56 
57  $this->initMappings();
58  }
59 
60  public function getSid()
61  {
62  return $this->sid;
63  }
64 
65  public function getMid()
66  {
67  return $this->mid;
68  }
69 
77  public function isClickable($a_type, $a_ref_id = 0, $a_obj_id = 0)
78  {
79  return false;
80  }
81 
86  public function addFormItemForType($type)
87  {
88  $this->form_items[$type] = true;
89  }
90 
91  public function removeFormItemForType($type)
92  {
93  $this->form_items[$type] = false;
94  }
95 
96  public function setCheckedItems($a_checked_items = array())
97  {
98  $this->checked_items = $a_checked_items;
99  }
100 
101  public function getCheckedItems()
102  {
103  return (array) $this->checked_items;
104  }
105 
106  public function isItemChecked($a_id)
107  {
108  return in_array($a_id, $this->checked_items) ? true : false;
109  }
110 
111  public function setPostVar($a_post_var)
112  {
113  $this->post_var = $a_post_var;
114  }
115  public function getPostVar()
116  {
117  return $this->post_var;
118  }
119 
120  public function buildFormItem($a_node_id, $a_type)
121  {
122  if (!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type]) {
123  return '';
124  }
125 
126  switch ($this->type) {
127  case self::SEL_TYPE_CHECK:
128  return ilUtil::formCheckbox((int) $this->isItemChecked($a_node_id), $this->post_var, $a_node_id);
129  break;
130 
131  case self::SEL_TYPE_RADIO:
132  return ilUtil::formRadioButton((int) $this->isItemChecked($a_node_id), $this->post_var, $a_node_id, "document.getElementById('map').submit(); return false;");
133  break;
134  }
135  }
136 
137  public function formatObject($tpl, $a_node_id, $a_option, $a_obj_id = 0)
138  {
139  global $DIC;
140 
141  $lng = $DIC['lng'];
142 
143  if (!isset($a_node_id) or !is_array($a_option)) {
144  $this->ilias->raiseError(get_class($this) . "::formatObject(): Missing parameter or wrong datatype! " .
145  "node_id: " . $a_node_id . " options:" . var_dump($a_option), $this->ilias->error_obj->WARNING);
146  }
147 
148  $pic = false;
149  foreach ($a_option["tab"] as $picture) {
150  if ($picture == 'plus') {
151  $tpl->setCurrentBlock("expander");
152  $tpl->setVariable("EXP_DESC", $lng->txt("expand"));
153  $target = $this->createTarget('+', $a_node_id);
154  $tpl->setVariable("LINK_NAME", $a_node_id);
155  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
156  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
157  $tpl->parseCurrentBlock();
158  $pic = true;
159  }
160 
161  if ($picture == 'minus' && $this->show_minus) {
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  $tpl->setCurrentBlock("blank");
175  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
176  $tpl->parseCurrentBlock();
177  }
178 
179  if ($this->output_icons) {
180  $tpl->setCurrentBlock("icon");
181  $tpl->setVariable("ICON_IMAGE", $this->getImage("icon_" . $a_option["type"] . ".svg", $a_option["type"], $a_obj_id));
182 
183  $tpl->setVariable("TARGET_ID", "iconid_" . $a_node_id);
184  $this->iconList[] = "iconid_" . $a_node_id;
185  $tpl->setVariable("TXT_ALT_IMG", $lng->txt($a_option["desc"]));
186  $tpl->parseCurrentBlock();
187  }
188 
189  if (strlen($formItem = $this->buildFormItem($a_node_id, $a_option['type']))) {
190  $tpl->setCurrentBlock('check');
191  $tpl->setVariable('OBJ_CHECK', $formItem);
192  $tpl->parseCurrentBlock();
193  }
194 
195  if ($this->isClickable($a_option["type"], $a_node_id, $a_obj_id)) { // output link
196  $tpl->setCurrentBlock("link");
197  //$target = (strpos($this->target, "?") === false) ?
198  // $this->target."?" : $this->target."&";
199  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
200  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
201 
202  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
203 
204  if ($style_class != "") {
205  $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
206  }
207 
208  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "") {
209  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
210  }
211 
212  $tpl->setVariable("LINK_NAME", $a_node_id);
213  $tpl->setVariable(
214  "TITLE",
215  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
216  );
217  $tpl->setVariable("DESC", ilUtil::shortenText(
218  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]),
219  $this->textwidth,
220  true
221  ));
222  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
223  if ($frame_target != "") {
224  $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
225  }
226  $tpl->parseCurrentBlock();
227  } else { // output text only
228  $tpl->setCurrentBlock("text");
229  $tpl->setVariable(
230  "OBJ_TITLE",
231  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
232  );
233  $tpl->setVariable("OBJ_DESC", ilUtil::shortenText(
234  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]),
235  $this->textwidth,
236  true
237  ));
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  public function formatHeader($tpl, $a_obj_id, $a_option)
256  {
257  global $DIC;
258 
259  $lng = $DIC['lng'];
260  $ilias = $DIC['ilias'];
261  $tree = $DIC['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  $title = $lng->txt("repository");
272  }
273 
274  $tpl->setVariable("ICON_IMAGE", $path);
275  $tpl->setVariable("TXT_ALT_IMG", $title);
276  $tpl->parseCurrentBlock();
277 
278  if (strlen($formItem = $this->buildFormItem($a_obj_id, $a_option['type']))) {
279  $tpl->setCurrentBlock('check');
280  $tpl->setVariable('OBJ_CHECK', $formItem);
281  $tpl->parseCurrentBlock();
282  }
283 
284  if ($this->isMapped(ROOT_FOLDER_ID)) {
285  $tpl->setVariable(
286  'OBJ_TITLE',
287  '<font style="font-weight: bold">' . $title . '</font>'
288  );
289  } else {
290  $tpl->setVariable('OBJ_TITLE', $title);
291  }
292  }
293 
301  public function buildTitle($title, $a_obj_id, $a_type)
302  {
303  if ($this->isMapped($a_obj_id)) {
304  return '<font style="font-weight: bold">' . $title . '</font>';
305  }
306  if ($this->hasParentMapping($a_obj_id)) {
307  return '<font style="font-style: italic">' . $title . '</font>';
308  }
309  return $title;
310  }
311 
315  protected function initMappings()
316  {
317  include_once './Services/WebServices/ECS/classes/Course/class.ilECSCourseMappingRule.php';
318  $mappings = array();
319  foreach (ilECSCourseMappingRule::getRuleRefIds($this->getSid(), $this->getMid()) as $ref_id) {
320  $mappings[$ref_id] = array();
321  }
322 
323  foreach ($mappings as $ref_id => $tmp) {
324  $this->mappings[$ref_id] = $GLOBALS['DIC']['tree']->getPathId($ref_id, 1);
325  }
326  return true;
327  }
328 
329  protected function isMapped($a_ref_id)
330  {
331  return array_key_exists($a_ref_id, $this->mappings);
332  }
333 
334  protected function hasParentMapping($a_ref_id)
335  {
336  foreach ($this->mappings as $ref_id => $parent_nodes) {
337  if (in_array($a_ref_id, $parent_nodes)) {
338  return true;
339  }
340  }
341  return false;
342  }
343 }
$path
Definition: aliased.php:25
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)
global $DIC
Definition: saml.php:7
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)
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
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
static formCheckbox($checked, $varname, $value, $disabled=false)
??? public