ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
 @readonly More...
 
Factory $ui_factory
 @readonly More...
 
Renderer $ui_renderer
 @readonly More...
 
ilCtrlInterface $ctrl
 @readonly More...
 
ResourceIdentification $rid = null
 
Services $irss
 @readonly More...
 
ILIAS HTTP Services $http
 @readonly More...
 
WrapperFactory $http_wrapper
 @readonly More...
 
ILIAS Refinery Factory $refinery
 @readonly More...
 
FlavourDefinition $flavour_definition
 @readonly More...
 
ilAccessHandler $access
 @readonly More...
 
ilLanguage $language
 @readonly More...
 
int $preview_size
 @readonly More...
 
int $pages_to_extract
 @readonly More...
 
bool $activated = false
 
string $file_name = ''
 
FlavourDefinition $fallback_flavour_definition
 @readonly More...
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

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 }
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilObjFilePreviewRendererGUI::executeCommand ( )

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

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 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ getAsyncModal()

ilObjFilePreviewRendererGUI::getAsyncModal ( )
private

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

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,
267 $this->file_name
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 }
A lightbox Image page represents a page displaying a media element, such as image,...
$url
Definition: shib_logout.php:68
$response
Definition: xapitoken.php:93

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

+ Here is the call graph for this function:

◆ getRenderedTriggerComponents()

ilObjFilePreviewRendererGUI::getRenderedTriggerComponents ( bool  $as_button = false)

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

192 : string
193 {
194 return $this->ui_renderer->render($this->getTriggerComponents($as_button));
195 }

References getTriggerComponents().

+ Here is the call graph for this function:

◆ getTriggerComponents()

ilObjFilePreviewRendererGUI::getTriggerComponents ( bool  $as_button = false)

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

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 }

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

Referenced by getRenderedTriggerComponents().

+ 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.

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 }

References isAccessGranted().

+ Here is the call graph for this function:

◆ isAccessGranted()

ilObjFilePreviewRendererGUI::isAccessGranted ( )
protected

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

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
$ref_id
Definition: ltiauth.php:66

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

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

+ 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.

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 }

References ILIAS\Repository\refinery().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilObjFilePreviewRendererGUI::$access
private

@readonly

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

@readonly

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

◆ $db

ilDBInterface ilObjFilePreviewRendererGUI::$db
private

@readonly

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

◆ $fallback_flavour_definition

FlavourDefinition ilObjFilePreviewRendererGUI::$fallback_flavour_definition
private

@readonly

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.

◆ $flavour_definition

FlavourDefinition ilObjFilePreviewRendererGUI::$flavour_definition
private

@readonly

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

◆ $http

ILIAS HTTP Services ilObjFilePreviewRendererGUI::$http
private

@readonly

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

◆ $http_wrapper

WrapperFactory ilObjFilePreviewRendererGUI::$http_wrapper
private

@readonly

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

◆ $irss

Services ilObjFilePreviewRendererGUI::$irss
private

@readonly

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

◆ $language

ilLanguage ilObjFilePreviewRendererGUI::$language
private

@readonly

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

◆ $pages_to_extract

int ilObjFilePreviewRendererGUI::$pages_to_extract
private

@readonly

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

◆ $preview_size

int ilObjFilePreviewRendererGUI::$preview_size
private

@readonly

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

◆ $refinery

ILIAS Refinery Factory ilObjFilePreviewRendererGUI::$refinery
private

@readonly

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

@readonly

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

◆ $ui_renderer

Renderer ilObjFilePreviewRendererGUI::$ui_renderer
private

@readonly

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: