ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 sort($options);
173 $si = new ilSelectInputGUI($this->lng->txt("obj_itgr"), "itgr");
174 $si->setOptions($options);
175 $selected = ($a_insert)
176 ? ""
177 : $this->content_obj->getItemGroupRefId();
178 $op_itemgroup->addSubItem($si);
179 if ($a_insert) {
180 $radg->setValue("itgr");
181 }
182 }
183
184 // learning objectives
185 if ($this->supportsObjectives()) {
186 $lng->loadLanguageModule("crs");
187 $op_lobj = new ilRadioOption($lng->txt("crs_objectives"), "_lobj", "");
188 $radg->addOption($op_lobj);
189 if (!$a_insert && $this->content_obj->getResourceListType() === "_lobj") {
190 $radg->setValue("_lobj");
191 }
192 }
193
194 // other
195 if ($this->supportsOther() && $this->hasOtherBlock()) {
196 $op_other = new ilRadioOption($lng->txt("cont_other_resources"), "_other", "");
197 $radg->addOption($op_other);
198 if (!$a_insert && $this->content_obj->getResourceListType() === "_other") {
199 $radg->setValue("_other");
200 }
201 }
202
203 // save/cancel buttons
204 if ($a_insert) {
205 $form->addCommandButton("create", $lng->txt("save"));
206 $form->addCommandButton("cancelCreate", $lng->txt("cancel"));
207 } else {
208 $form->addCommandButton("update_resources", $lng->txt("save"));
209 $form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
210 }
211 return $form;
212 }
213
215 {
216 $form = $this->initForm(true);
217 return $form;
218 }
219
221 {
222 $form = $this->initForm(false);
223 return $form;
224 }
225
230 protected function getContainerViewManager(): \ILIAS\Container\Content\ViewManager
231 {
234 $view_manager = $this->container_domain->content()->view($container);
235 return $view_manager;
236 }
237
238 protected function supportsItemGroups(): bool
239 {
240 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
241 if ($part instanceof \ILIAS\Container\Content\ItemGroupBlocks) {
242 return true;
243 }
244 }
245 return false;
246 }
247
248 protected function supportsOther(): bool
249 {
250 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
251 if ($part instanceof \ILIAS\Container\Content\OtherBlock) {
252 return true;
253 }
254 }
255 return false;
256 }
257
258 protected function supportsObjectives(): bool
259 {
260 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
261 if ($part instanceof \ILIAS\Container\Content\ObjectivesBlock) {
262 return true;
263 }
264 }
265 return false;
266 }
267
268 protected function supportsTypeBlocks(): bool
269 {
270 foreach ($this->getContainerViewManager()->getBlockSequence()->getParts() as $part) {
271 if ($part instanceof \ILIAS\Container\Content\TypeBlocks) {
272 return true;
273 }
274 }
275 return false;
276 }
277
278 public function create(): void
279 {
280 $this->content_obj = new ilPCResources($this->getPage());
281 $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
282
283 if ($this->request->getString("res_type") === "_other") {
284 $this->content_obj->setResourceListType("_other");
285 } elseif ($this->request->getString("res_type") === "_lobj") {
286 $this->content_obj->setResourceListType("_lobj");
287 } elseif ($this->request->getString("res_type") !== "itgr") {
288 $this->content_obj->setResourceListType(
289 $this->request->getString("type")
290 );
291 } else {
292 $this->content_obj->setItemGroupRefId(
293 $this->request->getString("itgr")
294 );
295 }
296 $this->updated = $this->pg_obj->update();
297 if ($this->updated === true) {
298 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
299 } else {
300 $this->insert();
301 }
302 }
303
304 public function update(): void
305 {
306 if ($this->request->getString("res_type") === "_other") {
307 $this->content_obj->setResourceListType("_other");
308 } elseif ($this->request->getString("res_type") === "_lobj") {
309 $this->content_obj->setResourceListType("_lobj");
310 } elseif ($this->request->getString("res_type") !== "itgr") {
311 $this->content_obj->setResourceListType(
312 $this->request->getString("type")
313 );
314 } else {
315 $this->content_obj->setItemGroupRefId(
316 $this->request->getString("itgr")
317 );
318 }
319 $this->updated = $this->pg_obj->update();
320 if ($this->updated === true) {
321 $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
322 } else {
323 $this->pg_obj->addHierIDs();
324 $this->edit();
325 }
326 }
327
328 protected function hasOtherBlock(): bool
329 {
330 global $DIC;
331
332 $ref_id = $DIC
333 ->copage()
334 ->internal()
335 ->gui()
336 ->pc()
337 ->editRequest()
338 ->getRefId();
339 $item_presentation_manager = $DIC->container()->internal()
340 ->domain()
341 ->content()
342 ->itemPresentation(
344 null,
345 false
346 );
347 $block_sequence = $item_presentation_manager->getItemBlockSequence();
348 foreach ($block_sequence->getBlocks() as $block) {
349 if (($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock)) {
350 return true;
351 }
352 }
353 return false;
354 }
355
359 public static function insertResourcesIntoPageContent(
360 string $a_content
361 ): string {
362 global $DIC;
363
364 $obj_definition = $DIC["objDefinition"];
365 $item_ref_ids = [];
366
367 $lng = $DIC->language();
368 $ref_id = $DIC
369 ->copage()
370 ->internal()
371 ->gui()
372 ->pc()
373 ->editRequest()
374 ->getRefId();
375 $item_presentation_manager = $DIC->container()->internal()
376 ->domain()
377 ->content()
378 ->itemPresentation(
380 null
381 );
382 $block_sequence = $item_presentation_manager->getItemBlockSequence();
383
384 foreach ($block_sequence->getBlocks() as $block) {
385 // render block
386 $tpl = new ilTemplate("tpl.resource_block.html", true, true, "components/ILIAS/COPage");
387 $cnt = 0;
388 $max = 5;
389 if (!($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) &&
390 count($block->getItemRefIds()) > 0) {
391 foreach ($block->getItemRefIds() as $ref_id) {
392 $data = $item_presentation_manager->getRawDataByRefId($ref_id);
393 if ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
394 if ($data["type"] === "itgr" || in_array($ref_id, $item_ref_ids)) {
395 continue;
396 }
397 }
398
399 if ($cnt < $max) {
400 $tpl->setCurrentBlock("row");
402 "IMG",
404 ilObject::_getIcon((int) $data["obj_id"], "small"),
405 null,
406 "",
407 "",
408 0,
409 "",
410 "ilListItemIcon"
411 )
412 );
413
414 $tpl->setVariable("TITLE", $data["title"]);
416 }
417 if ($cnt == $max) {
418 $tpl->setCurrentBlock("row");
420 ilObject::_getIcon((int) $data["obj_id"], "small"),
421 null,
422 "",
423 "",
424 0,
425 "",
426 "ilListItemIcon"
427 ));
428 $tpl->setVariable("TITLE", "...");
430 }
431 $cnt++;
432 $item_ref_ids[$ref_id] = $ref_id;
433 }
434 } elseif (count($block->getObjectiveIds()) > 0) {
435 foreach ($block->getObjectiveIds() as $objective_id) {
436 $title = \ilCourseObjective::lookupObjectiveTitle($objective_id);
437 if ($cnt < $max) {
438 $tpl->setCurrentBlock("row");
440 ilUtil::getImagePath("icon_lobj.svg"),
441 null,
442 "",
443 "",
444 0,
445 "",
446 "ilListItemIcon"
447 ));
448 $tpl->setVariable("TITLE", $title);
450 }
451 if ($cnt == $max) {
452 $tpl->setCurrentBlock("row");
454 ilUtil::getImagePath("icon_lobj.svg"),
455 null,
456 "",
457 "",
458 0,
459 "",
460 "ilListItemIcon"
461 ));
462 $tpl->setVariable("TITLE", "...");
464 }
465 $cnt++;
466 }
467 } else {
468 $tpl->setCurrentBlock("row");
469 $tpl->setVariable("TITLE", $lng->txt("no_items"));
471 }
472 if ($block->getBlock() instanceof \ILIAS\Container\Content\TypeBlock) {
473 $type = $block->getId();
474
475 if (!$obj_definition->isPlugin($type)) {
476 $title = $lng->txt("objs_" . $type);
477 } else {
479 $title = $pl->txt("objs_" . $type);
480 }
481
482 $tpl->setVariable("HEADER", $title);
483 $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
484 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\SessionBlock) {
485 $type = $block->getId();
486 $tpl->setVariable("HEADER", $lng->txt("objs_sess"));
487 $a_content = str_replace("[list-" . $type . "]", $tpl->get(), $a_content);
488 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ItemGroupBlock) {
489 $id = $block->getId();
492 ));
493 $a_content = str_replace("[item-group-" . $id . "]", $tpl->get(), $a_content);
494 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\ObjectivesBlock) {
495 $id = $block->getId();
496 $tpl->setVariable("HEADER", $lng->txt("crs_objectives"));
497 $a_content = str_replace("[list-_lobj]", $tpl->get(), $a_content);
498 } elseif ($block->getBlock() instanceof \ILIAS\Container\Content\OtherBlock) {
499 $id = $block->getId();
500 $tpl->setVariable("HEADER", $lng->txt("cont_content"));
501 $a_content = str_replace("[list-_other]", $tpl->get(), $a_content);
502 }
503 }
504 return $a_content;
505 }
506}
$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