ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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  // Store current page and sortation for possible back navigation
136  $this->ctrl->saveParameter($this, ResourceListingUI::P_PAGE);
137  $this->ctrl->saveParameter($this, ResourceListingUI::P_SORTATION);
138 
139  $rid = $this->getResourceIdFromRequest();
140  $resource = $this->irss->manage()->getResource($rid);
141  $stakeholders = $resource->getStakeholders();
142  if (count($stakeholders) === 1) { // Onyl one Stakeholder, we redirect to it
144  $stakeholder = array_shift($stakeholders);
145  $uri = $stakeholder->getLocationURIForResourceUsage($rid);
146  if ($uri !== null) {
147  $this->ctrl->redirectToURL($uri);
148  }
149  $this->initBackTab();
150  $this->main_tpl->setOnScreenMessage('info', $this->language->txt('resource_no_stakeholder_uri'));
151  } else {
152  // TODO list all stakeholders and it's locations
153  $this->main_tpl->setOnScreenMessage('failure', 'Multiple Stakeholders found, can\'t redirect', true);
154  $this->ctrl->redirect($this, self::CMD_INDEX);
155  }
156  }
157 
158  private function showRevisions(): void
159  {
160  $this->initBackTab();
161 
162  $rid = $this->getResourceIdFromRequest();
163  $resource = $this->irss->manage()->getResource($rid);
164 
165  $view_definition = new ViewDefinition(
166  self::class,
167  self::CMD_SHOW_REVISIONS,
168  $this->language->txt('resource_overview')
169  );
170  $view_definition->setMode(ViewDefinition::MODE_AS_TABLE);
171  $listing = new RevisionListingUI(
172  $view_definition,
173  $resource
174  );
175 
176 
177  $this->main_tpl->setContent(
178  $this->ui_renderer->render($listing->getComponents())
179  );
180  }
181 
182 
183  private function download(): void
184  {
185  $rid = $this->getResourceIdFromRequest();
186  if (!$rid instanceof ResourceIdentification) {
187  $this->main_tpl->setOnScreenMessage('failure', $this->language->txt('msg_no_perm_read'), true);
188  $this->ctrl->redirect($this, self::CMD_INDEX);
189  return;
190  }
191  $this->irss->consume()->download($rid)->run();
192  }
193 
194 
196  {
197  $rid = $this->wrapper->query()->has(self::P_RESOURCE_ID) ? $this->wrapper->query()->retrieve(
198  self::P_RESOURCE_ID,
199  $this->refinery->to()->string()
200  ) : ($this->wrapper->post()->has(self::P_RESOURCE_ID)
201  ? $this->wrapper->post()->retrieve(self::P_RESOURCE_ID, $this->refinery->to()->string())
202  : null);
203 
204  if ($rid === null) {
205  return null;
206  }
207 
208  return $this->irss->manage()->find($rid);
209  }
210 }
ilGlobalTemplateInterface $main_tpl
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...
ArrayBasedRequestWrapper $query
global $DIC
Definition: shib_login.php:25
Class FileUpload.
Definition: FileUpload.php:34
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...
language()
description: > Example for rendring a language glyph.
Definition: language.php:25
getLocationURIForResourceUsage(ResourceIdentification $identification)