ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $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(ilDBConstants::FETCHMODE_OBJECT)) {
31 return true;
32 }
33 return false;
34 }
35
44 public static function lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
45 {
46 global $ilDB;
47
48 $query = 'SELECT title_update, position_update, tree_update FROM ecs_node_mapping_a ' .
49 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
50 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
51 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
52 'AND cs_id = ' . $ilDB->quote($a_node_id, 'integer');
53 $res = $ilDB->query($query);
54
55 if (!$res->numRows()) {
56 return false;
57 }
58
59 $settings = array();
60 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
61 $settings['title_update'] = $row->title_update;
62 $settings['position_update'] = $row->position_update;
63 $settings['tree_update'] = $row->tree_update;
64 }
65 return (array) $settings;
66 }
67
75 public static function lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
76 {
77 global $ilDB;
78
79 $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
80 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
81 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
82 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
83 'AND ref_id > 0';
84 $res = $ilDB->query($query);
85
86 $assignments = array();
87 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
88 $assignments[] = $row->cs_id;
89 }
90 return $assignments;
91 }
92
99 public static function lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
100 {
101 global $ilDB;
102
103 $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
104 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
105 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
106 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
107 'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
108 $res = $ilDB->query($query);
109
110 $assignments = array();
111 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
112 $assignments[] = $row->cs_id;
113 }
114 return $assignments;
115 }
116
117
123 public static function isWholeTreeMapped($a_server_id, $a_mid, $a_tree_id)
124 {
125 global $ilDB;
126
127 $query = 'SELECT depth FROM ecs_node_mapping_a ' .
128 'JOIN ecs_cms_tree ON (tree = cs_root AND child = cs_id) ' .
129 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
130 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
131 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
132 $res = $ilDB->query($query);
133 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
134 return $row->depth == 1;
135 }
136 return false;
137 }
138
142 public static function lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
143 {
144 global $ilDB;
145
146 $query = 'SELECT title_update FROM ecs_node_mapping_a ' .
147 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
148 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
149 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
150 'AND cs_id = ' . $ilDB->quote(0, 'integer') . ' ';
151 $res = $ilDB->query($query);
152 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
153 return (bool) $row->title_update;
154 }
155 return false;
156 }
157
167 public static function lookupMappedItemsForRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
168 {
169 global $ilDB;
170
171 $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
172 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
173 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
174 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
175 'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
176 $res = $ilDB->query($query);
177
178 $cs_ids = array();
179 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
180 $cs_ids[] = $row->cs_id;
181 }
182 return $cs_ids;
183 }
184
195 public static function deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $cs_ids)
196 {
197 global $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
216 public static function deleteMappings($a_server_id, $a_mid, $a_tree_id)
217 {
218 global $ilDB;
219
220 $query = 'DELETE FROM ecs_node_mapping_a ' .
221 'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
222 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
223 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
224 $ilDB->manipulate($query);
225 return true;
226 }
227
234 public static function deleteDisconnectableMappings($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
235 {
236 global $ilDB;
237
238 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
239 include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
240
241 $toDelete = array();
242 foreach (self::lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id) as $assignment) {
243 $status = ilECSCmsData::lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $assignment);
244
245 switch ($status) {
247 $toDelete[] = $assignment;
248 break;
249
251 $toDelete[] = $assignment;
252 break;
254 break;
255
257 $toDelete[] = $assignment;
258 break;
259
261 $toDelete[] = $assignment;
262 break;
263 }
264 }
265 self::deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $toDelete);
266 }
267}
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
$query
foreach($_POST as $key=> $value) $res
global $ilDB