ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilECSNodeMappingLocalExplorer.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
26 {
27  public const SEL_TYPE_CHECK = 1;
28  public const SEL_TYPE_RADIO = 2;
29 
33  private array $checked_items = [];
34  private string $post_var = '';
35  private array $form_items = [];
36  private int $type;
37 
38  private int $sid;
39  private int $mid;
40 
41  private array $mappings = [];
42 
43  public function __construct(string $a_target, int $a_sid, int $a_mid)
44  {
45  parent::__construct($a_target);
46 
47  $this->sid = $a_sid;
48  $this->mid = $a_mid;
49 
50  $this->type = self::SEL_TYPE_RADIO;
51 
52  $this->setRoot($this->tree->readRootId());
53  $this->setOrderColumn('title');
54 
55 
56  // reset filter
57  $this->filter = array();
58 
59  $this->addFilter('root');
60  $this->addFilter('cat');
61 
62  $this->addFormItemForType('root');
63  $this->addFormItemForType('cat');
64 
65  $this->setFiltered(true);
67 
68  $this->initMappings();
69  }
70 
71  public function getSid(): int
72  {
73  return $this->sid;
74  }
75 
76  public function getMid(): int
77  {
78  return $this->mid;
79  }
80 
84  public function isClickable(string $type, int $ref_id = 0): bool
85  {
86  return false;
87  }
88 
92  public function addFormItemForType($type): void
93  {
94  $this->form_items[$type] = true;
95  }
96 
97  public function removeFormItemForType($type): void
98  {
99  $this->form_items[$type] = false;
100  }
101 
102  public function setCheckedItems($a_checked_items = array()): void
103  {
104  $this->checked_items = $a_checked_items;
105  }
106 
107  public function getCheckedItems(): array
108  {
109  return $this->checked_items;
110  }
111 
112  public function isItemChecked(int $a_id): bool
113  {
114  return in_array($a_id, $this->checked_items, true);
115  }
116 
117  public function setPostVar(string $a_post_var): void
118  {
119  $this->post_var = $a_post_var;
120  }
121  public function getPostVar(): string
122  {
123  return $this->post_var;
124  }
125 
126  public function buildFormItem($a_node_id, string $a_type): string
127  {
128  if (!array_key_exists($a_type, $this->form_items) || !$this->form_items[$a_type]) {
129  return '';
130  }
131 
132  switch ($this->type) {
133  case self::SEL_TYPE_CHECK:
135  $this->isItemChecked($a_node_id),
136  $this->post_var,
137  (string) $a_node_id
138  );
139  case self::SEL_TYPE_RADIO:
141  $this->isItemChecked($a_node_id),
142  $this->post_var,
143  (string) $a_node_id,
144  "document.getElementById('map').submit(); return false;"
145  );
146  }
147  return '';
148  }
149 
154  public function formatObject(ilTemplate $tpl, $a_node_id, array $a_option, $a_obj_id = 0): void
155  {
156  if (!isset($a_node_id) || !is_array($a_option)) {
157  $this->error->raiseError(get_class($this) . "::formatObject(): Missing parameter or wrong datatype! " .
158  "node_id: " . $a_node_id . " options:" . print_r($a_option, true), $this->error->WARNING);
159  }
160 
161  $pic = false;
162  foreach ($a_option["tab"] as $picture) {
163  if ($picture === 'plus') {
164  $tpl->setCurrentBlock("expander");
165  $tpl->setVariable("EXP_DESC", $this->lng->txt("expand"));
166  $this->setParamsGet([]);
167  $target = $this->createTarget('+', $a_node_id);
168  $tpl->setVariable("LINK_NAME", $a_node_id);
169  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
170  $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
171  $tpl->parseCurrentBlock();
172  $pic = true;
173  }
174 
175  if ($picture === 'minus' && $this->show_minus) {
176  $tpl->setCurrentBlock("expander");
177  $tpl->setVariable("EXP_DESC", $this->lng->txt("collapse"));
178  $this->setParamsGet([]);
179  $target = $this->createTarget('-', $a_node_id);
180  $tpl->setVariable("LINK_NAME", $a_node_id);
181  $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
182  $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
183  $tpl->parseCurrentBlock();
184  $pic = true;
185  }
186  }
187 
188  if (!$pic) {
189  $tpl->setCurrentBlock("blank");
190  $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
191  $tpl->parseCurrentBlock();
192  }
193 
194  if ($this->output_icons) {
195  $tpl->setCurrentBlock("icon");
196  $tpl->setVariable("ICON_IMAGE", $this->getImage("icon_" . $a_option["type"] . ".svg", $a_option["type"], $a_obj_id));
197 
198  $tpl->setVariable("TARGET_ID", "iconid_" . $a_node_id);
199  $this->iconList[] = "iconid_" . $a_node_id;
200  $tpl->setVariable("TXT_ALT_IMG", $this->lng->txt($a_option["desc"]));
201  $tpl->parseCurrentBlock();
202  }
203 
204  if (($formItem = $this->buildFormItem((int) $a_node_id, (string) $a_option['type'])) !== '') {
205  $tpl->setCurrentBlock('check');
206  $tpl->setVariable('OBJ_CHECK', $formItem);
207  $tpl->parseCurrentBlock();
208  }
209 
210  if ($this->isClickable($a_option["type"], (int) $a_node_id)) { // output link
211  $tpl->setCurrentBlock("link");
212  //$target = (strpos($this->target, "?") === false) ?
213  // $this->target."?" : $this->target."&";
214  //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
215  $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
216 
217  $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
218 
219  if ($style_class !== "") {
220  $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
221  }
222 
223  if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) !== "") {
224  $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
225  }
226 
227  $tpl->setVariable("LINK_NAME", $a_node_id);
228  $tpl->setVariable(
229  "TITLE",
230  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
231  );
232  $tpl->setVariable(
233  "DESC",
235  $this->buildDescription($a_option["description"], $a_node_id, $a_option["type"]),
236  $this->textwidth,
237  true
238  )
239  );
240  $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
241  if ($frame_target !== "") {
242  $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
243  }
244  } else { // output text only
245  $tpl->setCurrentBlock("text");
246  $tpl->setVariable(
247  "OBJ_TITLE",
248  $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"])
249  );
250  $tpl->setVariable(
251  "OBJ_DESC",
253  $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]),
254  $this->textwidth,
255  true
256  )
257  );
258  }
259  $tpl->parseCurrentBlock();
260 
261  $tpl->setCurrentBlock("list_item");
262  $tpl->parseCurrentBlock();
263  $tpl->touchBlock("element");
264  }
265 
266 
267 
271  public function formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option): void
272  {
273  // custom icons
274  $path = ilObject::_getIcon((int) $a_obj_id, "tiny", "root");
275 
276 
277  $tpl->setCurrentBlock("icon");
278  $nd = $this->tree->getNodeData(ROOT_FOLDER_ID);
279  $title = $nd["title"];
280  if ($title === "ILIAS") {
281  $title = $this->lng->txt("repository");
282  }
283 
284  $tpl->setVariable("ICON_IMAGE", $path);
285  $tpl->setVariable("TXT_ALT_IMG", $title);
286  $tpl->parseCurrentBlock();
287 
288  if (($formItem = $this->buildFormItem((int) $a_obj_id, (string) $a_option['type'])) !== '') {
289  $tpl->setCurrentBlock('check');
290  $tpl->setVariable('OBJ_CHECK', $formItem);
291  $tpl->parseCurrentBlock();
292  }
293 
294  if ($this->isMapped(ROOT_FOLDER_ID)) {
295  $tpl->setVariable(
296  'OBJ_TITLE',
297  '<font style="font-weight: bold">' . $title . '</font>'
298  );
299  } else {
300  $tpl->setVariable('OBJ_TITLE', $title);
301  }
302  }
303 
307  public function buildTitle(string $a_title, $a_id, string $a_type): string
308  {
309  if ($this->isMapped($a_id)) {
310  return '<font style="font-weight: bold">' . $a_title . '</font>';
311  }
312  if ($this->hasParentMapping($a_id)) {
313  return '<font style="font-style: italic">' . $a_title . '</font>';
314  }
315  return $a_title;
316  }
317 
321  protected function initMappings(): bool
322  {
323  $mappings = array();
324  foreach (ilECSCourseMappingRule::getRuleRefIds($this->getSid(), $this->getMid()) as $ref_id) {
325  $mappings[$ref_id] = [];
326  }
327 
328  foreach (array_keys($mappings) as $ref_id) {
329  $this->mappings[$ref_id] = $this->tree->getPathId($ref_id, 1);
330  }
331  return true;
332  }
333 
334  protected function isMapped($a_ref_id): bool
335  {
336  return array_key_exists($a_ref_id, $this->mappings);
337  }
338 
339  protected function hasParentMapping($a_ref_id): bool
340  {
341  foreach ($this->mappings as $parent_nodes) {
342  if (in_array($a_ref_id, $parent_nodes, true)) {
343  return true;
344  }
345  }
346  return false;
347  }
348 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setFiltered(bool $a_bool)
buildDescription(string $a_desc, $a_id, string $a_type)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
formatObject(ilTemplate $tpl, $a_node_id, array $a_option, $a_obj_id=0)
const ROOT_FOLDER_ID
Definition: constants.php:32
ilGlobalTemplateInterface $tpl
const IL_FM_POSITIVE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
isClickable(string $type, int $ref_id=0)
no item is clickable
touchBlock(string $block)
$ref_id
Definition: ltiauth.php:67
$nd
Definition: error.php:12
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
__construct(string $a_target, int $a_sid, int $a_mid)
static getRuleRefIds(int $a_sid, int $a_mid)
setOrderColumn(string $a_column)
static formRadioButton(bool $checked, string $varname, string $value, string $onclick=null, bool $disabled=false)
string $frame_target
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
setRoot($a_root_id)
class for explorer view in admin frame
buildFrameTarget(string $a_type, $a_child=0, $a_obj_id=0)
getNodeStyleClass( $a_id, string $a_type)
getImage(string $a_name, string $a_type="", $a_obj_id="")
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
addFilter(string $a_item)
createTarget(string $a_type, $a_node_id, bool $a_highlighted_subtree=false, bool $a_append_anch=true)
buildLinkTarget( $a_node_id, string $a_type)
formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option)
overwritten method from base class
buildOnClick( $a_node_id, string $a_type, string $a_title)
setFilterMode(int $a_mode=IL_FM_NEGATIVE)
buildTitle(string $a_title, $a_id, string $a_type)
Format title (bold for direct mappings, italic for child mappings)
setParamsGet(array $a_params_get)