ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjectOwnershipManagementGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 {
32  public const P_OWNID = 'ownid';
33  protected ilObjUser $user;
34  protected ilCtrl $ctrl;
38  protected ilLanguage $lng;
40  protected ilTree $tree;
41  protected int $user_id;
42  protected int $own_id = 0;
43  protected bool $read_only;
45 
46  public function __construct(int $user_id = null, bool $read_only = false)
47  {
48  global $DIC;
49 
50  $this->user = $DIC['ilUser'];
51  $this->ctrl = $DIC['ilCtrl'];
52  $this->tpl = $DIC['tpl'];
53  $this->ui_factory = $DIC['ui.factory'];
54  $this->toolbar = $DIC['ilToolbar'];
55  $this->lng = $DIC['lng'];
56  $this->obj_definition = $DIC['objDefinition'];
57  $this->tree = $DIC['tree'];
58  $this->retriever = new ilObjectRequestRetriever($DIC->http()->wrapper(), $DIC['refinery']);
59 
60  $this->lng->loadLanguageModule('obj');
61 
62  $this->user_id = $this->user->getId();
63  if (!is_null($user_id)) {
64  $this->user_id = $user_id;
65  }
66  $this->read_only = $read_only;
67  $this->own_id = $this->retriever->getMaybeInt(self::P_OWNID, 0);
68  }
69 
70  public function executeCommand(): void
71  {
72  $this->ctrl->getNextClass($this);
73  $cmd = $this->ctrl->getCmd();
74 
75  if (!$cmd) {
76  $cmd = 'listObjects';
77  }
78  $this->$cmd();
79  }
80 
81  public function listObjects(): void
82  {
83  $objects = ilObject::getAllOwnedRepositoryObjects($this->user_id);
84 
85  $tbl = new ilObjectOwnershipManagementTableGUI($this, 'listObjects', $this->user_id);
86 
87  if ($objects === []) {
88  $tbl->setTitle($this->lng->txt('user_owns_no_objects'));
89  $this->tpl->setContent($tbl->getHTML());
90  return;
91  }
92 
93  $object_types = array_keys($objects);
94 
95  $options = [];
96  foreach ($object_types as $type) {
97  $this->ctrl->setParameterByClass(self::class, 'type', $type);
98  $target = $this->ctrl->getLinkTargetByClass(self::class, 'listObjects');
99  $label = $this->getLabelForObjectType($type);
100  $options[$type] = $this->ui_factory->button()->shy($label, $target);
101  }
102  asort($options);
103 
104  $selected_type = $this->retriever->getMaybeString('type') ?? array_keys($options)[0];
105  unset($options[$selected_type]);
106 
107  $dropdown = $this->ui_factory->dropdown()->standard($options)->withLabel(
108  $this->lng->txt('select_object_type')
109  );
110 
111  $this->toolbar->addStickyItem($dropdown);
112 
113  if (is_array($objects[$selected_type])
114  && $objects[$selected_type] !== []) {
115  ilObject::fixMissingTitles($selected_type, $objects[$selected_type]);
116  }
117 
118  $tbl->setTitle($this->getLabelForObjectType($selected_type));
119  $tbl->initItems($objects[$selected_type]);
120  $this->ctrl->setParameterByClass(self::class, 'type', $selected_type);
121  $this->tpl->setContent($tbl->getHTML());
122  }
123 
124  private function getLabelForObjectType(string $type): string
125  {
126  if ($this->obj_definition->isPlugin($type)) {
127  return $this->lng->txt($type, 'obj_' . $type);
128  }
129 
130  return $this->lng->txt('objs_' . $type);
131  }
132 
133  public function applyFilter(): void
134  {
135  $tbl = new ilObjectOwnershipManagementTableGUI($this, 'listObjects', $this->user_id);
136  $tbl->resetOffset();
137  $tbl->writeFilterToSession();
138  $this->listObjects();
139  }
140 
141  public function resetFilter(): void
142  {
143  $tbl = new ilObjectOwnershipManagementTableGUI($this, 'listObjects', $this->user_id);
144  $tbl->resetOffset();
145  $tbl->resetFilter();
146  $this->listObjects();
147  }
148 
149  protected function redirectParentCmd(int $ref_id, string $cmd): void
150  {
151  $parent = $this->tree->getParentId($ref_id);
152  $this->ctrl->setParameterByClass('ilRepositoryGUI', 'ref_id', $parent);
153  $this->ctrl->setParameterByClass('ilRepositoryGUI', 'item_ref_id', $ref_id);
154  $this->ctrl->setParameterByClass('ilRepositoryGUI', 'cmd', $cmd);
155  $this->ctrl->redirectByClass('ilRepositoryGUI');
156  }
157 
158  protected function redirectCmd(int $ref_id, string $class, string $cmd = null): void
159  {
160  $node = $this->tree->getNodeData($ref_id);
161  $gui_class = 'ilObj' . $this->obj_definition->getClassName($node['type']) . 'GUI';
162  $path = ['ilRepositoryGUI', $gui_class, $class];
163 
164  if ($class == 'ilExportGUI') {
165  try {
166  $this->ctrl->getLinkTargetByClass($path);
167  } catch (Exception $e) {
168  switch ($node['type']) {
169  case 'glo':
170  $export_cmd = 'exportList';
171  $path = ['ilRepositoryGUI', 'ilGlossaryEditorGUI', $gui_class];
172  break;
173 
174  default:
175  $export_cmd = 'export';
176  $path = ['ilRepositoryGUI', $gui_class];
177  break;
178  }
179  $this->ctrl->setParameterByClass($gui_class, 'ref_id', $ref_id);
180  $this->ctrl->setParameterByClass($gui_class, 'cmd', $export_cmd);
181  $this->ctrl->redirectByClass($path);
182  }
183  }
184 
185  $this->ctrl->setParameterByClass($class, 'ref_id', $ref_id);
186  $this->ctrl->setParameterByClass($class, 'cmd', $cmd);
187  $this->ctrl->redirectByClass($path);
188  }
189 
190  public function delete(): void
191  {
192  $this->checkReadOnly();
193 
194  $this->redirectParentCmd(
195  $this->own_id,
196  'delete'
197  );
198  }
199 
200  public function move(): void
201  {
202  $this->checkReadOnly();
203 
204  $this->redirectParentCmd(
205  $this->own_id,
206  'cut'
207  );
208  }
209 
210  public function export(): void
211  {
212  $this->checkReadOnly();
213 
214  $this->redirectCmd(
215  $this->own_id,
216  ilExportGUI::class
217  );
218  }
219 
220  public function changeOwner(): void
221  {
222  $this->checkReadOnly();
223 
224  $this->redirectCmd(
225  $this->own_id,
226  ilPermissionGUI::class,
227  'owner'
228  );
229  }
230 
231  public function isReadOnly(): bool
232  {
233  return $this->read_only;
234  }
235 
236  protected function checkReadOnly(): void
237  {
238  if ($this->read_only) {
239  throw new ilObjectException(
240  'Cannot perform actions when in read only mode'
241  );
242  }
243  }
244 }
__construct(int $user_id=null, bool $read_only=false)
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)
Class ilObjectOwnershipManagementGUI.
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
$ref_id
Definition: ltiauth.php:67
Base class for all sub item list gui&#39;s.
static getAllOwnedRepositoryObjects(int $user_id)
static fixMissingTitles($type, array &$obj_title_map)
Try to fix missing object titles.