ILIAS  release_8 Revision v8.24
class.ilObjectOwnershipManagementGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
29{
30 public const P_OWNID = 'ownid';
31 protected ilObjUser $user;
32 protected ilCtrl $ctrl;
35 protected ilLanguage $lng;
37 protected ilTree $tree;
38 protected int $user_id;
39 protected int $own_id = 0;
40 protected bool $read_only;
42
43 public function __construct(int $user_id = null, bool $read_only = false)
44 {
45 global $DIC;
46
47 $this->user = $DIC->user();
48 $this->ctrl = $DIC->ctrl();
49 $this->tpl = $DIC["tpl"];
50 $this->toolbar = $DIC->toolbar();
51 $this->lng = $DIC->language();
52 $this->obj_definition = $DIC["objDefinition"];
53 $this->tree = $DIC->repositoryTree();
54 $this->retriever = new ilObjectRequestRetriever($DIC->http()->wrapper(), $DIC->refinery());
55
56 $this->user_id = $this->user->getId();
57 if (!is_null($user_id)) {
58 $this->user_id = $user_id;
59 }
60 $this->read_only = $read_only;
61 $this->own_id = $this->retriever->getMaybeInt(self::P_OWNID, 0);
62 }
63
64 public function executeCommand(): void
65 {
66 $this->ctrl->getNextClass($this);
67 $cmd = $this->ctrl->getCmd();
68
69 if (!$cmd) {
70 $cmd = "listObjects";
71 }
72 $this->$cmd();
73 }
74
75 public function listObjects(): void
76 {
77 $sel_type = '';
78
79 $objects = ilObject::getAllOwnedRepositoryObjects($this->user_id);
80
81 if (sizeof($objects)) {
82 $this->toolbar->setFormAction($this->ctrl->getFormAction($this, "listObjects"));
83
84 $sel = new ilSelectInputGUI($this->lng->txt("type"), "type");
85 $this->toolbar->addStickyItem($sel, true);
86
88 $button->setCaption("ok");
89 $button->setCommand("listObjects");
90 $this->toolbar->addStickyItem($button);
91
92 $options = [];
93 foreach (array_keys($objects) as $type) {
94 if (!$this->obj_definition->isPlugin($type)) {
95 $options[$type] = $this->lng->txt("obj_" . $type);
96 } else {
97 $options[$type] = ilObjectPlugin::lookupTxtById($type, "obj_" . $type);
98 }
99 }
100 asort($options);
101 $sel->setOptions($options);
102
103 $sel_type = $this->retriever->getMaybeString('type', '');
104 if ($sel_type !== '') {
105 $sel->setValue($sel_type);
106 } else {
107 $sel_type = array_keys($options);
108 $sel_type = array_shift($sel_type);
109 }
110 $this->ctrl->setParameter($this, "type", $sel_type);
111 }
112
113 if ($sel_type === '') {
114 return;
115 }
116
117 if (is_array($objects[$sel_type]) && sizeof($objects[$sel_type])) {
118 ilObject::fixMissingTitles($sel_type, $objects[$sel_type]);
119 }
120
121 $tbl = new ilObjectOwnershipManagementTableGUI($this, "listObjects", $this->user_id, $objects[$sel_type]);
122 $this->tpl->setContent($tbl->getHTML());
123 }
124
125 public function applyFilter(): void
126 {
127 $tbl = new ilObjectOwnershipManagementTableGUI($this, "listObjects", $this->user_id);
128 $tbl->resetOffset();
129 $tbl->writeFilterToSession();
130 $this->listObjects();
131 }
132
133 public function resetFilter(): void
134 {
135 $tbl = new ilObjectOwnershipManagementTableGUI($this, "listObjects", $this->user_id);
136 $tbl->resetOffset();
137 $tbl->resetFilter();
138 $this->listObjects();
139 }
140
141 protected function redirectParentCmd(int $ref_id, string $cmd): void
142 {
143 $parent = $this->tree->getParentId($ref_id);
144 $this->ctrl->setParameterByClass("ilRepositoryGUI", "ref_id", $parent);
145 $this->ctrl->setParameterByClass("ilRepositoryGUI", "item_ref_id", $ref_id);
146 $this->ctrl->setParameterByClass("ilRepositoryGUI", "cmd", $cmd);
147 $this->ctrl->redirectByClass("ilRepositoryGUI");
148 }
149
150 protected function redirectCmd(int $ref_id, string $class, string $cmd = null): void
151 {
152 $node = $this->tree->getNodeData($ref_id);
153 $gui_class = "ilObj" . $this->obj_definition->getClassName($node["type"]) . "GUI";
154 $path = ["ilRepositoryGUI", $gui_class, $class];
155
156 if ($class == "ilExportGUI") {
157 try {
158 $this->ctrl->getLinkTargetByClass($path);
159 } catch (Exception $e) {
160 switch ($node["type"]) {
161 case "glo":
162 $export_cmd = "exportList";
163 $path = ["ilRepositoryGUI", "ilGlossaryEditorGUI", $gui_class];
164 break;
165
166 default:
167 $export_cmd = "export";
168 $path = ["ilRepositoryGUI", $gui_class];
169 break;
170 }
171 $this->ctrl->setParameterByClass($gui_class, "ref_id", $ref_id);
172 $this->ctrl->setParameterByClass($gui_class, "cmd", $export_cmd);
173 $this->ctrl->redirectByClass($path);
174 }
175 }
176
177 $this->ctrl->setParameterByClass($class, "ref_id", $ref_id);
178 $this->ctrl->setParameterByClass($class, "cmd", $cmd);
179 $this->ctrl->redirectByClass($path);
180 }
181
182 public function delete(): void
183 {
184 $this->checkReadOnly();
185
186 $this->redirectParentCmd(
187 $this->own_id,
188 "delete"
189 );
190 }
191
192 public function move(): void
193 {
194 $this->checkReadOnly();
195
196 $this->redirectParentCmd(
197 $this->own_id,
198 "cut"
199 );
200 }
201
202 public function export(): void
203 {
204 $this->checkReadOnly();
205
206 $this->redirectCmd(
207 $this->own_id,
208 ilExportGUI::class
209 );
210 }
211
212 public function changeOwner(): void
213 {
214 $this->checkReadOnly();
215
216 $this->redirectCmd(
217 $this->own_id,
218 ilPermissionGUI::class,
219 "owner"
220 );
221 }
222
223 public function isReadOnly(): bool
224 {
225 return $this->read_only;
226 }
227
228 protected function checkReadOnly(): void
229 {
230 if ($this->read_only) {
231 throw new ilObjectException(
232 'Cannot perform actions when in read only mode'
233 );
234 }
235 }
236}
Class ilCtrl provides processing control methods.
language handling
User class.
parses the objects.xml it handles the xml-description of all ilias objects
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
redirectCmd(int $ref_id, string $class, string $cmd=null)
__construct(int $user_id=null, bool $read_only=false)
static lookupTxtById(string $plugin_id, string $lang_var)
Base class for all sub item list gui's.
static getAllOwnedRepositoryObjects(int $user_id)
static fixMissingTitles($type, array &$obj_title_map)
Try to fix missing object titles.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:32
$type