19 declare(strict_types=1);
35 protected \ilDBInterface
$db;
51 is_null($this->
table($table)) ||
52 is_null($this->
IDName($table))
54 throw new \ilMDRepositoryException(
'Invalid MD table: ' . $table);
58 protected function table(
string $table): ?string
63 protected function IDName(
string $table): ?string
72 $create_assignments = [];
73 $update_assignments = [];
74 $delete_assignments = [];
75 $delete_full_row =
false;
76 $create_new_row =
false;
78 foreach ($row->
actions() as $action) {
79 switch ($action->action()) {
81 $create_assignments[] = $action;
82 if ($action->tag()->hasRowInTable()) {
83 $create_new_row =
true;
88 $update_assignments[] = $action;
92 $delete_assignments[] = $action;
93 if ($action->tag()->hasRowInTable()) {
94 $delete_full_row =
true;
99 if ($delete_full_row) {
100 $this->
delete($row->
table(), $row->
id());
103 if ($create_new_row) {
109 ...$create_assignments
116 ...$create_assignments,
117 ...$update_assignments,
118 ...$delete_assignments
126 int $id_from_parent_table,
130 $table_name = $this->
table($table);
131 $has_parent = $assignments[0]->
tag()->hasParent();
132 $parent = $assignments[0]->
tag()->parent();
133 $id_field = $this->
IDName($table);
136 $this->db->quoteIdentifier($id_field),
148 $fields[] =
'parent_type';
150 $fields[] =
'parent_id';
153 foreach ($assignments as $assignment) {
154 $tag = $assignment->tag();
155 if ($tag->hasData() && (
$data = $assignment->value()) !==
'') {
156 $fields[] = $this->db->quoteIdentifier($tag->dataField());
161 $this->db->manipulate(
162 'INSERT INTO ' . $this->db->quoteIdentifier($table_name) .
' (' .
163 implode(
', ', $fields) .
') VALUES (' . implode(
', ', $values) .
')' 172 int $id_from_parent_table,
175 $table = $tags[0]->
table();
178 $parent = $tags[0]->
parent();
179 $id_field = $this->
IDName($table);
181 $selected_fields[] = $this->db->quoteIdentifier($id_field);
182 foreach ($tags as $tag) {
183 if ($tag->hasData()) {
184 $selected_fields[] = $this->db->quoteIdentifier($tag->dataField());
196 $order =
'ORDER BY ' . $this->db->quoteIdentifier($id_field);
198 $result = $this->db->query(
199 'SELECT ' . implode(
', ', $selected_fields) .
' FROM ' .
200 $this->db->quoteIdentifier($this->table($table)) .
' WHERE ' .
201 implode(
' AND ', $where) .
' ' . $order
204 while ($row = $this->db->fetchAssoc($result)) {
207 foreach ($row as $field => $value) {
208 if ($field === $id_field) {
212 $data[] = $this->data_row_factory->field($field, $value ??
'');
214 yield $this->data_row_factory->row(
$id, $table, ...
$data);
224 $id_field = $this->
IDName($table);
226 $updated_fields = [];
227 foreach ($assignments as $assignment) {
228 $tag = $assignment->tag();
229 if (!$tag->hasData()) {
233 $updated_fields[] = $this->db->quoteIdentifier($tag->dataField()) .
" = ''";
236 if ((
$data = $assignment->value()) !==
'') {
237 $updated_fields[] = $this->db->quoteIdentifier($tag->dataField()) .
' = ' .
242 if (empty($updated_fields)) {
246 $this->db->manipulate(
247 'UPDATE ' . $this->db->quoteIdentifier($this->table($table)) .
' SET ' .
248 implode(
', ', $updated_fields) .
' WHERE ' . $this->db->quoteIdentifier($id_field) .
253 protected function delete(
258 $table_name = $this->
table($table);
259 $id_field = $this->
IDName($table);
261 $this->db->manipulate(
262 'DELETE FROM ' . $this->db->quoteIdentifier($table_name) .
' WHERE ' .
263 $this->db->quoteIdentifier($id_field) .
' = ' .
270 $rbac_id = $ressource_id->
objID();
271 $obj_id = $ressource_id->
subID();
272 $obj_type = $ressource_id->
type();
274 $query =
"DELETE FROM " . $this->db->quoteIdentifier($table) .
" " .
279 $this->db->manipulate($query);
286 return $this->db->nextId($this->
table($table));
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins