ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4include_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}
An exception for terminatinating execution or to throw for unit testing.
const MAPPING_PENDING_DISCONNECTABLE
const MAPPING_PENDING_NOT_DISCONNECTABLE
static lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $cms_id)
Lookup status.
static lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
Lookup default title update setting.
static hasAssignments($a_server_id, $a_mid, $a_tree_id)
Check if there is any assignment for a cms tree.
static lookupMappedItemsForRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
Get cs ids for ref_id @global <type> $ilDB.
static isWholeTreeMapped($a_server_id, $a_mid, $a_tree_id)
Check if whole tree is mapped.
static deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $cs_ids)
Delete mappings @global $ilDB.
static deleteMappings($a_server_id, $a_mid, $a_tree_id)
Delete mappings @global $ilDB $ilDB.
static lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
Lookup Settings.
static lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
Lookup assignments @global $ilDB.
static lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
Lookup assignments.
static deleteDisconnectableMappings($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
delete disconnectable mappings
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB