ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPasteIntoMultipleItemsExplorer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30{
31 public const SEL_TYPE_CHECK = 1;
32 public const SEL_TYPE_RADIO = 2;
33
34 protected int $type = 0;
36
37 protected array $checked_items = [];
38 protected string $post_var = '';
39 protected array $form_items = [];
40 protected string $form_item_permission = 'read';
41
42 public function __construct(int $type, string $target, string $session_variable)
43 {
44 global $DIC;
45
46 $this->setId("cont_paste_explorer");
47 $this->type = $type;
48
50
51 $this->root_id = $this->tree->readRootId();
52 $this->order_column = 'title';
53 $this->setSessionExpandVariable($session_variable);
54
55 $this->addFilter('root');
56 $this->addFilter('crs');
57 $this->addFilter('grp');
58 $this->addFilter('cat');
59 $this->addFilter('fold');
60 $this->addFilter('lso');
61
62 $this->addFormItemForType('root');
63 $this->addFormItemForType('crs');
64 $this->addFormItemForType('grp');
65 $this->addFormItemForType('cat');
66 $this->addFormItemForType('fold');
67 $this->addFormItemForType('lso');
68
69 $this->setFiltered(true);
71 $this->clipboard = $DIC
72 ->repository()
73 ->internal()
74 ->domain()
75 ->clipboard();
76 }
77
78 public function isClickable(
79 string $type,
80 int $ref_id = 0
81 ): bool {
82 return false;
83 }
84
85 public function addFormItemForType(string $type): void
86 {
87 $this->form_items[$type] = true;
88 }
89
90 public function removeFormItemForType(string $type): void
91 {
92 $this->form_items[$type] = false;
93 }
94
95 public function setCheckedItems(array $checked_items = []): void
96 {
97 $this->checked_items = $checked_items;
98 }
99
100 public function isItemChecked(int $id): bool
101 {
102 return in_array($id, $this->checked_items);
103 }
104
105 public function setPostVar(string $post_var): void
106 {
107 $this->post_var = $post_var;
108 }
109
110 public function getPostVar(): string
111 {
112 return $this->post_var;
113 }
114
115 public function setRequiredFormItemPermission(string $form_item_permission): void
116 {
117 $this->form_item_permission = $form_item_permission;
118 }
119
120 public function getRequiredFormItemPermission(): string
121 {
122 return $this->form_item_permission;
123 }
124
125 public function buildFormItem(int $node_id, string $type): string
126 {
127 if (!$this->access->checkAccess($this->getRequiredFormItemPermission(), '', $node_id)) {
128 return "";
129 }
130
131 if (
132 !array_key_exists($type, $this->form_items) ||
133 !$this->form_items[$type]
134 ) {
135 return "";
136 }
137
138 $disabled = false;
139 if ($this->clipboard->hasEntries()) {
140 $disabled = in_array($node_id, $this->clipboard->getRefIds());
141 } elseif ($this->clipboard->getCmd() == 'copy' && $node_id == $this->clipboard->getParent()) {
142 $disabled = true;
143 }
144
145 switch ($this->type) {
146 case self::SEL_TYPE_CHECK:
148 $this->isItemChecked($node_id),
149 $this->post_var,
150 (string) $node_id,
151 $disabled
152 );
153 case self::SEL_TYPE_RADIO:
155 $this->isItemChecked($node_id),
156 $this->post_var,
157 (string) $node_id,
158 '',
159 $disabled
160 );
161 }
162 return "";
163 }
164
165 public function formatObject(ilTemplate $tpl, $node_id, array $option, $obj_id = 0): void
166 {
167 $node_id = (int) $node_id;
168 $obj_id = (int) $obj_id;
169 if (!isset($node_id) or !is_array($option)) {
170 $this->error->raiseError(
171 get_class($this) .
172 "::formatObject(): Missing parameter or wrong datatype! " .
173 "node_id: " .
174 $node_id .
175 " options:" .
176 var_dump($option),
177 $this->error->WARNING
178 );
179 }
180
181 $pic = false;
182 foreach ($option["tab"] as $picture) {
183 if ($picture == 'plus') {
184 $tpl->setCurrentBlock("expander");
185 $tpl->setVariable("EXP_DESC", $this->lng->txt("expand"));
186 $target = $this->createTarget('+', $node_id);
187 $tpl->setVariable("LINK_NAME", $node_id);
188 $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
189 $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
190 $tpl->parseCurrentBlock();
191 $pic = true;
192 }
193
194 if ($picture == 'minus' && $this->show_minus) {
195 $tpl->setCurrentBlock("expander");
196 $tpl->setVariable("EXP_DESC", $this->lng->txt("collapse"));
197 $target = $this->createTarget('-', $node_id);
198 $tpl->setVariable("LINK_NAME", $node_id);
199 $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
200 $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
201 $tpl->parseCurrentBlock();
202 $pic = true;
203 }
204 }
205
206 if (!$pic) {
207 $tpl->setCurrentBlock("blank");
208 $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
209 $tpl->parseCurrentBlock();
210 }
211
212 if ($this->output_icons) {
213 $tpl->setCurrentBlock("icon");
214
215 $path = ilObject::_getIcon($obj_id, "tiny", $option["type"]);
216 $tpl->setVariable("ICON_IMAGE", $path);
217
218 $tpl->setVariable("TARGET_ID", "iconid_" . $node_id);
219 $this->iconList[] = "iconid_" . $node_id;
220 $tpl->setVariable("TXT_ALT_IMG", $this->lng->txt($option["desc"]));
221 $tpl->parseCurrentBlock();
222 }
223
224 if (strlen($formItem = $this->buildFormItem($node_id, $option['type']))) {
225 $tpl->setCurrentBlock('check');
226 $tpl->setVariable('OBJ_CHECK', $formItem);
227 $tpl->parseCurrentBlock();
228 }
229
230 if ($this->isClickable($option["type"], $node_id)) {
231 $tpl->setCurrentBlock("link");
232 $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($node_id, $option["type"]));
233
234 $style_class = $this->getNodeStyleClass($node_id, $option["type"]);
235
236 if ($style_class != "") {
237 $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
238 }
239
240 if (($onclick = $this->buildOnClick($node_id, $option["type"], $option["title"])) != "") {
241 $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
242 }
243
244 $tpl->setVariable("LINK_NAME", $node_id);
245 $tpl->setVariable("TITLE", $this->buildTitle($option["title"], $node_id, $option["type"]));
246 $tpl->setVariable(
247 "DESC",
249 $this->buildDescription($option["description"], $node_id, $option["type"]),
250 $this->textwidth,
251 true
252 )
253 );
254 $frame_target = $this->buildFrameTarget($option["type"], $node_id, $option["obj_id"]);
255 if ($frame_target != "") {
256 $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
257 }
258 } else {
259 $obj_title = $this->buildTitle($option["title"], $node_id, $option["type"]);
260
261 if ($node_id == $this->highlighted) {
262 $obj_title = "<span class=\"ilHighlighted\">" . $obj_title . "</span>";
263 }
264
265 $tpl->setCurrentBlock("text");
266 $tpl->setVariable("OBJ_TITLE", $obj_title);
267 $tpl->setVariable(
268 "OBJ_DESC",
270 $this->buildDescription($option["desc"], $node_id, $option["type"]),
271 $this->textwidth,
272 true
273 )
274 );
275 }
276 $tpl->parseCurrentBlock();
277
278 $tpl->setCurrentBlock("list_item");
279 $tpl->parseCurrentBlock();
280 $tpl->touchBlock("element");
281 }
282
283 /*
284 * @param int $obj_id
285 */
286 public function formatHeader(ilTemplate $tpl, $obj_id, array $option): void
287 {
288 $path = ilObject::_getIcon((int) $obj_id, "tiny", "root");
289
290 $tpl->setCurrentBlock("icon");
291 $nd = $this->tree->getNodeData(ROOT_FOLDER_ID);
292 $title = $nd["title"];
293 if ($title == "ILIAS") {
294 $title = $this->lng->txt("repository");
295 }
296
297 $tpl->setVariable("ICON_IMAGE", $path);
298 $tpl->setVariable("TXT_ALT_IMG", $title);
299 $tpl->parseCurrentBlock();
300
301 if (strlen($formItem = $this->buildFormItem((int) $obj_id, $option['type']))) {
302 $tpl->setCurrentBlock('check');
303 $tpl->setVariable('OBJ_CHECK', $formItem);
304 $tpl->parseCurrentBlock();
305 }
306
307 $tpl->setVariable('OBJ_TITLE', $title);
308 }
309
310 public function showChilds($parent_id, $obj_id = 0): bool
311 {
312 if ($parent_id == 0) {
313 return true;
314 }
315 if ($this->access->checkAccess("read", "", (int) $parent_id)) {
316 return true;
317 }
318 return false;
319 }
320
321 public function isVisible($ref_id, string $type): bool
322 {
323 if (!$this->access->checkAccess('visible', '', (int) $ref_id)) {
324 return false;
325 }
326 return true;
327 }
328}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Manages items in repository clipboard.
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)
addFilter(string $a_item)
setFilterMode(int $a_mode=IL_FM_NEGATIVE)
setSessionExpandVariable(string $a_var_name="expand")
setFiltered(bool $a_bool)
setId(string $a_val)
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.
ilPasteIntoMultipleItemsExplorer Explorer
__construct(int $type, string $target, string $session_variable)
formatHeader(ilTemplate $tpl, $obj_id, array $option)
formatObject(ilTemplate $tpl, $node_id, array $option, $obj_id=0)
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
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
touchBlock(string $block)
const ROOT_FOLDER_ID
Definition: constants.php:32
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$nd
Definition: error.php:30
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26