ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ResourceDBRepository.php
Go to the documentation of this file.
1<?php
2
20
26
33{
34 public const TABLE_NAME = 'il_resource';
35 public const IDENTIFICATION = 'rid';
36
40 protected array $cache = [];
41
42 public function __construct(protected \ilDBInterface $db)
43 {
44 }
45
49 public function getNamesForLocking(): array
50 {
51 return [self::TABLE_NAME];
52 }
53
57 public function blank(
58 ResourceIdentification $identification,
59 ResourceType $type = ResourceType::SINGLE_FILE
61 return match ($type) {
62 ResourceType::SINGLE_FILE => new StorableFileResource($identification),
64 };
65 }
66
70 public function get(ResourceIdentification $identification): StorableResource
71 {
72 $rid = $identification->serialize();
73
74 if (isset($this->cache[$rid])) {
75 return $this->cache[$rid];
76 }
77
78 $q = "SELECT storage_id, rtype, confidential FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s";
79 $r = $this->db->queryF($q, ['text'], [$rid]);
80 $d = $this->db->fetchObject($r);
81
82 $resource = $this->blank($identification, ResourceType::from((int) $d->rtype));
83 $resource->setStorageID($d->storage_id);
84 $resource->setConfidential((bool) $d->confidential);
85
86 $this->cache[$rid] = $resource;
87
88 return $resource;
89 }
90
94 public function has(ResourceIdentification $identification): bool
95 {
96 $rid = $identification->serialize();
97
98 if (isset($this->cache[$rid])) {
99 return true;
100 }
101
102 $q = "SELECT EXISTS(SELECT 1 FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s) AS found";
103 $r = $this->db->queryF($q, ['text'], [$rid]);
104 $d = $this->db->fetchAssoc($r);
105
106 return (bool) $d['found'];
107 }
108
112 public function store(StorableResource $resource): void
113 {
114 $rid = $resource->getIdentification()->serialize();
115
116 $this->db->replace(
117 self::TABLE_NAME,
118 [
119 self::IDENTIFICATION => ['text', $rid]
120 ],
121 [
122 'storage_id' => ['text', $resource->getStorageID()],
123 'rtype' => ['integer', $resource->getType()->value],
124 'confidential' => ['integer', (int) $resource->isConfidential()],
125 ]
126 );
127
128 $this->cache[$rid] = $resource;
129 }
130
134 public function delete(StorableResource $resource): void
135 {
136 $rid = $resource->getIdentification()->serialize();
137 $this->db->manipulateF(
138 "DELETE FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s",
139 ['text'],
140 [$rid]
141 );
142 unset($this->cache[$rid]);
143 }
144
148 public function getAll(): \Generator
149 {
150 yield from [];
151 }
152
153 public function preload(array $identification_strings): void
154 {
155 $r = $this->db->query(
156 "SELECT rid, storage_id, rtype, confidential FROM " . self::TABLE_NAME . " WHERE "
157 . $this->db->in(self::IDENTIFICATION, $identification_strings, false, 'text')
158 );
159 while ($d = $this->db->fetchAssoc($r)) {
160 $this->populateFromArray($d);
161 }
162 }
163
164 public function populateFromArray(array $data): void
165 {
166 $resource = $this->blank(
167 new ResourceIdentification($data['rid']),
168 ResourceType::from((int) ($data['rtype'] ?? ResourceType::SINGLE_FILE->value))
169 );
170 $resource->setStorageID($data['storage_id']);
171 $resource->setConfidential((bool) ($data['confidential'] ?? false));
172 $this->cache[$data['rid']] = $resource;
173 }
174}
blank(ResourceIdentification $identification, ResourceType $type=ResourceType::SINGLE_FILE)
@inheritDoc
has(ResourceIdentification $identification)
@inheritDoc
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isConfidential()
Confidential resources are redacted in the administration for everyone except the owner of the curren...
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$data
Definition: storeScorm.php:45