ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilObjFileInfoRepository.php
Go to the documentation of this file.
1<?php
2
28
36{
37 private static array $cache = [];
38 private \ILIAS\ResourceStorage\Services $irss;
40 private array $inline_suffixes = [];
41
42 public function __construct(bool $with_cleared_cache = false)
43 {
44 global $DIC;
45 if ($with_cleared_cache) {
46 self::$cache = [];
47 }
48 $this->irss = $DIC->resourceStorage();
49 $this->db = $DIC->database();
50 $this->inline_suffixes = $this->initInlineSuffixes();
51 }
52
53 public function getByRefId(int $ref_id): ilObjFileInfo
54 {
56
57 return $this->getByObjectId($object_id);
58 }
59
60 private function initInlineSuffixes(): array
61 {
62 $settings = new ilSetting('file_access');
63 return array_map('strtolower', explode(" ", $settings->get('inline_file_extensions')));
64 }
65
66 public function preloadData(array $object_ids): void
67 {
68 $res = $this->db->query(
69 "SELECT title, rid, file_id, page_count FROM file_data JOIN object_data ON object_data.obj_id = file_data.file_id WHERE rid IS NOT NULL AND " . $this->db->in(
70 'file_id',
71 $object_ids,
72 false,
73 'integer'
74 )
75 );
76 $rids = [];
77 $page_counts = [];
78 $object_titles = [];
79
80 while ($row = $this->db->fetchObject($res)) {
81 $rids[(int) $row->file_id] = $row->rid;
82 $page_counts[(int) $row->file_id] = $row->page_count;
83 $object_titles[(int) $row->file_id] = $row->title;
84 }
85 $this->irss->preload($rids);
86
87 foreach ($rids as $file_id => $rid) {
88 if ($id = $this->irss->manage()->find($rid)) {
89 $max = $this->irss->manage()->getResource($id)->getCurrentRevision();
90
91 $info = new ilObjFileInfo(
92 $object_titles[$file_id] ?? $max->getTitle(),
93 $max->getInformation()->getTitle(),
94 $max->getInformation()->getSuffix(),
95 in_array(strtolower($max->getInformation()->getSuffix()), $this->inline_suffixes, true),
96 true,
97 $max->getVersionNumber(),
98 $max->getInformation()->getCreationDate(),
99 in_array(strtolower($max->getInformation()->getMimeType()), [
100 MimeType::APPLICATION__ZIP,
101 MimeType::APPLICATION__X_ZIP_COMPRESSED
102 ], true),
103 $max->getInformation()->getMimeType(),
104 new DataSize($max->getInformation()->getSize() ?? 0, DataSize::Byte),
105 $page_counts[$file_id] === null ? null : (int) $page_counts[$file_id]
106 );
107
108 self::$cache[$file_id] = $info;
109 }
110 }
111 }
112
113 public function getByObjectId(int $object_id): ilObjFileInfo
114 {
115 $this->preloadData([$object_id]);
116 return self::$cache[$object_id] ?? new ilObjFileInfo(
117 'Unknown',
118 'Unknown',
119 '',
120 false,
121 false,
122 0,
123 new DateTimeImmutable(),
124 false,
125 '',
126 new DataSize(0, DataSize::Byte),
127 null
128 );
129 }
130
131}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
Mime type determination.
Definition: MimeType.php:28
__construct(bool $with_cleared_cache=false)
ILIAS ResourceStorage Services $irss
static _lookupObjectId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$ref_id
Definition: ltiauth.php:67
$res
Definition: ltiservices.php:69
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200