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