ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLocalUnitConfigurationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 private const REQUEST_PARAM_SUB_CONTEXT_ID = 'question_fi';
27
28 protected function getDefaultCommand(): string
29 {
30 return 'showLocalUnitCategories';
31 }
32
33 public function getUnitCategoryOverviewCommand(): string
34 {
35 if ($this->isCRUDContext()) {
36 return 'showLocalUnitCategories';
37 }
38
39 return 'showGlobalUnitCategories';
40 }
41
42 public function isCRUDContext(): bool
43 {
44 if (!$this->request->isset(self::REQUEST_PARAM_SUB_CONTEXT_ID) ||
45 $this->request->raw(self::REQUEST_PARAM_SUB_CONTEXT_ID) == $this->repository->getConsumerId()) {
46 return true;
47 }
48
49 return false;
50 }
51
52 public function getUniqueId(): string
53 {
54 $id = $this->repository->getConsumerId();
55 if ($this->isCRUDContext()) {
56 $id .= '_local';
57 } else {
58 $id .= '_global';
59 }
60
61 return $id;
62 }
63
64 public function executeCommand(): void
65 {
66 global $DIC;
67
69 $ilHelp = $DIC['ilHelp'];
70
71 $this->ctrl->saveParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID);
72
73 $ilHelp->setScreenIdComponent('qpl');
74 parent::executeCommand();
75 }
76
77 protected function handleSubtabs(): void
78 {
79 global $DIC;
80
81 $ilTabs = $DIC->tabs();
82
83 $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, $this->repository->getConsumerId());
84 $ilTabs->addSubTab('view_unit_ctx_local', $this->lng->txt('un_local_units'), $this->ctrl->getLinkTarget($this, 'showLocalUnitCategories'));
85 $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, 0);
86 $ilTabs->addSubTab('view_unit_ctx_global', $this->lng->txt('un_global_units'), $this->ctrl->getLinkTarget($this, 'showGlobalUnitCategories'));
87 $this->ctrl->setParameter($this, self::REQUEST_PARAM_SUB_CONTEXT_ID, '');
88
89 if ($this->isCRUDContext()) {
90 $ilTabs->activateSubTab('view_unit_ctx_local');
91 } else {
92 $ilTabs->activateSubTab('view_unit_ctx_global');
93 }
94 }
95
96 protected function showLocalUnitCategories(): void
97 {
98 global $DIC;
99
100 $ilToolbar = $DIC->toolbar();
101
102 $ilToolbar->addButton($this->lng->txt('un_add_category'), $this->ctrl->getLinkTarget($this, 'showUnitCategoryCreationForm'));
103
104 $repo = $this->repository;
105 $categories = array_filter(
106 $this->repository->getAllUnitCategories(),
107 static function (assFormulaQuestionUnitCategory $category) use ($repo): bool {
108 return $category->getQuestionFi() === $repo->getConsumerId();
109 }
110 );
111 $data = [];
112 foreach ($categories as $category) {
114 $data[] = [
115 'category_id' => $category->getId(),
116 'category' => $category->getDisplayString()
117 ];
118 }
119
120 $this->showUnitCategories($data);
121 }
122
126 protected function showUnitCategories(array $categories): void
127 {
129 $table->setData($categories);
130
131 $this->tpl->setContent($table->getHTML());
132 }
133
134 protected function confirmImportGlobalCategory(): void
135 {
136 if (!$this->request->isset('category_id')) {
137 $this->showGlobalUnitCategories();
138 return;
139 }
140 $this->confirmImportGlobalCategories([$this->request->raw('category_id')]);
141 }
142
143 protected function confirmImportGlobalCategories(array $category_ids): void
144 {
145 // @todo: Confirmation Currently not implemented, so forward to import
146 $this->importGlobalCategories($category_ids);
147 }
148
149 protected function importGlobalCategories(array $category_ids): void
150 {
151 if ($this->isCRUDContext()) {
152 $this->{$this->getDefaultCommand()}();
153 return;
154 }
155
156 $i = 0;
157 foreach ($category_ids as $category_id) {
158 try {
159 $category = $this->repository->getUnitCategoryById((int) $category_id);
160 } catch (ilException $e) {
161 continue;
162 }
163
164 // Copy admin-category to custom-category (with question_fi)
165 $new_cat_id = $this->repository->copyCategory($category->getId(), $this->repository->getConsumerId());
166
167 // Copy units to custom_category
168 $this->repository->copyUnitsByCategories($category->getId(), $new_cat_id, $this->repository->getConsumerId());
169 ++$i;
170 }
171
172 if ($i) {
173 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
174 }
175
176 $this->ctrl->setParameter($this, 'question_fi', 0);
177 $this->ctrl->redirect($this, 'showLocalUnitCategories');
178 }
179}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Base class for ILIAS Exception handling.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilLocalUnitConfigurationGUI.
Class ilUnitConfigurationGUI.
global $DIC
Definition: shib_login.php:26