ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCResourcesGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected \ILIAS\Container\InternalDomainService $container_domain;
26 protected ilTree $rep_tree;
28
29
30 public function __construct(
31 ilPageObject $a_pg_obj,
32 ?ilPageContent $a_content_obj,
33 string $a_hier_id,
34 string $a_pc_id = ""
35 ) {
36 global $DIC;
37
38 $this->ctrl = $DIC->ctrl();
39 $this->tpl = $DIC["tpl"];
40 $this->lng = $DIC->language();
41 $this->obj_definition = $DIC["objDefinition"];
42 $tree = $DIC->repositoryTree();
43
44 $this->rep_tree = $tree;
45
46 $this->container_domain = $DIC->container()->internal()->domain();
47
48 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
49 }
50
51 public function executeCommand(): void
52 {
53 // get next class that processes or forwards current command
54 $next_class = $this->ctrl->getNextClass($this);
55
56 // get current command
57 $cmd = $this->ctrl->getCmd();
58
59 switch ($next_class) {
60 default:
61 $this->$cmd();
62 break;
63 }
64 }
65
66 public function insert(): void
67 {
68 $this->edit(true);
69 }
70
71 public function edit(bool $a_insert = false): void
72 {
75 $form = $this->initForm($a_insert);
76 $html = $form->getHTML();
77 $tpl->setContent($html);
78 }
79
80 public function initForm(bool $a_insert = false): ilPropertyFormGUI
81 {
82 $ilCtrl = $this->ctrl;
85 $objDefinition = $this->obj_definition;
86
87 $op_type = null;
88 $op_itemgroup = null;
89
90 // edit form
91 $form = new ilPropertyFormGUI();
92 $form->setFormAction($ilCtrl->getFormAction($this));
93 if ($a_insert) {
94 $form->setTitle($this->lng->txt("cont_insert_resources"));
95 } else {
96 $form->setTitle($this->lng->txt("cont_update_resources"));
97 }
98
99 // count number of existing objects per type and collect item groups
101 $childs = $this->rep_tree->getChilds($ref_id);
102
103 $type_counts = array();
104 $item_groups = array();
105 foreach ($childs as $c) {
106 // see bug #12471
107 //echo "<br>-".$c["type"]."-".$objDefinition->getGroupOfObj($c["type"])."-";
108 $key = ($objDefinition->getGroupOfObj($c["type"]) != "")
109 ? $objDefinition->getGroupOfObj($c["type"])
110 : $c["type"];
111 $type_counts[$key] = ($type_counts[$key] ?? 0) + 1;
112 if ($c["type"] == "itgr") {
113 $item_groups[$c["ref_id"]] = $c["title"];
114 }
115 }
116
117 // radio group for type selection
118 $radg = new ilRadioGroupInputGUI($lng->txt("cont_resources"), "res_type");
119 $form->addItem($radg);
120 if (!$a_insert && $this->content_obj->getMainType() == "ItemGroup") {
121 $radg->setValue("itgr");
122 } else {
123 $radg->setValue("by_type");
124 }
125
126
127 $op_type = new ilRadioOption($lng->txt("cont_resources_of_type"), "by_type", "");
128 // all views support typed blocks
129 //if ($this->supportsTypeBlocks()) {
130 //}
131
132 if ($this->supportsItemGroups() && count($item_groups) > 0) {
133 $op_itemgroup = new ilRadioOption($lng->txt("cont_manual_item_group"), "itgr", "");
134 $radg->addOption($op_itemgroup);
135 }
136
137 $radg->addOption($op_type);
138
139 // type selection
140 $type_prop = new ilSelectInputGUI(
141 $this->lng->txt("cont_type"),
142 "type"
143 );
144 $obj_id = ilObject::_lookupObjId($this->requested_ref_id);
145 $obj_type = ilObject::_lookupType($obj_id);
146 $sub_objs = $objDefinition->getGroupedRepositoryObjectTypes($obj_type);
147 $types = array();
148 foreach ($sub_objs as $k => $so) {
149 $cnt = (int) ($type_counts[$k] ?? 0);
150 if ($cnt === 0) {
151 continue;
152 }
153 if (!$objDefinition->isPlugin($k)) {
154 if ($k != "itgr") {
155 $types[$k] = $this->lng->txt("objs_" . $k) . " (" . $cnt . ")";
156 }
157 } else {
159 $types[$k] = $pl->txt("objs_" . $k) . " (" . $cnt . ")";
160 }
161 }
162 $type_prop->setOptions($types);
163 $selected = ($a_insert)
164 ? ""
165 : $this->content_obj->getResourceListType();
166 $type_prop->setValue($selected);
167 $op_type->addSubItem($type_prop);
168
169 if ($this->supportsItemGroups() && count($item_groups) > 0) {
170 // item groups
171 $options = $item_groups;
172 $si = new ilSelectInputGUI($this->lng->txt("obj_itgr"), "itgr");
173 $si->setOptions($options);
174 $selected = ($a_insert)
175 ? ""
176 : $this->content_obj->getItemGroupRefId();
177 $op_itemgroup->addSubItem($si);
178 if ($a_insert) {
179 $radg->setValue("itgr");
180 }
181 }
182
183 // learning objectives
184 if ($this->supportsObjectives()) {
185 $lng->loadLanguageModule("crs");
186 $op_lobj = new ilRadioOption($lng->txt("crs_objectives"), "_lobj", "");
187 $radg->addOption($op_lobj);
188 if (!$a_insert && $this->content_obj->getResourceListType() === "_lobj") {
189 $radg->setValue("_lobj");
190 }
191 }
192
193 // other
194 if ($this->supportsOther() && $this->hasOtherBlock()) {
195 $op_other = new ilRadioOption($lng->txt("cont_other_resources"), "_other", "");
196 $radg->addOption($op_other);
197 if (!$a_insert && $this->content_obj->getResourceListType() === "_other") {
198 $radg->setValue("_other");
199 }
200 }
201
202 // save/cancel buttons
203 if ($a_insert) {
204 $form->addCommandButton("create", $lng->txt("save"));
205 $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
206 } else {
207 $form->addCommandButton("update_resources", $lng->txt("save"));
208 $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
209 }
210 return $form;
211 }
212
214 {
215 $form = $this->initForm(true);
216 return $form;
217 }
218
220 {
221 $form = $this->initForm(false);
222 return $form;
223 }
224
229 protected function getContainerViewManager(): \ILIAS\Container\Content\ViewManager
230 {
233 $view_manager = $this->container_domain->content()->view($container);
234 return $view_manager;
235 }
236
237 protected function supportsItemGroups(): bool
238 {
239 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
240 if ($part instanceof \ILIAS\Container\Content\ItemGroupBlocks) {
241 return true;
242 }
243 }
244 return false;
245 }
246
247 protected function supportsOther(): bool
248 {
249 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
250 if ($part instanceof \ILIAS\Container\Content\OtherBlock) {
251 return true;
252 }
253 }
254 return false;
255 }
256
257 protected function supportsObjectives(): bool
258 {
259 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
260 if ($part instanceof \ILIAS\Container\Content\ObjectivesBlock) {
261 return true;
262 }
263 }
264 return false;
265 }
266
267 protected function supportsTypeBlocks(): bool
268 {
269 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
270 if ($part instanceof \ILIAS\Container\Content\TypeBlocks) {
271 return true;
272 }
273 }
274 return false;
275 }
276
277 public function create(): void
278 {
279 $this->content_obj = new ilPCResources($this->getPage());
280 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
281
282 if ($this->request->getString("res_type") === "_other") {
283 $this->content_obj->setResourceListType("_other");
284 } elseif ($this->request->getString("res_type") === "_lobj") {
285 $this->content_obj->setResourceListType("_lobj");
286 } elseif ($this->request->getString("res_type") !== "itgr") {
287 $this->content_obj->setResourceListType(
288 $this->request->getString("type")
289 );
290 } else {
291 $this->content_obj->setItemGroupRefId(
292 $this->request->getString("itgr")
293 );
294 }
295 $this->updated = $this->pg_obj->update();
296 if ($this->updated === true) {
297 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
298 } else {
299 $this->insert();
300 }
301 }
302
303 public function update(): void
304 {
305 if ($this->request->getString("res_type") === "_other") {
306 $this->content_obj->setResourceListType("_other");
307 } elseif ($this->request->getString("res_type") === "_lobj") {
308 $this->content_obj->setResourceListType("_lobj");
309 } elseif ($this->request->getString("res_type") !== "itgr") {
310 $this->content_obj->setResourceListType(
311 $this->request->getString("type")
312 );
313 } else {
314 $this->content_obj->setItemGroupRefId(
315 $this->request->getString("itgr")
316 );
317 }
318 $this->updated = $this->pg_obj->update();
319 if ($this->updated === true) {
320 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
321 } else {
322 $this->pg_obj->addHierIDs();
323 $this->edit();
324 }
325 }
326
327 protected function hasOtherBlock(): bool
328 {
329 global $DIC;
330
331 $ref_id = $DIC
332 ->copage()
333 ->internal()
334 ->gui()
335 ->pc()
336 ->editRequest()
337 ->getRefId();
338 $item_presentation_manager = $DIC->container()->internal()
339 ->domain()
340 ->content()
341 ->itemPresentation(
343 null,
344 false
345 );
346 $block_sequence = $item_presentation_manager->getItemBlockSequence();
347 foreach ($block_sequence->getBlocks() as $block) {
348 if (($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock)) {
349 return true;
350 }
351 }
352 return false;
353 }
354
358 public static function insertResourcesIntoPageContent(
359 string $a_content
360 ): string {
361 global $DIC;
362
363 $obj_definition = $DIC["objDefinition"];
364 $item_ref_ids = [];
365
366 $lng = $DIC->language();
367 $ref_id = $DIC
368 ->copage()
369 ->internal()
370 ->gui()
371 ->pc()
372 ->editRequest()
373 ->getRefId();
374 $item_presentation_manager = $DIC->container()->internal()
375 ->domain()
376 ->content()
377 ->itemPresentation(
379 null
380 );
381 $block_sequence = $item_presentation_manager->getItemBlockSequence();
382
383 foreach ($block_sequence->getBlocks() as $block) {
384 // render block
385 $tpl = new ilTemplate("tpl.resource_block.html", true, true, "components/ILIAS/COPage");
386 $cnt = 0;
387 $max = 5;
388 if (!($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) &&
389 count($block->getItemRefIds()) > 0) {
390 foreach ($block->getItemRefIds() as $ref_id) {
391 $data = $item_presentation_manager->getRawDataByRefId($ref_id);
392 if ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
393 if ($data["type"] === "itgr" || in_array($ref_id, $item_ref_ids)) {
394 continue;
395 }
396 }
397
398 if ($cnt < $max) {
399 $tpl->setCurrentBlock("row");
401 "IMG",
403 ilObject::_getIcon((int) $data["obj_id"], "small"),
404 null,
405 "",
406 "",
407 0,
408 "",
409 "ilListItemIcon"
410 )
411 );
412
413 $tpl->setVariable("TITLE", $data["title"]);
415 }
416 if ($cnt == $max) {
417 $tpl->setCurrentBlock("row");
419 ilObject::_getIcon((int) $data["obj_id"], "small"),
420 null,
421 "",
422 "",
423 0,
424 "",
425 "ilListItemIcon"
426 ));
427 $tpl->setVariable("TITLE", "...");
429 }
430 $cnt++;
431 $item_ref_ids[$ref_id] = $ref_id;
432 }
433 } elseif (count($block->getObjectiveIds()) > 0) {
434 foreach ($block->getObjectiveIds() as $objective_id) {
435 $title = \ilCourseObjective::lookupObjectiveTitle($objective_id);
436 if ($cnt < $max) {
437 $tpl->setCurrentBlock("row");
439 ilUtil::getImagePath("icon_lobj.svg"),
440 null,
441 "",
442 "",
443 0,
444 "",
445 "ilListItemIcon"
446 ));
447 $tpl->setVariable("TITLE", $title);
449 }
450 if ($cnt == $max) {
451 $tpl->setCurrentBlock("row");
453 ilUtil::getImagePath("icon_lobj.svg"),
454 null,
455 "",
456 "",
457 0,
458 "",
459 "ilListItemIcon"
460 ));
461 $tpl->setVariable("TITLE", "...");
463 }
464 $cnt++;
465 }
466 } else {
467 $tpl->setCurrentBlock("row");
468 $tpl->setVariable("TITLE", $lng->txt("no_items"));
470 }
471 if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock) {
472 $type = $block->getId();
473
474 if (!$obj_definition->isPlugin($type)) {
475 $title = $lng->txt("objs_" . $type);
476 } else {
478 $title = $pl->txt("objs_" . $type);
479 }
480
481 $tpl->setVariable("HEADER", $title);
482 $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
483 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
484 $type = $block->getId();
485 $tpl->setVariable("HEADER", $lng->txt("objs_sess"));
486 $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
487 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
488 $id = $block->getId();
491 ));
492 $a_content = str_replace("[item-group-" . $id . "]", $tpl->get(), $a_content);
493 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
494 $id = $block->getId();
495 $tpl->setVariable("HEADER", $lng->txt("crs_objectives"));
496 $a_content = str_replace("[list-_lobj]", $tpl->get(), $a_content);
497 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
498 $id = $block->getId();
499 $tpl->setVariable("HEADER", $lng->txt("cont_content"));
500 $a_content = str_replace("[list-_other]", $tpl->get(), $a_content);
501 }
502 }
503 return $a_content;
504 }
505}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
parses the objects.xml it handles the xml-description of all ilias objects
isPlugin(string $obj_name)
get RBAC status by type returns true if object type is an (activated) plugin type
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getPluginObjectByType(string $type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin.
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilObjectDefinition $obj_definition
static insertResourcesIntoPageContent(string $a_content)
Insert resources (see also ilContainerContentGUI::determinePageEmbeddedBlocks for presentation)
edit(bool $a_insert=false)
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
ILIAS Container InternalDomainService $container_domain
initForm(bool $a_insert=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
special template class to simplify handling of ITX/PEAR
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static img(string $a_src, ?string $a_alt=null, $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
$c
Definition: deliver.php:25
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
setContent(string $a_html)
Sets content for standard template.
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$container
@noRector
Definition: wac.php:37