63 private \ILIAS\HTTP\Services
$http;
100 private readonly ?
int $object_id =
null 105 $this->activated = $settings->isPreviewEnabled();
107 $this->db = $DIC->database();
108 $this->
ctrl = $DIC->ctrl();
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();
116 $this->
access = $DIC->access();
118 $this->
language->loadLanguageModule(
'file');
122 $this->rid = $this->irss->manage()->find($rid_string);
124 $settings->isPersisting(),
125 $settings->getImageSize(),
126 $settings->getMaximumPreviews()
128 $this->fallback_flavour_definition =
new FitToSquare(
129 $settings->isPersisting(),
130 $settings->getImageSize()
133 if ($this->rid !==
null) {
134 $this->file_name = $this->irss->manage()->getCurrentRevision($this->rid)->getTitle();
138 public function has(): bool
140 if (!$this->activated) {
143 if ($this->rid ===
null) {
147 !$this->irss->flavours()->possible(
149 $this->flavour_definition
151 && !$this->irss->flavours()->possible(
153 $this->fallback_flavour_definition
167 $this->
ctrl->setParameterByClass(self::class, self::P_RID, $this->rid->serialize());
169 $modal = $this->ui_factory->modal()
171 ->withAsyncRenderUrl(
172 $this->
ctrl->getLinkTargetByClass(self::class, self::CMD_GET_ASYNC_MODAL)
176 $trigger = $this->ui_factory->symbol()->glyph()->preview(
178 )->withOnClick($modal->getShowSignal());
180 $trigger = $this->ui_factory->button()->standard(
181 $this->
language->txt(
'show_preview'),
183 )->withOnClick($modal->getShowSignal());
199 $cmd = $this->
ctrl->getCmd();
201 self::CMD_GET_ASYNC_MODAL => $this->{$cmd}(),
211 if ($object_id !==
null) {
212 return $this->db->fetchObject(
214 'SELECT rid FROM file_data WHERE file_id = %s',
220 return $this->http_wrapper->query()->has(self::P_RID)
221 ? $this->http_wrapper->query()->retrieve(
230 if ($this->object_id !==
null) {
232 if ($this->
access->checkAccess(
'read',
'', $ref_id)) {
239 $resource = $this->irss->manage()->getResource($this->rid);
240 foreach ($resource->getStakeholders() as $stakeholder) {
241 if ($stakeholder->canBeAccessedByCurrentUser($this->rid)) {
255 $flavour = $this->irss->flavours()->get($this->rid, $this->flavour_definition);
256 $flavour_urls = $this->irss->consume()->flavourUrls($flavour)->getURLsAsArray();
257 if ($flavour_urls === []) {
258 $flavour = $this->irss->flavours()->get($this->rid, $this->fallback_flavour_definition);
259 $flavour_urls = $this->irss->consume()->flavourUrls($flavour)->getURLsAsArray();
262 $page_title =
function (?
int $index):
string {
263 $index_string = $index !==
null ? (($index + 1) .
' ') :
'';
265 $this->
language->txt(
'preview_caption'),
273 $title = $page_title($i);
274 return $this->ui_factory->modal()->lightboxImagePage(
275 $this->ui_factory->image()->responsive(
281 }, $flavour_urls, count($flavour_urls) > 1 ? array_keys($flavour_urls) : []);
285 $pages = $this->ui_factory->modal()->lightboxTextPage(
287 $this->
language->txt(
'preview_not_possible'),
288 'components/ILIAS/File/classes/Preview/README.md' 293 $modal = $this->ui_factory->modal()->lightbox($pages);
296 $response = $this->
http->response()->withBody(Streams::ofString($this->ui_renderer->renderAsync($modal)));
298 $this->
http->sendResponse();
ILIAS HTTP Services $http
WrapperFactory $http_wrapper
resolveRidString(?int $object_id)
static _getAllReferences(int $id)
get all reference ids for object ID
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...
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
FlavourDefinition $fallback_flavour_definition
This is how the factory for UI elements looks.
Class ResourceIdentification.
const CMD_GET_ASYNC_MODAL
getRenderedTriggerComponents(bool $as_button=false)
A lightbox Image page represents a page displaying a media element, such as image, video.
ILIAS Refinery Factory $refinery
__construct(private readonly ?int $object_id=null)
getTriggerComponents(bool $as_button=false)
language()
description: > Example for rendring a language glyph.
ResourceIdentification $rid
FlavourDefinition $flavour_definition