ILIAS  release_8 Revision v8.24
CollectionDBRepository.php
Go to the documentation of this file.
1<?php
2
20
25
33{
34 public const COLLECTION_TABLE_NAME = 'il_resource_rc';
35 public const COLLECTION_ASSIGNMENT_TABLE_NAME = 'il_resource_rca';
36 public const R_IDENTIFICATION = 'rid';
37 public const C_IDENTIFICATION = 'rcid';
38 protected \ilDBInterface $db;
39
40 public function __construct(\ilDBInterface $db)
41 {
42 $this->db = $db;
43 }
44
48 public function getNamesForLocking(): array
49 {
51 }
52
53 public function blank(
55 ?int $owner_id = null,
56 ?string $title = null
59 $identification,
60 $owner_id ?? ResourceCollection::NO_SPECIFIC_OWNER,
61 $title ?? ''
62 );
63 }
64
66 {
67 $q = "SELECT owner_id, title FROM " . self::COLLECTION_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s";
68 $r = $this->db->queryF($q, ['text'], [$identification->serialize()]);
69 $d = $this->db->fetchObject($r);
70 $owner_id = (int)($d->owner_id ?? ResourceCollection::NO_SPECIFIC_OWNER);
71 $title = (string)($d->title ?? '');
72
73 return $this->blank($identification, $owner_id, $title);
74 }
75
76
77 public function has(ResourceCollectionIdentification $identification): bool
78 {
79 $q = "SELECT " . self::C_IDENTIFICATION . " FROM " . self::COLLECTION_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s";
80 $r = $this->db->queryF($q, ['text'], [$identification->serialize()]);
81
82 return ($r->numRows() === 1);
83 }
84
88 public function getResourceIdStrings(ResourceCollectionIdentification $identification): \Generator
89 {
90 $q = "SELECT " . self::R_IDENTIFICATION . " FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s ORDER BY position ASC";
91 $r = $this->db->queryF($q, ['text'], [$identification->serialize()]);
92 while ($d = $this->db->fetchAssoc($r)) {
93 yield (string)$d[self::R_IDENTIFICATION];
94 }
95 }
96
97 public function clear(ResourceCollectionIdentification $identification): void
98 {
99 $q = "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s";
100 $r = $this->db->manipulateF($q, ['text'], [$identification->serialize()]);
101 }
102
103 public function update(ResourceCollection $collection): void
104 {
105 $identification = $collection->getIdentification();
106 $resource_identifications = $collection->getResourceIdentifications();
107 $owner_id = $collection->getOwner();
108 $title = $collection->getTitle();
109
110 $resource_identification_strings = array_map(
111 fn (ResourceIdentification $i): string => $i->serialize(),
112 $resource_identifications
113 );
114
115 $q = "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s AND "
116 . $this->db->in(self::R_IDENTIFICATION, $resource_identification_strings, true, 'text');
117 $r = $this->db->manipulateF($q, ['text'], [$identification->serialize()]);
118
119 $missing_resource_identification_string = array_diff(
120 $resource_identification_strings,
121 iterator_to_array($this->getResourceIdStrings($identification))
122 );
123 foreach ($missing_resource_identification_string as $position => $resource_identification_string) {
124 $this->db->insert(self::COLLECTION_ASSIGNMENT_TABLE_NAME, [
125 self::C_IDENTIFICATION => ['text', $identification->serialize()],
126 self::R_IDENTIFICATION => ['text', $resource_identification_string],
127 'position' => ['integer', (int)$position + 1],
128 ]);
129 }
130 foreach ($resource_identification_strings as $position => $resource_identification_string) {
131 $this->db->update(
132 self::COLLECTION_ASSIGNMENT_TABLE_NAME,
133 [
134 self::C_IDENTIFICATION => ['text', $identification->serialize()],
135 self::R_IDENTIFICATION => ['text', $resource_identification_string],
136 'position' => ['integer', (int)$position + 1],
137 ],
138 [
139 self::C_IDENTIFICATION => ['text', $identification->serialize()],
140 self::R_IDENTIFICATION => ['text', $resource_identification_string],
141 ]
142 );
143 }
144 if ($this->has($identification)) {
145 $this->db->update(
146 self::COLLECTION_TABLE_NAME,
147 [
148 self::C_IDENTIFICATION => ['text', $identification->serialize()],
149 'title' => ['text', $title ?? ''],
150 'owner_id' => ['integer', $owner_id],
151 ],
152 [
153 self::C_IDENTIFICATION => ['text', $identification->serialize()]
154 ]
155 );
156 } else {
157 $this->db->insert(
158 self::COLLECTION_TABLE_NAME,
159 [
160 self::C_IDENTIFICATION => ['text', $identification->serialize()],
161 'title' => ['text', $title ?? ''],
162 'owner_id' => ['integer', $owner_id],
163 ]
164 );
165 }
166 }
167
168 public function removeResourceFromAllCollections(ResourceIdentification $resource_identification): void
169 {
170 $this->db->manipulateF(
171 "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::R_IDENTIFICATION . " = %s",
172 ['text'],
173 [$resource_identification->serialize()]
174 );
175 }
176
177 public function delete(ResourceCollectionIdentification $identification): void
178 {
179 $this->db->manipulateF(
180 "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s",
181 ['text'],
182 [$identification->serialize()]
183 );
184 $this->db->manipulateF(
185 "DELETE FROM " . self::COLLECTION_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s",
186 ['text'],
187 [$identification->serialize()]
188 );
189 }
190
191
192 public function preload(array $identification_strings): void
193 {
194 // TODO: Implement preload() method.
195 }
196
197 public function populateFromArray(array $data): void
198 {
199 // TODO: Implement populateFromArray() method.
200 }
201}
clear(ResourceCollectionIdentification $identification)
blank(ResourceCollectionIdentification $identification, ?int $owner_id=null, ?string $title=null)
removeResourceFromAllCollections(ResourceIdentification $resource_identification)
has(ResourceCollectionIdentification $identification)
existing(ResourceCollectionIdentification $identification)
getResourceIdStrings(ResourceCollectionIdentification $identification)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
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', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
Interface ilDBInterface.
$i
Definition: metadata.php:41
has(string $class_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...