ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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

Services $irss
 
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 42 of file class.ilObjFileInfoRepository.php.

References $DIC, and initInlineSuffixes().

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  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ getByObjectId()

ilObjFileInfoRepository::getByObjectId ( int  $object_id)

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

References preloadData().

Referenced by getByRefId().

131  : ilObjFileInfo
132  {
133  if (isset(self::$cache[$object_id])) {
134  return self::$cache[$object_id];
135  }
136 
137  $this->preloadData([$object_id]);
138 
139  return self::$cache[$object_id] ?? new ilObjFileInfo(
140  'Unknown',
141  null,
142  'Unknown',
143  '',
144  false,
145  false,
146  0,
147  new DateTimeImmutable(),
148  false,
149  '',
150  new DataSize(0, DataSize::Byte),
151  null
152  );
153  }
This class provides the data size with additional information to remove the work to calculate the siz...
Definition: DataSize.php:30
preloadData(array $ids, bool $are_ref_ids=false)
+ 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 53 of file class.ilObjFileInfoRepository.php.

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

54  {
55  $object_id = ilObject2::_lookupObjectId($ref_id);
56 
57  return $this->getByObjectId($object_id);
58  }
$ref_id
Definition: ltiauth.php:67
static _lookupObjectId(int $ref_id)
+ Here is the call graph for this function:

◆ initInlineSuffixes()

ilObjFileInfoRepository::initInlineSuffixes ( )
private

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

References ILIAS\LTI\ToolProvider\$settings.

Referenced by __construct().

60  : array
61  {
62  $settings = new ilSetting('file_access');
63  return array_map('strtolower', explode(' ', (string) $settings->get('inline_file_extensions', '')));
64  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
+ Here is the caller graph for this function:

◆ preloadData()

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

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

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

Referenced by getByObjectId().

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

ilDBInterface ilObjFileInfoRepository::$db
private

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

◆ $inline_suffixes

array ilObjFileInfoRepository::$inline_suffixes = []
private

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

◆ $irss

Services ilObjFileInfoRepository::$irss
private

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


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