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