ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilObjFileInfoRepository Class Reference
+ Collaboration diagram for ilObjFileInfoRepository:

Public Member Functions

 __construct (bool $with_cleared_cache=false)
 
 getByRefId (int $ref_id)
 
 preloadData (array $ids, bool $are_ref_ids=false)
 
 getByObjectId (int $object_id)
 

Private Member Functions

 initInlineSuffixes ()
 

Private Attributes

readonly Services $irss
 
readonly ilDBInterface $db
 
array $inline_suffixes = []
 

Static Private Attributes

static array $cache = []
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s
    Use this class to get common information about a file object. if you need infos for multiple files, use the
    preloadData method to load all data at once.

Definition at line 29 of file class.ilObjFileInfoRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjFileInfoRepository::__construct ( bool  $with_cleared_cache = false)

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

37 {
38 global $DIC;
39 if ($with_cleared_cache) {
40 self::$cache = [];
41 }
42 $this->irss = $DIC->resourceStorage();
43 $this->db = $DIC->database();
44 $this->inline_suffixes = $this->initInlineSuffixes();
45 }
global $DIC
Definition: shib_login.php:26

References $DIC, and initInlineSuffixes().

+ Here is the call graph for this function:

Member Function Documentation

◆ getByObjectId()

ilObjFileInfoRepository::getByObjectId ( int  $object_id)

Definition at line 125 of file class.ilObjFileInfoRepository.php.

126 {
127 if (isset(self::$cache[$object_id])) {
128 return self::$cache[$object_id];
129 }
130
131 $this->preloadData([$object_id]);
132
133 return self::$cache[$object_id] ?? new ilObjFileInfo(
134 'Unknown',
135 null,
136 'Unknown',
137 '',
138 false,
139 false,
140 0,
141 new DateTimeImmutable(),
142 false,
143 '',
144 new DataSize(0, DataSize::Byte),
145 null
146 );
147 }
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:31
preloadData(array $ids, bool $are_ref_ids=false)

References preloadData().

Referenced by getByRefId().

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

◆ getByRefId()

ilObjFileInfoRepository::getByRefId ( int  $ref_id)

Definition at line 47 of file class.ilObjFileInfoRepository.php.

48 {
50
51 return $this->getByObjectId($object_id);
52 }
static _lookupObjectId(int $ref_id)
$ref_id
Definition: ltiauth.php:66

References $ref_id, ilObject\_lookupObjectId(), and getByObjectId().

+ Here is the call graph for this function:

◆ initInlineSuffixes()

ilObjFileInfoRepository::initInlineSuffixes ( )
private

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

54 : array
55 {
56 $settings = new ilSetting('file_access');
57 return array_map('strtolower', explode(' ', (string) $settings->get('inline_file_extensions', '')));
58 }
ILIAS Setting Class.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ preloadData()

ilObjFileInfoRepository::preloadData ( array  $ids,
bool  $are_ref_ids = false 
)

Definition at line 60 of file class.ilObjFileInfoRepository.php.

60 : void
61 {
62 if ($are_ref_ids) {
63 $query = "SELECT title, rid, file_id, page_count, on_click_mode
64 FROM file_data
65 JOIN object_data ON object_data.obj_id = file_data.file_id
66 JOIN object_reference ON object_reference.obj_id = object_data.obj_id
67 WHERE rid IS NOT NULL AND " . $this->db->in(
68 'ref_id',
69 $ids,
70 false,
71 'integer'
72 );
73 } else {
74 $query = "SELECT title, rid, file_id, page_count, on_click_mode FROM file_data JOIN object_data ON object_data.obj_id = file_data.file_id WHERE rid IS NOT NULL AND " . $this->db->in(
75 'file_id',
76 $ids,
77 false,
78 'integer'
79 );
80 }
81
82 $res = $this->db->query(
83 $query
84 );
85 $rids = [];
86 $page_counts = [];
87 $object_titles = [];
88 $click_modes = [];
89
90 while ($row = $this->db->fetchObject($res)) {
91 $rids[(int) $row->file_id] = $row->rid;
92 $page_counts[(int) $row->file_id] = $row->page_count;
93 $object_titles[(int) $row->file_id] = $row->title;
94 $click_modes[(int) $row->file_id] = (int) ($row->on_click_mode ?? ilObjFile::CLICK_MODE_DOWNLOAD);
95 }
96 $this->irss->preload($rids);
97
98 foreach ($rids as $file_id => $rid) {
99 if (($id = $this->irss->manage()->find($rid)) !== null) {
100 $max = $this->irss->manage()->getResource($id)->getCurrentRevision();
101
102 $info = new ilObjFileInfo(
103 $object_titles[$file_id] ?? $max->getTitle(),
104 $id,
105 $max->getInformation()->getTitle(),
106 $max->getInformation()->getSuffix(),
107 in_array(strtolower($max->getInformation()->getSuffix()), $this->inline_suffixes, true),
108 $click_modes[$file_id] === ilObjFile::CLICK_MODE_DOWNLOAD,
109 $max->getVersionNumber(),
110 $max->getInformation()->getCreationDate(),
111 in_array(strtolower($max->getInformation()->getMimeType()), [
112 MimeType::APPLICATION__ZIP,
113 MimeType::APPLICATION__X_ZIP_COMPRESSED
114 ], true),
115 $max->getInformation()->getMimeType(),
116 new DataSize($max->getInformation()->getSize() ?? 0, DataSize::Byte),
117 $page_counts[$file_id] === null ? null : (int) $page_counts[$file_id]
118 );
119
120 self::$cache[$file_id] = $info;
121 }
122 }
123 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const CLICK_MODE_DOWNLOAD
$info
Definition: entry_point.php:21
$res
Definition: ltiservices.php:69

References $id, $info, $res, ilObjFile\CLICK_MODE_DOWNLOAD, and ILIAS\Repository\int().

Referenced by getByObjectId().

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

Field Documentation

◆ $cache

array ilObjFileInfoRepository::$cache = []
staticprivate

Definition at line 31 of file class.ilObjFileInfoRepository.php.

◆ $db

readonly ilDBInterface ilObjFileInfoRepository::$db
private

Definition at line 33 of file class.ilObjFileInfoRepository.php.

◆ $inline_suffixes

array ilObjFileInfoRepository::$inline_suffixes = []
private

Definition at line 34 of file class.ilObjFileInfoRepository.php.

◆ $irss

readonly Services ilObjFileInfoRepository::$irss
private

Definition at line 32 of file class.ilObjFileInfoRepository.php.


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