ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilResourceOverviewGUI.php
Go to the documentation of this file.
1 <?php
2 
34 
42 {
43  use Hasher;
44 
45  public const CMD_INDEX = 'index';
46  public const CMD_REMOVE = 'remove';
47  public const CMD_DOWNLOAD = 'download';
48  public const CMD_SHOW_REVISIONS = 'showRevisions';
49  public const CMD_GOTO_RESOURCE = 'gotoResource';
50 
51 
52  public const P_RESOURCE_ID = 'irss_resource_id';
53 
54 
56  protected ilLanguage $language;
59  protected Services $irss;
60  protected FileUpload $upload;
61  protected \ILIAS\HTTP\Services $http;
62  protected Factory $refinery;
67  private ilTabsGUI $tabs;
68 
69  final public function __construct()
70  {
71  global $DIC;
72  // Services
73  $this->irss = $DIC->resourceStorage();
74  $this->ctrl = $DIC->ctrl();
75  $this->language = $DIC->language();
76  $this->language->loadLanguageModule('irss');
77  $this->main_tpl = $DIC->ui()->mainTemplate();
78  $this->upload = $DIC->upload();
79  $this->wrapper = $DIC->http()->wrapper();
80  $this->refinery = $DIC->refinery();
81  $this->ui_renderer = $DIC->ui()->renderer();
82  $this->tabs = $DIC->tabs();
83  }
84 
88  protected function initBackTab(): void
89  {
90  $this->tabs->clearTargets();
91  $this->tabs->setBackTarget(
92  $this->language->txt('back'),
93  $this->ctrl->getLinkTarget($this, self::CMD_INDEX)
94  );
95  }
96 
97  final public function executeCommand(): void
98  {
99  switch ($this->ctrl->getCmd(self::CMD_INDEX)) {
100  case self::CMD_INDEX:
101  $this->index();
102  break;
103  case self::CMD_DOWNLOAD:
104  $this->download();
105  break;
106  case self::CMD_SHOW_REVISIONS:
107  $this->showRevisions();
108  break;
109  case self::CMD_GOTO_RESOURCE:
110  $this->gotoResource();
111  break;
112  }
113  }
114 
115  private function index(): void
116  {
117  $listing = new ResourceListingUI(
118  new ViewDefinition(
119  self::class,
120  self::CMD_INDEX,
121  $this->language->txt('resource_overview')
122  ),
125  );
126 
127  $this->main_tpl->setContent(
128  $this->ui_renderer->render($listing->getComponents())
129  );
130  }
131 
132 
133  private function gotoResource(): void
134  {
135  $rid = $this->getResourceIdFromRequest();
136  $resource = $this->irss->manage()->getResource($rid);
137  $stakeholders = $resource->getStakeholders();
138  if (count($stakeholders) === 1) { // Onyl one Stakeholder, we redirect to it
140  $stakeholder = array_shift($stakeholders);
141  $uri = $stakeholder->getLocationURIForResourceUsage($rid);
142  if ($uri !== null) {
143  $this->ctrl->redirectToURL($uri);
144  }
145  $this->initBackTab();
146  $this->main_tpl->setOnScreenMessage('info', $this->language->txt('resource_no_stakeholder_uri'));
147  } else {
148  // TODO list all stakeholders and it's locations
149  $this->main_tpl->setOnScreenMessage('failure', 'Multiple Stakeholders found, can\'t redirect', true);
150  $this->ctrl->redirect($this, self::CMD_INDEX);
151  }
152  }
153 
154  private function showRevisions(): void
155  {
156  $this->initBackTab();
157 
158  $rid = $this->getResourceIdFromRequest();
159  $resource = $this->irss->manage()->getResource($rid);
160 
161  $view_definition = new ViewDefinition(
162  self::class,
163  self::CMD_SHOW_REVISIONS,
164  $this->language->txt('resource_overview')
165  );
166  $view_definition->setMode(ViewDefinition::MODE_AS_TABLE);
167  $listing = new RevisionListingUI(
168  $view_definition,
169  $resource
170  );
171 
172 
173  $this->main_tpl->setContent(
174  $this->ui_renderer->render($listing->getComponents())
175  );
176  }
177 
178 
179  private function download(): void
180  {
181  $rid = $this->getResourceIdFromRequest();
182  if (!$rid instanceof ResourceIdentification) {
183  $this->main_tpl->setOnScreenMessage('failure', $this->language->txt('msg_no_perm_read'), true);
184  $this->ctrl->redirect($this, self::CMD_INDEX);
185  return;
186  }
187  $this->irss->consume()->download($rid)->run();
188  }
189 
190 
192  {
193  $rid = $this->wrapper->query()->has(self::P_RESOURCE_ID) ? $this->wrapper->query()->retrieve(
194  self::P_RESOURCE_ID,
195  $this->refinery->to()->string()
196  ) : ($this->wrapper->post()->has(self::P_RESOURCE_ID)
197  ? $this->wrapper->post()->retrieve(self::P_RESOURCE_ID, $this->refinery->to()->string())
198  : null);
199 
200  if ($rid === null) {
201  return null;
202  }
203 
204  return $this->irss->manage()->find($rid);
205  }
206 }
ilGlobalTemplateInterface $main_tpl
An entity that renders components to a string output.
Definition: Renderer.php:30
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...
ArrayBasedRequestWrapper $query
Class FileUpload.
Definition: FileUpload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLocationURIForResourceUsage(ResourceIdentification $identification)