ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 $ilDB;
23 
24  $query = 'SELECT ref_id FROM ecs_node_mapping_a '.
25  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer'). ' '.
26  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
27  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' '.
28  'AND ref_id > 0';
29  $res = $ilDB->query($query);
30  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
31  {
32  return true;
33  }
34  return false;
35  }
36 
45  public static function lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
46  {
47  global $ilDB;
48 
49  $query = 'SELECT title_update, position_update, tree_update FROM ecs_node_mapping_a '.
50  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer'). ' '.
51  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
52  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' '.
53  'AND cs_id = '.$ilDB->quote($a_node_id,'integer');
54  $res = $ilDB->query($query);
55 
56  if(!$res->numRows())
57  {
58  return false;
59  }
60 
61  $settings = array();
62  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
63  {
64  $settings['title_update'] = $row->title_update;
65  $settings['position_update'] = $row->position_update;
66  $settings['tree_update'] = $row->tree_update;
67  }
68  return (array) $settings;
69  }
70 
78  public static function lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
79  {
80  global $ilDB;
81 
82  $query = 'SELECT cs_id FROM ecs_node_mapping_a '.
83  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer'). ' '.
84  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
85  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' '.
86  'AND ref_id > 0';
87  $res = $ilDB->query($query);
88 
89  $assignments = array();
90  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
91  {
92  $assignments[] = $row->cs_id;
93  }
94  return $assignments;
95  }
96 
103  public static function lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
104  {
105  global $ilDB;
106 
107  $query = 'SELECT cs_id FROM ecs_node_mapping_a '.
108  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer'). ' '.
109  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
110  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' '.
111  'AND ref_id = '.$ilDB->quote($a_ref_id,'integer').' ';
112  $res = $ilDB->query($query);
113 
114  $assignments = array();
115  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
116  {
117  $assignments[] = $row->cs_id;
118  }
119  return $assignments;
120  }
121 
122 
128  public static function isWholeTreeMapped($a_server_id, $a_mid, $a_tree_id)
129  {
130  global $ilDB;
131 
132  $query = 'SELECT depth FROM ecs_node_mapping_a '.
133  'JOIN ecs_cms_tree ON (tree = cs_root AND child = cs_id) '.
134  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer').' '.
135  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
136  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' ';
137  $res = $ilDB->query($query);
138  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
139  {
140  return $row->depth == 1;
141  }
142  return false;
143  }
144 
148  public static function lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
149  {
150  global $ilDB;
151 
152  $query = 'SELECT title_update FROM ecs_node_mapping_a '.
153  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer').' '.
154  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
155  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' '.
156  'AND cs_id = '.$ilDB->quote(0,'integer').' ';
157  $res = $ilDB->query($query);
158  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
159  {
160  return (bool) $row->title_update;
161  }
162  return false;
163  }
164 
174  public static function lookupMappedItemsForRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
175  {
176  global $ilDB;
177 
178  $query = 'SELECT cs_id FROM ecs_node_mapping_a '.
179  'WHERE server_id = '.$ilDB->quote($a_server_id,'integer').' '.
180  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
181  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' '.
182  'AND ref_id = '.$ilDB->quote($a_ref_id,'integer').' ';
183  $res = $ilDB->query($query);
184 
185  $cs_ids = array();
186  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
187  {
188  $cs_ids[] = $row->cs_id;
189  }
190  return $cs_ids;
191  }
192 
203  public static function deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $cs_ids)
204  {
205  global $ilDB;
206 
207  $query = 'DELETE FROM ecs_node_mapping_a '.
208  'WHERE server_id = '.$ilDB->quote($a_server_id).' '.
209  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
210  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' '.
211  'AND '.$ilDB->in('cs_id',$cs_ids,false,'integer');
212  $ilDB->manipulate($query);
213  return true;
214  }
215 
224  public static function deleteMappings($a_server_id, $a_mid, $a_tree_id)
225  {
226  global $ilDB;
227 
228  $query = 'DELETE FROM ecs_node_mapping_a '.
229  'WHERE server_id = '.$ilDB->quote($a_server_id).' '.
230  'AND mid = '.$ilDB->quote($a_mid,'integer').' '.
231  'AND cs_root = '.$ilDB->quote($a_tree_id,'integer').' ';
232  $ilDB->manipulate($query);
233  return true;
234  }
235 
242  public static function deleteDisconnectableMappings($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
243  {
244  global $ilDB;
245 
246  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
247  include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
248 
249  $toDelete = array();
250  foreach(self::lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id,$a_ref_id) as $assignment)
251  {
252  $status = ilECSCmsData::lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $assignment);
253 
254  switch($status)
255  {
257  $toDelete[] = $assignment;
258  break;
259 
261  $toDelete[] = $assignment;
262  break;
264  break;
265 
267  $toDelete[] = $assignment;
268  break;
269 
271  $toDelete[] = $assignment;
272  break;
273  }
274  }
275  self::deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $toDelete);
276  }
277 }
278 ?>