ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilObjFilePreviewRendererGUI Class Reference
+ Inheritance diagram for ilObjFilePreviewRendererGUI:
+ Collaboration diagram for ilObjFilePreviewRendererGUI:

Public Member Functions

 __construct (private readonly ?int $object_id=null)
 
 has ()
 
 getTriggerComponents (bool $as_button=false)
 
 getRenderedTriggerComponents (bool $as_button=false)
 
 executeCommand ()
 

Data Fields

const P_RID = "rid"
 
const CMD_GET_ASYNC_MODAL = 'getAsyncModal'
 

Protected Member Functions

 resolveRidString (?int $object_id)
 
 isAccessGranted ()
 

Private Member Functions

 getAsyncModal ()
 

Private Attributes

ilDBInterface $db
 
Factory $ui_factory
 
Renderer $ui_renderer
 
ilCtrlInterface $ctrl
 
ResourceIdentification $rid = null
 
Services $irss
 
ILIAS HTTP Services $http
 
WrapperFactory $http_wrapper
 
ILIAS Refinery Factory $refinery
 
FlavourDefinition $flavour_definition
 
ilAccessHandler $access
 
ilLanguage $language
 
int $preview_size
 
int $pages_to_extract
 
bool $activated = false
 
string $file_name = ''
 
FlavourDefinition $fallback_flavour_definition
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilObjFilePreviewRendererGUI::__construct ( private readonly ?int  $object_id = null)

Definition at line 99 of file class.ilObjFilePreviewRendererGUI.php.

References $DIC, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), null, ILIAS\Repository\refinery(), and resolveRidString().

101  {
102  global $DIC;
103 
104  $settings = (new SettingsFactory())->getSettings();
105  $this->activated = $settings->isPreviewEnabled();
106 
107  $this->db = $DIC->database();
108  $this->ctrl = $DIC->ctrl();
109 
110  $this->ui_factory = $DIC->ui()->factory();
111  $this->ui_renderer = $DIC->ui()->renderer();
112  $this->irss = $DIC->resourceStorage();
113  $this->http = $DIC->http();
114  $this->http_wrapper = $DIC->http()->wrapper();
115  $this->refinery = $DIC->refinery();
116  $this->access = $DIC->access();
117  $this->language = $DIC->language();
118  $this->language->loadLanguageModule('file');
119 
120  $rid_string = $this->resolveRidString($this->object_id);
121 
122  $this->rid = $this->irss->manage()->find($rid_string);
123  $this->flavour_definition = new PagesToExtract(
124  $settings->isPersisting(),
125  $settings->getImageSize(),
126  $settings->getMaximumPreviews()
127  );
128  $this->fallback_flavour_definition = new FitToSquare(
129  $settings->isPersisting(),
130  $settings->getImageSize()
131  );
132  // Resolve File Name
133  if ($this->rid !== null) {
134  $this->file_name = $this->irss->manage()->getCurrentRevision($this->rid)->getTitle();
135  }
136  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:22
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilObjFilePreviewRendererGUI::executeCommand ( )

Definition at line 197 of file class.ilObjFilePreviewRendererGUI.php.

References ILIAS\Repository\ctrl().

197  : void
198  {
199  $cmd = $this->ctrl->getCmd();
200  match ($cmd) {
201  self::CMD_GET_ASYNC_MODAL => $this->{$cmd}(),
202  default => throw new InvalidArgumentException('Command not found: ' . $cmd),
203  };
204  }
+ Here is the call graph for this function:

◆ getAsyncModal()

ilObjFilePreviewRendererGUI::getAsyncModal ( )
private

Definition at line 248 of file class.ilObjFilePreviewRendererGUI.php.

References $file_name, $response, $url, ILIAS\FileDelivery\http(), isAccessGranted(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), and null.

248  : void
249  {
250  if (!$this->isAccessGranted()) {
251  throw new LogicException('User cannot see this resource');
252  }
253 
254  // Resolve Flavour for Definition
255  $flavour = $this->irss->flavours()->get($this->rid, $this->flavour_definition);
256  $flavour_urls = $this->irss->consume()->flavourUrls($flavour)->getURLsAsArray();
257  if ($flavour_urls === []) { // Try Fallback
258  $flavour = $this->irss->flavours()->get($this->rid, $this->fallback_flavour_definition);
259  $flavour_urls = $this->irss->consume()->flavourUrls($flavour)->getURLsAsArray();
260  }
261 
262  $page_title = function (?int $index): string {
263  $index_string = $index !== null ? (($index + 1) . ' ') : '';
264  return sprintf(
265  $this->language->txt('preview_caption'),
266  $index_string,
268  );
269  };
270 
271  // Build Pages for Lightbox
272  $pages = array_map(function (string $url, $i) use ($page_title): LightboxImagePage {
273  $title = $page_title($i);
274  return $this->ui_factory->modal()->lightboxImagePage(
275  $this->ui_factory->image()->responsive(
276  $url,
277  $title
278  ),
279  $title
280  );
281  }, $flavour_urls, count($flavour_urls) > 1 ? array_keys($flavour_urls) : []);
282 
283  // Fallback to a TextPage if no Flavour Images were found
284  if ($pages === []) {
285  $pages = $this->ui_factory->modal()->lightboxTextPage(
286  sprintf(
287  $this->language->txt('preview_not_possible'),
288  'components/ILIAS/File/classes/Preview/README.md'
289  ),
290  $this->language->txt('preview')
291  );
292  }
293  $modal = $this->ui_factory->modal()->lightbox($pages);
294 
295  // Send response and end script
296  $response = $this->http->response()->withBody(Streams::ofString($this->ui_renderer->renderAsync($modal)));
297  $this->http->saveResponse($response);
298  $this->http->sendResponse();
299  }
$response
Definition: xapitoken.php:93
$url
Definition: shib_logout.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
A lightbox Image page represents a page displaying a media element, such as image, video.
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ Here is the call graph for this function:

◆ getRenderedTriggerComponents()

ilObjFilePreviewRendererGUI::getRenderedTriggerComponents ( bool  $as_button = false)

Definition at line 192 of file class.ilObjFilePreviewRendererGUI.php.

References getTriggerComponents().

192  : string
193  {
194  return $this->ui_renderer->render($this->getTriggerComponents($as_button));
195  }
+ Here is the call graph for this function:

◆ getTriggerComponents()

ilObjFilePreviewRendererGUI::getTriggerComponents ( bool  $as_button = false)

Definition at line 161 of file class.ilObjFilePreviewRendererGUI.php.

References ILIAS\Repository\ctrl(), isAccessGranted(), and ILIAS\UI\examples\Symbol\Glyph\Language\language().

Referenced by getRenderedTriggerComponents().

161  : array
162  {
163  if (!$this->isAccessGranted()) {
164  throw new LogicException('User cannot see this resource');
165  }
166 
167  $this->ctrl->setParameterByClass(self::class, self::P_RID, $this->rid->serialize());
168 
169  $modal = $this->ui_factory->modal()
170  ->lightbox([])
171  ->withAsyncRenderUrl(
172  $this->ctrl->getLinkTargetByClass(self::class, self::CMD_GET_ASYNC_MODAL)
173  );
174 
175  if (!$as_button) {
176  $trigger = $this->ui_factory->symbol()->glyph()->preview(
177  "#"
178  )->withOnClick($modal->getShowSignal());
179  } else {
180  $trigger = $this->ui_factory->button()->standard(
181  $this->language->txt('show_preview'),
182  "#"
183  )->withOnClick($modal->getShowSignal());
184  }
185 
186  return [
187  $modal,
188  $trigger
189  ];
190  }
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ has()

ilObjFilePreviewRendererGUI::has ( )

Definition at line 138 of file class.ilObjFilePreviewRendererGUI.php.

References isAccessGranted(), and null.

138  : bool
139  {
140  if (!$this->activated) {
141  return false;
142  }
143  if ($this->rid === null) {
144  return false;
145  }
146  if (
147  !$this->irss->flavours()->possible(
148  $this->rid,
149  $this->flavour_definition
150  )
151  && !$this->irss->flavours()->possible(
152  $this->rid,
153  $this->fallback_flavour_definition
154  )
155  ) {
156  return false;
157  }
158  return $this->isAccessGranted();
159  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ isAccessGranted()

ilObjFilePreviewRendererGUI::isAccessGranted ( )
protected

Definition at line 227 of file class.ilObjFilePreviewRendererGUI.php.

References $ref_id, ilObject\_getAllReferences(), ILIAS\Repository\access(), and null.

Referenced by getAsyncModal(), getTriggerComponents(), and has().

227  : bool
228  {
229  // if object_id is set, we can check the access using it's ref_ids
230  if ($this->object_id !== null) {
231  foreach (ilObject::_getAllReferences($this->object_id) as $ref_id) {
232  if ($this->access->checkAccess('read', '', $ref_id)) {
233  return true;
234  }
235  }
236  return false;
237  }
238  // else we ask the stakeholders if they allow access
239  $resource = $this->irss->manage()->getResource($this->rid);
240  foreach ($resource->getStakeholders() as $stakeholder) {
241  if ($stakeholder->canBeAccessedByCurrentUser($this->rid)) {
242  return true;
243  }
244  }
245  return false;
246  }
static _getAllReferences(int $id)
get all reference ids for object ID
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveRidString()

ilObjFilePreviewRendererGUI::resolveRidString ( ?int  $object_id)
protected
Returns
mixed

Definition at line 209 of file class.ilObjFilePreviewRendererGUI.php.

References null, and ILIAS\Repository\refinery().

Referenced by __construct().

209  : string
210  {
211  if ($object_id !== null) {
212  return $this->db->fetchObject(
213  $this->db->queryF(
214  'SELECT rid FROM file_data WHERE file_id = %s',
215  ['integer'],
216  [$object_id]
217  )
218  )->rid ?? '';
219  }
220  return $this->http_wrapper->query()->has(self::P_RID)
221  ? $this->http_wrapper->query()->retrieve(
222  self::P_RID,
223  $this->refinery->to()->string()
224  ) : '';
225  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilObjFilePreviewRendererGUI::$access
private

Definition at line 79 of file class.ilObjFilePreviewRendererGUI.php.

◆ $activated

bool ilObjFilePreviewRendererGUI::$activated = false
private

Definition at line 92 of file class.ilObjFilePreviewRendererGUI.php.

◆ $ctrl

ilCtrlInterface ilObjFilePreviewRendererGUI::$ctrl
private

Definition at line 54 of file class.ilObjFilePreviewRendererGUI.php.

◆ $db

ilDBInterface ilObjFilePreviewRendererGUI::$db
private

Definition at line 42 of file class.ilObjFilePreviewRendererGUI.php.

◆ $fallback_flavour_definition

FlavourDefinition ilObjFilePreviewRendererGUI::$fallback_flavour_definition
private

Definition at line 97 of file class.ilObjFilePreviewRendererGUI.php.

◆ $file_name

string ilObjFilePreviewRendererGUI::$file_name = ''
private

Definition at line 93 of file class.ilObjFilePreviewRendererGUI.php.

Referenced by getAsyncModal().

◆ $flavour_definition

FlavourDefinition ilObjFilePreviewRendererGUI::$flavour_definition
private

Definition at line 75 of file class.ilObjFilePreviewRendererGUI.php.

◆ $http

ILIAS HTTP Services ilObjFilePreviewRendererGUI::$http
private

Definition at line 63 of file class.ilObjFilePreviewRendererGUI.php.

◆ $http_wrapper

WrapperFactory ilObjFilePreviewRendererGUI::$http_wrapper
private

Definition at line 67 of file class.ilObjFilePreviewRendererGUI.php.

◆ $irss

Services ilObjFilePreviewRendererGUI::$irss
private

Definition at line 59 of file class.ilObjFilePreviewRendererGUI.php.

◆ $language

ilLanguage ilObjFilePreviewRendererGUI::$language
private

Definition at line 83 of file class.ilObjFilePreviewRendererGUI.php.

◆ $pages_to_extract

int ilObjFilePreviewRendererGUI::$pages_to_extract
private

Definition at line 91 of file class.ilObjFilePreviewRendererGUI.php.

◆ $preview_size

int ilObjFilePreviewRendererGUI::$preview_size
private

Definition at line 87 of file class.ilObjFilePreviewRendererGUI.php.

◆ $refinery

ILIAS Refinery Factory ilObjFilePreviewRendererGUI::$refinery
private

Definition at line 71 of file class.ilObjFilePreviewRendererGUI.php.

◆ $rid

ResourceIdentification ilObjFilePreviewRendererGUI::$rid = null
private

Definition at line 55 of file class.ilObjFilePreviewRendererGUI.php.

◆ $ui_factory

Factory ilObjFilePreviewRendererGUI::$ui_factory
private

Definition at line 46 of file class.ilObjFilePreviewRendererGUI.php.

◆ $ui_renderer

Renderer ilObjFilePreviewRendererGUI::$ui_renderer
private

Definition at line 50 of file class.ilObjFilePreviewRendererGUI.php.

◆ CMD_GET_ASYNC_MODAL

const ilObjFilePreviewRendererGUI::CMD_GET_ASYNC_MODAL = 'getAsyncModal'

Definition at line 37 of file class.ilObjFilePreviewRendererGUI.php.

◆ P_RID

const ilObjFilePreviewRendererGUI::P_RID = "rid"

Definition at line 36 of file class.ilObjFilePreviewRendererGUI.php.


The documentation for this class was generated from the following file: