ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
EntriesRepositoryDB.php
Go to the documentation of this file.
1<?php
2
20
22use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
27
29{
30 use Hasher;
31
32 public const TABLE_NAME = 'gs_footer_items';
33
37 protected array $cache = [];
38
39 public function __construct(
40 private \ilDBInterface $db,
41 private ?\ilFooterCustomGroupsProvider $provider = null
42 ) {
43 }
44
45 public function syncWithGlobalScreen(
46 FooterMainCollector $collector
47 ): void {
48 $collector->collectOnce();
49 $this->preload();
50
51 foreach ($collector->getRawUnfilteredItems() as $item) {
52 if (!$item instanceof canHaveParent) {
53 continue;
54 }
55 if ($this->has($item->getProviderIdentification()->serialize())) {
56 continue;
57 }
60 $new = new EntryDTO(
61 $item->getProviderIdentification()->serialize(),
62 $item->getTitle(),
63 true,
64 $item->getPosition(),
65 $item->getParentIdentification()->serialize(),
66 $item instanceof hasAction ? (string) $item->getAction() : '',
67 $item instanceof hasAction ? $item->mustOpenInNewViewport() : false,
68 true
69 );
70 $this->store($new);
71 }
72 }
73
74 public function preload(): void
75 {
76 foreach (
77 $this->db->fetchAll(
78 $this->db->query('SELECT * FROM ' . self::TABLE_NAME . ' WHERE type != 1 ORDER BY position ASC')
79 ) as $row
80 ) {
81 $entry = $this->fromDB($row);
82 $this->cache[$entry->getId()] = $entry;
83 }
84 }
85
86 private function fromDB(array $row): Entry
87 {
88 return new EntryDTO(
89 $row['id'],
90 $row['title'],
91 $row['is_active'] === 1,
92 (int) $row['position'],
93 (string) ($row['parent'] ?? ''),
94 (string) ($row['action'] ?? ''),
95 (bool) $row['external'],
96 (bool) $row['core']
97 );
98 }
99
100 public function get(string $identifier): ?Entry
101 {
102 if (isset($this->cache[$identifier]) && $this->has($identifier)) {
103 return $this->cache[$identifier];
104 }
105
106 $row = $this->db->queryF(
107 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE id = %s AND type != 1',
108 ['text'],
109 [$identifier]
110 )->fetchAssoc();
111 if ($row === null) {
112 return null;
113 }
114 return $this->fromDB($row);
115 }
116
117 public function has(string $identifier): bool
118 {
119 return $this->db->queryF(
120 'SELECT id FROM ' . self::TABLE_NAME . ' WHERE id = %s AND type != 1',
121 ['text'],
122 [$identifier]
123 )->numRows() > 0;
124 }
125
126 public function blank(): Entry
127 {
128 return new EntryDTO('', '', true, 0, '', false);
129 }
130
131 public function store(Entry $entry): Entry
132 {
133 if ($entry->getId() === '' || !$this->has($entry->getId())) {
134 return $this->create($entry);
135 }
136
137 return $this->update($entry);
138 }
139
140 private function create(Entry $entry): Entry
141 {
142 if ($this->provider === null) {
143 throw new \LogicException('No provider set');
144 }
145
146 if ($entry->getId() === '') {
147 $entry = $entry->withId($this->provider->getNewIdentification()->serialize());
148 }
149 $this->db->insert(
150 self::TABLE_NAME,
151 [
152 'id' => ['text', $entry->getId()],
153 'type' => ['integer', 2],
154 'title' => ['text', $entry->getTitle()],
155 'position' => ['integer', $entry->getPosition()],
156 'is_active' => ['integer', $entry->isActive() ? 1 : 0],
157 'parent' => ['text', $entry->getParent()],
158 'action' => ['text', $entry->getAction()],
159 'external' => ['integer', $entry->isExternal() ? 1 : 0],
160 'core' => ['integer', $entry->isCore() ? 1 : 0],
161 ]
162 );
163 return $entry;
164 }
165
166 private function update(Entry $entry): Entry
167 {
168 $this->db->update(
169 self::TABLE_NAME,
170 [
171 'title' => ['text', $entry->getTitle()],
172 'position' => ['integer', $entry->getPosition()],
173 'is_active' => ['integer', $entry->isActive() ? 1 : 0],
174 'parent' => ['text', $entry->getParent()],
175 'action' => ['text', $entry->getAction()],
176 'external' => ['integer', $entry->isExternal() ? 1 : 0],
177 'core' => ['integer', $entry->isCore() ? 1 : 0],
178 ],
179 ['id' => ['text', $entry->getId()]]
180 );
181 return $entry;
182 }
183
184 public function delete(Entry $entry): void
185 {
186 if ($entry->isCore()) {
187 return;
188 }
189
190 $this->db->manipulateF(
191 'DELETE FROM ' . self::TABLE_NAME . ' WHERE id = %s',
192 ['text'],
193 [$entry->getId()]
194 );
195 }
196
200 public function all(): \Generator
201 {
202 $this->preload();
203 yield from $this->cache;
204 }
205
206 public function allForParent(string $parent_identifier): \Generator
207 {
208 $this->preload();
209 foreach ($this->cache as $entry) {
210 if ($entry->getParent() === $parent_identifier) {
211 yield $entry;
212 }
213 }
214 }
215
216 public function updatePositionById(string $id, int $position): void
217 {
218 $this->db->update(
219 self::TABLE_NAME,
220 ['position' => ['integer', $position]],
221 ['id' => ['text', $id]]
222 );
223 }
224
225 public function getTotalRowCount(
226 mixed $additional_viewcontrol_data,
227 mixed $filter_data,
228 mixed $additional_parameters
229 ): ?int {
230 return null;
231 }
232
233 public function reset(FooterMainCollector $collector): void
234 {
235 $this->db->manipulate('DELETE FROM ' . self::TABLE_NAME . ' WHERE type != 1');
236 $this->syncWithGlobalScreen($collector);
237 }
238
239}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
__construct(private \ilDBInterface $db, private ?\ilFooterCustomGroupsProvider $provider=null)
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...
syncWithGlobalScreen(FooterMainCollector $collector)
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
has(string $class_name)