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