ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilECSNodeMappingAssignments.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
5 
13 {
14 
20  public static function hasAssignments($a_server_id, $a_mid, $a_tree_id)
21  {
22  global $DIC;
23 
24  $ilDB = $DIC['ilDB'];
25 
26  $query = 'SELECT ref_id FROM ecs_node_mapping_a ' .
27  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
28  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
29  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
30  'AND ref_id > 0';
31  $res = $ilDB->query($query);
32  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
33  return true;
34  }
35  return false;
36  }
37 
46  public static function lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
47  {
48  global $DIC;
49 
50  $ilDB = $DIC['ilDB'];
51 
52  $query = 'SELECT title_update, position_update, tree_update FROM ecs_node_mapping_a ' .
53  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
54  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
55  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
56  'AND cs_id = ' . $ilDB->quote($a_node_id, 'integer');
57  $res = $ilDB->query($query);
58 
59  if (!$res->numRows()) {
60  return false;
61  }
62 
63  $settings = array();
64  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
65  $settings['title_update'] = $row->title_update;
66  $settings['position_update'] = $row->position_update;
67  $settings['tree_update'] = $row->tree_update;
68  }
69  return (array) $settings;
70  }
71 
79  public static function lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
80  {
81  global $DIC;
82 
83  $ilDB = $DIC['ilDB'];
84 
85  $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
86  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
87  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
88  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
89  'AND ref_id > 0';
90  $res = $ilDB->query($query);
91 
92  $assignments = array();
93  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
94  $assignments[] = $row->cs_id;
95  }
96  return $assignments;
97  }
98 
105  public static function lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
106  {
107  global $DIC;
108 
109  $ilDB = $DIC['ilDB'];
110 
111  $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
112  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
113  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
114  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
115  'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
116  $res = $ilDB->query($query);
117 
118  $assignments = array();
119  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
120  $assignments[] = $row->cs_id;
121  }
122  return $assignments;
123  }
124 
125 
131  public static function isWholeTreeMapped($a_server_id, $a_mid, $a_tree_id)
132  {
133  global $DIC;
134 
135  $ilDB = $DIC['ilDB'];
136 
137  $query = 'SELECT depth FROM ecs_node_mapping_a ' .
138  'JOIN ecs_cms_tree ON (tree = cs_root AND child = cs_id) ' .
139  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
140  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
141  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
142  $res = $ilDB->query($query);
143  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144  return $row->depth == 1;
145  }
146  return false;
147  }
148 
152  public static function lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
153  {
154  global $DIC;
155 
156  $ilDB = $DIC['ilDB'];
157 
158  $query = 'SELECT title_update FROM ecs_node_mapping_a ' .
159  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
160  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
161  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
162  'AND cs_id = ' . $ilDB->quote(0, 'integer') . ' ';
163  $res = $ilDB->query($query);
164  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
165  return (bool) $row->title_update;
166  }
167  return false;
168  }
169 
179  public static function lookupMappedItemsForRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
180  {
181  global $DIC;
182 
183  $ilDB = $DIC['ilDB'];
184 
185  $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
186  'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
187  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
188  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
189  'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
190  $res = $ilDB->query($query);
191 
192  $cs_ids = array();
193  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
194  $cs_ids[] = $row->cs_id;
195  }
196  return $cs_ids;
197  }
198 
209  public static function deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $cs_ids)
210  {
211  global $DIC;
212 
213  $ilDB = $DIC['ilDB'];
214 
215  $query = 'DELETE FROM ecs_node_mapping_a ' .
216  'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
217  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
218  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
219  'AND ' . $ilDB->in('cs_id', $cs_ids, false, 'integer');
220  $ilDB->manipulate($query);
221  return true;
222  }
223 
232  public static function deleteMappings($a_server_id, $a_mid, $a_tree_id)
233  {
234  global $DIC;
235 
236  $ilDB = $DIC['ilDB'];
237 
238  $query = 'DELETE FROM ecs_node_mapping_a ' .
239  'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
240  'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
241  'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
242  $ilDB->manipulate($query);
243  return true;
244  }
245 
252  public static function deleteDisconnectableMappings($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
253  {
254  global $DIC;
255 
256  $ilDB = $DIC['ilDB'];
257 
258  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
259  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
260 
261  $toDelete = array();
262  foreach (self::lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id) as $assignment) {
263  $status = ilECSCmsData::lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $assignment);
264 
265  switch ($status) {
267  $toDelete[] = $assignment;
268  break;
269 
271  $toDelete[] = $assignment;
272  break;
274  break;
275 
277  $toDelete[] = $assignment;
278  break;
279 
281  $toDelete[] = $assignment;
282  break;
283  }
284  }
285  self::deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $toDelete);
286  }
287 }
const MAPPING_PENDING_DISCONNECTABLE
global $DIC
Definition: saml.php:7
static lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $cms_id)
Lookup status.
static deleteMappings($a_server_id, $a_mid, $a_tree_id)
Delete mappings $ilDB $ilDB.
static lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
Lookup default title update setting.
static isWholeTreeMapped($a_server_id, $a_mid, $a_tree_id)
Check if whole tree is mapped.
foreach($_POST as $key=> $value) $res
static deleteDisconnectableMappings($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
delete disconnectable mappings
static deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $cs_ids)
Delete mappings $ilDB.
static hasAssignments($a_server_id, $a_mid, $a_tree_id)
Check if there is any assignment for a cms tree.
$query
static lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
Lookup assignments.
$row
global $ilDB
static lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
Lookup assignments $ilDB.
static lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
Lookup Settings.
static lookupMappedItemsForRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
Get cs ids for ref_id <type> $ilDB.
const MAPPING_PENDING_NOT_DISCONNECTABLE