ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSNodeMappingAssignments.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
29 public static function hasAssignments(int $a_server_id, int $a_mid, int $a_tree_id): bool
30 {
31 global $DIC;
32
36 $ilDB = $DIC['ilDB'];
37
38 $query = 'SELECT ref_id FROM ecs_node_mapping_a ' .
39 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
40 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
41 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
42 'AND ref_id > 0';
43 $res = $ilDB->query($query);
44 return $res->rowCount() > 0;
45 }
46
52 public static function lookupSettings(int $a_server_id, int $a_mid, int $a_tree_id, int $a_node_id)
53 {
54 global $DIC;
55
56 $ilDB = $DIC['ilDB'];
57
58 $query = 'SELECT title_update, position_update, tree_update FROM ecs_node_mapping_a ' .
59 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
60 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
61 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
62 'AND cs_id = ' . $ilDB->quote($a_node_id, 'integer');
63 $res = $ilDB->query($query);
64
65 if (!$res->numRows()) {
66 return false;
67 }
68
69 $settings = [];
70 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
71 $settings['title_update'] = $row->title_update;
72 $settings['position_update'] = $row->position_update;
73 $settings['tree_update'] = $row->tree_update;
74 }
75 return $settings;
76 }
77
81 public static function lookupAssignmentIds(int $a_server_id, int $a_mid, int $a_tree_id): array
82 {
83 global $DIC;
84
85 $ilDB = $DIC['ilDB'];
86
87 $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
88 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
89 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
90 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
91 'AND ref_id > 0';
92 $res = $ilDB->query($query);
93
94 $assignments = array();
95 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
96 $assignments[] = $row->cs_id;
97 }
98 return $assignments;
99 }
100
104 public static function lookupAssignmentsByRefId(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id): array
105 {
106 global $DIC;
107
108 $ilDB = $DIC['ilDB'];
109
110 $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
111 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
112 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
113 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
114 'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
115 $res = $ilDB->query($query);
116
117 $assignments = array();
118 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
119 $assignments[] = $row->cs_id;
120 }
121 return $assignments;
122 }
123
124
128 public static function isWholeTreeMapped(int $a_server_id, int $a_mid, int $a_tree_id): bool
129 {
130 global $DIC;
131
132 $ilDB = $DIC['ilDB'];
133
134 $query = 'SELECT depth FROM ecs_node_mapping_a ' .
135 'JOIN ecs_cms_tree ON (tree = cs_root AND child = cs_id) ' .
136 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
137 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
138 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
139 $res = $ilDB->query($query);
140 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
141 return $row->depth === 1;
142 }
143 return false;
144 }
145
149 public static function lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id): bool
150 {
151 global $DIC;
152
153 $ilDB = $DIC['ilDB'];
154
155 $query = 'SELECT title_update FROM ecs_node_mapping_a ' .
156 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
157 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
158 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
159 'AND cs_id = ' . $ilDB->quote(0, 'integer') . ' ';
160 $res = $ilDB->query($query);
161 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
162 return (bool) $row->title_update;
163 }
164 return false;
165 }
166
170 public static function lookupMappedItemsForRefId(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id): array
171 {
172 global $DIC;
173
174 $ilDB = $DIC['ilDB'];
175
176 $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
177 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
178 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
179 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
180 'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
181 $res = $ilDB->query($query);
182
183 $cs_ids = array();
184 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
185 $cs_ids[] = $row->cs_id;
186 }
187 return $cs_ids;
188 }
189
193 public static function deleteMappingsByCsId(int $a_server_id, int $a_mid, int $a_tree_id, array $cs_ids): bool
194 {
195 global $DIC;
196
197 $ilDB = $DIC['ilDB'];
198
199 $query = 'DELETE FROM ecs_node_mapping_a ' .
200 'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
201 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
202 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
203 'AND ' . $ilDB->in('cs_id', $cs_ids, false, 'integer');
204 $ilDB->manipulate($query);
205 return true;
206 }
207
211 public static function deleteMappings(int $a_server_id, int $a_mid, int $a_tree_id): bool
212 {
213 global $DIC;
214
215 $ilDB = $DIC['ilDB'];
216
217 $query = 'DELETE FROM ecs_node_mapping_a ' .
218 'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
219 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
220 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
221 $ilDB->manipulate($query);
222 return true;
223 }
224
228 public static function deleteDisconnectableMappings(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id): void
229 {
230 $toDelete = array();
231 foreach (self::lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id) as $assignment) {
232 $status = ilECSCmsData::lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $assignment);
233
234 switch ($status) {
239 $toDelete[] = $assignment;
240 break;
241
243 break;
244 }
245 }
246 self::deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $toDelete);
247 }
248}
const MAPPING_PENDING_DISCONNECTABLE
const MAPPING_PENDING_NOT_DISCONNECTABLE
static lookupStatusByCmsId(int $a_server_id, int $a_mid, int $a_tree_id, string $cms_id)
Lookup status.
static deleteDisconnectableMappings(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id)
delete disconnectable mappings
static lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
Lookup default title update setting.
static isWholeTreeMapped(int $a_server_id, int $a_mid, int $a_tree_id)
Check if whole tree is mapped.
static deleteMappingsByCsId(int $a_server_id, int $a_mid, int $a_tree_id, array $cs_ids)
Delete mappings.
static lookupAssignmentsByRefId(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id)
Lookup assignments.
static lookupSettings(int $a_server_id, int $a_mid, int $a_tree_id, int $a_node_id)
Lookup Settings.
static lookupMappedItemsForRefId(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id)
Get cs ids for ref_id.
static deleteMappings(int $a_server_id, int $a_mid, int $a_tree_id)
Delete mappings.
static lookupAssignmentIds(int $a_server_id, int $a_mid, int $a_tree_id)
Lookup assignments.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26