ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CollectionDBRepository.php
Go to the documentation of this file.
1<?php
2
20
27
35{
36 public const COLLECTION_TABLE_NAME = 'il_resource_rc';
37 public const COLLECTION_ASSIGNMENT_TABLE_NAME = 'il_resource_rca';
38 public const R_IDENTIFICATION = 'rid';
39 public const C_IDENTIFICATION = 'rcid';
40
41 public function __construct(protected \ilDBInterface $db)
42 {
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 public function has(ResourceCollectionIdentification $identification): bool
77 {
78 $q = "SELECT EXISTS (
79 SELECT 1 FROM " . self::COLLECTION_TABLE_NAME . "
80 WHERE " . self::C_IDENTIFICATION . " = %s
81 ) AS found";
82
83 $r = $this->db->queryF($q, ['text'], [$identification->serialize()]);
84 $d = $this->db->fetchAssoc($r);
85
86 return (bool) ($d['found'] ?? false);
87 }
88
92 public function getResourceIdStrings(ResourceCollectionIdentification $identification): \Generator
93 {
94 $q = "SELECT " . self::R_IDENTIFICATION . " FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s ORDER BY position ASC";
95 $r = $this->db->queryF($q, ['text'], [$identification->serialize()]);
96 while ($d = $this->db->fetchAssoc($r)) {
97 yield (string) $d[self::R_IDENTIFICATION];
98 }
99 }
100
101 public function clear(ResourceCollectionIdentification $identification): void
102 {
103 $q = "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s";
104 $r = $this->db->manipulateF($q, ['text'], [$identification->serialize()]);
105 }
106
107 public function update(ResourceCollection $collection, DataContainer $event_data_container): void
108 {
109 $identification = $collection->getIdentification();
110 $resource_identifications = $collection->getResourceIdentifications();
111 $owner_id = $collection->getOwner();
112 $title = $collection->getTitle();
113
114 $resource_identification_strings = array_map(
115 static fn(ResourceIdentification $i): string => $i->serialize(),
116 $resource_identifications
117 );
118
119 $q = "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s AND "
120 . $this->db->in(self::R_IDENTIFICATION, $resource_identification_strings, true, 'text');
121 $r = $this->db->manipulateF($q, ['text'], [$identification->serialize()]);
122
123 $missing_resource_identification_string = array_diff(
124 $resource_identification_strings,
125 iterator_to_array($this->getResourceIdStrings($identification))
126 );
127 foreach ($missing_resource_identification_string as $position => $resource_identification_string) {
128 $this->db->insert(self::COLLECTION_ASSIGNMENT_TABLE_NAME, [
129 self::C_IDENTIFICATION => ['text', $identification->serialize()],
130 self::R_IDENTIFICATION => ['text', $resource_identification_string],
131 'position' => ['integer', (int) $position + 1],
132 ]);
133 $event_data_container->append(
134 new CollectionData(['rid' => $resource_identification_string, 'rcid' => $identification->serialize()])
135 );
136 }
137 foreach ($resource_identification_strings as $position => $resource_identification_string) {
138 $this->db->update(
139 self::COLLECTION_ASSIGNMENT_TABLE_NAME,
140 [
141 self::C_IDENTIFICATION => ['text', $identification->serialize()],
142 self::R_IDENTIFICATION => ['text', $resource_identification_string],
143 'position' => ['integer', (int) $position + 1],
144 ],
145 [
146 self::C_IDENTIFICATION => ['text', $identification->serialize()],
147 self::R_IDENTIFICATION => ['text', $resource_identification_string],
148 ]
149 );
150 }
151 if ($this->has($identification)) {
152 $this->db->update(
153 self::COLLECTION_TABLE_NAME,
154 [
155 self::C_IDENTIFICATION => ['text', $identification->serialize()],
156 'title' => ['text', $title ?? ''],
157 'owner_id' => ['integer', $owner_id],
158 ],
159 [
160 self::C_IDENTIFICATION => ['text', $identification->serialize()]
161 ]
162 );
163 } else {
164 $this->db->insert(
165 self::COLLECTION_TABLE_NAME,
166 [
167 self::C_IDENTIFICATION => ['text', $identification->serialize()],
168 'title' => ['text', $title ?? ''],
169 'owner_id' => ['integer', $owner_id],
170 ]
171 );
172 }
173 }
174
175 public function removeResourceFromAllCollections(ResourceIdentification $resource_identification): void
176 {
177 $this->db->manipulateF(
178 "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::R_IDENTIFICATION . " = %s",
179 ['text'],
180 [$resource_identification->serialize()]
181 );
182 }
183
184 public function delete(ResourceCollectionIdentification $identification): void
185 {
186 $this->db->manipulateF(
187 "DELETE FROM " . self::COLLECTION_ASSIGNMENT_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s",
188 ['text'],
189 [$identification->serialize()]
190 );
191 $this->db->manipulateF(
192 "DELETE FROM " . self::COLLECTION_TABLE_NAME . " WHERE " . self::C_IDENTIFICATION . " = %s",
193 ['text'],
194 [$identification->serialize()]
195 );
196 }
197
198 public function preload(array $identification_strings): void
199 {
200 // TODO: Implement preload() method.
201 }
202
203 public function populateFromArray(array $data): void
204 {
205 // TODO: Implement populateFromArray() method.
206 }
207}
update(ResourceCollection $collection, DataContainer $event_data_container)
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)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
has(string $class_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$q
Definition: shib_logout.php:23