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