58 ?
int $owner_id =
null,
68 if (!isset($this->resource_ids_cache[$rcid])) {
69 $this->resource_ids_cache[$rcid] = [];
77 $q =
"SELECT owner_id, title FROM " . self::COLLECTION_TABLE_NAME .
" WHERE " . self::C_IDENTIFICATION .
" = %s";
78 $r = $this->db->queryF(
$q, [
'text'], [$identification->
serialize()]);
79 $d = $this->db->fetchObject($r);
81 $title = (string) (
$d->title ??
'');
83 return $this->blank($identification, $owner_id, $title);
89 SELECT 1 FROM " . self::COLLECTION_TABLE_NAME .
"
90 WHERE " . self::C_IDENTIFICATION .
" = %s
93 $r = $this->db->queryF(
$q, [
'text'], [$identification->
serialize()]);
94 $d = $this->db->fetchAssoc($r);
96 return (
bool) (
$d[
'found'] ??
false);
106 if (!isset($this->resource_ids_cache[$rcid])) {
107 $this->preload([$rcid]);
110 foreach ($this->resource_ids_cache[$rcid] ?? [] as $rid) {
118 $q =
"DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME .
" WHERE " . self::C_IDENTIFICATION .
" = %s";
119 $this->db->manipulateF(
$q, [
'text'], [$rcid]);
121 $this->resource_ids_cache[$rcid] = [];
128 $owner_id = $collection->
getOwner();
131 $resource_identification_strings = array_map(
133 $resource_identifications
136 $q =
"DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME .
" WHERE " . self::C_IDENTIFICATION .
" = %s AND "
137 . $this->db->in(self::R_IDENTIFICATION, $resource_identification_strings,
true,
'text');
138 $r = $this->db->manipulateF(
$q, [
'text'], [$identification->
serialize()]);
140 $missing_resource_identification_string = array_diff(
141 $resource_identification_strings,
142 iterator_to_array($this->getResourceIdStrings($identification))
144 foreach ($missing_resource_identification_string as $position => $resource_identification_string) {
145 $this->db->insert(self::COLLECTION_ASSIGNMENT_TABLE_NAME, [
146 self::C_IDENTIFICATION => [
'text', $identification->
serialize()],
147 self::R_IDENTIFICATION => [
'text', $resource_identification_string],
148 'position' => [
'integer', (
int) $position + 1],
150 $event_data_container->
append(
154 foreach ($resource_identification_strings as $position => $resource_identification_string) {
156 self::COLLECTION_ASSIGNMENT_TABLE_NAME,
158 self::C_IDENTIFICATION => [
'text', $identification->
serialize()],
159 self::R_IDENTIFICATION => [
'text', $resource_identification_string],
160 'position' => [
'integer', (
int) $position + 1],
163 self::C_IDENTIFICATION => [
'text', $identification->
serialize()],
164 self::R_IDENTIFICATION => [
'text', $resource_identification_string],
169 $this->resource_ids_cache[$identification->
serialize()] = array_values($resource_identification_strings);
170 if ($this->
has($identification)) {
172 self::COLLECTION_TABLE_NAME,
174 self::C_IDENTIFICATION => [
'text', $identification->
serialize()],
175 'title' => [
'text', $title ??
''],
176 'owner_id' => [
'integer', $owner_id],
179 self::C_IDENTIFICATION => [
'text', $identification->
serialize()]
184 self::COLLECTION_TABLE_NAME,
186 self::C_IDENTIFICATION => [
'text', $identification->
serialize()],
187 'title' => [
'text', $title ??
''],
188 'owner_id' => [
'integer', $owner_id],
196 $rid = $resource_identification->
serialize();
198 $this->db->manipulateF(
199 "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME .
" WHERE " . self::R_IDENTIFICATION .
" = %s",
204 foreach ($this->resource_ids_cache as $rcid => $rids) {
205 if (in_array($rid, $rids,
true)) {
206 $this->resource_ids_cache[$rcid] = array_values(array_diff($rids, [$rid]));
215 $this->db->manipulateF(
216 "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME .
" WHERE " . self::C_IDENTIFICATION .
" = %s",
220 $this->db->manipulateF(
221 "DELETE FROM " . self::COLLECTION_TABLE_NAME .
" WHERE " . self::C_IDENTIFICATION .
" = %s",
226 unset($this->resource_ids_cache[$rcid]);
229 public function preload(array $identification_strings): void
231 if ($identification_strings === []) {
235 $identification_strings = array_values(array_unique($identification_strings));
238 foreach ($identification_strings as $rcid) {
239 if (!isset($this->resource_ids_cache[$rcid])) {
240 $this->resource_ids_cache[$rcid] = [];
245 if ($to_load === []) {
249 $q =
"SELECT " . self::C_IDENTIFICATION .
", " . self::R_IDENTIFICATION .
250 " FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME .
251 " WHERE " . $this->db->in(self::C_IDENTIFICATION, $to_load,
false,
'text') .
252 " ORDER BY position ASC";
254 $res = $this->db->query(
$q);
255 while ($row = $this->db->fetchAssoc(
$res)) {
256 $rcid = (string) $row[self::C_IDENTIFICATION];
257 $rid = (string) $row[self::R_IDENTIFICATION];
258 $this->resource_ids_cache[$rcid][] = $rid;
268 if ($collection_identifications === []) {
272 $collection_identifications = array_values(array_unique($collection_identifications));
275 foreach ($collection_identifications as $rcid) {
276 if (!isset($this->resource_ids_cache[$rcid])) {
277 $to_preload[] = $rcid;
280 if ($to_preload !== []) {
281 $this->preload($to_preload);
285 foreach ($collection_identifications as $rcid) {
286 foreach ($this->resource_ids_cache[$rcid] ?? [] as $rid) {
287 $result_rids[] = $rid;
291 $result_rids = array_values(array_unique($result_rids));
Class ResourceCollection.
getResourceIdentifications()
Class ResourceCollectionIdentification.
Class ResourceIdentification.
Class CollectionDBRepository.
update(ResourceCollection $collection, DataContainer $event_data_container)
populateFromArray(array $data)
const COLLECTION_TABLE_NAME
array $resource_ids_cache
const COLLECTION_ASSIGNMENT_TABLE_NAME
clear(ResourceCollectionIdentification $identification)
blank(ResourceCollectionIdentification $identification, ?int $owner_id=null, ?string $title=null)
__construct(protected \ilDBInterface $db)
removeResourceFromAllCollections(ResourceIdentification $resource_identification)
has(ResourceCollectionIdentification $identification)
existing(ResourceCollectionIdentification $identification)
getResourceIdStrings(ResourceCollectionIdentification $identification)
preload(array $identification_strings)
getResourceIdsForCollections(array $collection_identifications)
Interface CollectionRepository.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...