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