/Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignments.php

https://github.com/ILIAS-eLearning/ILIAS · PHP · 287 lines · 170 code · 43 blank · 74 comment · 10 complexity · 681c73de52e76530c29132fae9b420e7 MD5 · raw file

  1. <?php
  2. /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
  3. include_once './Services/WebServices/ECS/classes/Mapping/class.ilECSNodeMappingAssignment.php';
  4. /**
  5. *
  6. *
  7. * @author Stefan Meyer <smeyer.ilias@gmx.de>
  8. * $Id$
  9. */
  10. class ilECSNodeMappingAssignments
  11. {
  12. /**
  13. * Check if there is any assignment for a cms tree
  14. * @param int $a_server_id
  15. * @param int $a_tree_id
  16. */
  17. public static function hasAssignments($a_server_id, $a_mid, $a_tree_id)
  18. {
  19. global $DIC;
  20. $ilDB = $DIC['ilDB'];
  21. $query = 'SELECT ref_id FROM ecs_node_mapping_a ' .
  22. 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
  23. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  24. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
  25. 'AND ref_id > 0';
  26. $res = $ilDB->query($query);
  27. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  28. return true;
  29. }
  30. return false;
  31. }
  32. /**
  33. * Lookup Settings
  34. * @param type $a_server_id
  35. * @param type $a_mid
  36. * @param type $a_tree_id
  37. *
  38. * @return mixed false in case of no specific setting available, array of settings
  39. */
  40. public static function lookupSettings($a_server_id, $a_mid, $a_tree_id, $a_node_id)
  41. {
  42. global $DIC;
  43. $ilDB = $DIC['ilDB'];
  44. $query = 'SELECT title_update, position_update, tree_update FROM ecs_node_mapping_a ' .
  45. 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
  46. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  47. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
  48. 'AND cs_id = ' . $ilDB->quote($a_node_id, 'integer');
  49. $res = $ilDB->query($query);
  50. if (!$res->numRows()) {
  51. return false;
  52. }
  53. $settings = array();
  54. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  55. $settings['title_update'] = $row->title_update;
  56. $settings['position_update'] = $row->position_update;
  57. $settings['tree_update'] = $row->tree_update;
  58. }
  59. return (array) $settings;
  60. }
  61. /**
  62. * Lookup assignments
  63. * @global $ilDB
  64. * @param <type> $a_server_id
  65. * @param <type> $a_mid
  66. * @param <type> $a_tree_id
  67. */
  68. public static function lookupAssignmentIds($a_server_id, $a_mid, $a_tree_id)
  69. {
  70. global $DIC;
  71. $ilDB = $DIC['ilDB'];
  72. $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
  73. 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
  74. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  75. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
  76. 'AND ref_id > 0';
  77. $res = $ilDB->query($query);
  78. $assignments = array();
  79. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  80. $assignments[] = $row->cs_id;
  81. }
  82. return $assignments;
  83. }
  84. /**
  85. * Lookup assignments
  86. * @param <type> $a_server_id
  87. * @param <type> $a_mid
  88. * @param <type> $a_tree_id
  89. */
  90. public static function lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
  91. {
  92. global $DIC;
  93. $ilDB = $DIC['ilDB'];
  94. $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
  95. 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
  96. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  97. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
  98. 'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
  99. $res = $ilDB->query($query);
  100. $assignments = array();
  101. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  102. $assignments[] = $row->cs_id;
  103. }
  104. return $assignments;
  105. }
  106. /**
  107. * Check if whole tree is mapped
  108. * @param int $a_server_id
  109. * @param int $a_tree_id
  110. */
  111. public static function isWholeTreeMapped($a_server_id, $a_mid, $a_tree_id)
  112. {
  113. global $DIC;
  114. $ilDB = $DIC['ilDB'];
  115. $query = 'SELECT depth FROM ecs_node_mapping_a ' .
  116. 'JOIN ecs_cms_tree ON (tree = cs_root AND child = cs_id) ' .
  117. 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
  118. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  119. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
  120. $res = $ilDB->query($query);
  121. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  122. return $row->depth == 1;
  123. }
  124. return false;
  125. }
  126. /**
  127. * Lookup default title update setting
  128. */
  129. public static function lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
  130. {
  131. global $DIC;
  132. $ilDB = $DIC['ilDB'];
  133. $query = 'SELECT title_update FROM ecs_node_mapping_a ' .
  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. 'AND cs_id = ' . $ilDB->quote(0, 'integer') . ' ';
  138. $res = $ilDB->query($query);
  139. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  140. return (bool) $row->title_update;
  141. }
  142. return false;
  143. }
  144. /**
  145. * Get cs ids for ref_id
  146. * @global <type> $ilDB
  147. * @param <type> $a_server_id
  148. * @param <type> $a_mid
  149. * @param <type> $a_tree_id
  150. * @param <type> $a_ref_id
  151. * @return <type>
  152. */
  153. public static function lookupMappedItemsForRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
  154. {
  155. global $DIC;
  156. $ilDB = $DIC['ilDB'];
  157. $query = 'SELECT cs_id FROM ecs_node_mapping_a ' .
  158. 'WHERE server_id = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
  159. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  160. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
  161. 'AND ref_id = ' . $ilDB->quote($a_ref_id, 'integer') . ' ';
  162. $res = $ilDB->query($query);
  163. $cs_ids = array();
  164. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  165. $cs_ids[] = $row->cs_id;
  166. }
  167. return $cs_ids;
  168. }
  169. /**
  170. * Delete mappings
  171. * @global $ilDB
  172. * @param <type> $a_server_id
  173. * @param <type> $a_mid
  174. * @param <type> $a_tree_id
  175. * @param <type> $a_ref_id
  176. * @param <type> $cs_ids
  177. * @return <type>
  178. */
  179. public static function deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $cs_ids)
  180. {
  181. global $DIC;
  182. $ilDB = $DIC['ilDB'];
  183. $query = 'DELETE FROM ecs_node_mapping_a ' .
  184. 'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
  185. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  186. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ' .
  187. 'AND ' . $ilDB->in('cs_id', $cs_ids, false, 'integer');
  188. $ilDB->manipulate($query);
  189. return true;
  190. }
  191. /**
  192. * Delete mappings
  193. * @global $ilDB $ilDB
  194. * @param <type> $a_server_id
  195. * @param <type> $a_mid
  196. * @param <type> $a_tree_id
  197. * @return <type>
  198. */
  199. public static function deleteMappings($a_server_id, $a_mid, $a_tree_id)
  200. {
  201. global $DIC;
  202. $ilDB = $DIC['ilDB'];
  203. $query = 'DELETE FROM ecs_node_mapping_a ' .
  204. 'WHERE server_id = ' . $ilDB->quote($a_server_id) . ' ' .
  205. 'AND mid = ' . $ilDB->quote($a_mid, 'integer') . ' ' .
  206. 'AND cs_root = ' . $ilDB->quote($a_tree_id, 'integer') . ' ';
  207. $ilDB->manipulate($query);
  208. return true;
  209. }
  210. /**
  211. * delete disconnectable mappings
  212. * @param <type> $a_server_id
  213. * @param <type> $a_mid
  214. * @param <type> $a_tree_id
  215. */
  216. public static function deleteDisconnectableMappings($a_server_id, $a_mid, $a_tree_id, $a_ref_id)
  217. {
  218. global $DIC;
  219. $ilDB = $DIC['ilDB'];
  220. include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsTree.php';
  221. include_once './Services/WebServices/ECS/classes/Tree/class.ilECSCmsData.php';
  222. $toDelete = array();
  223. foreach (self::lookupAssignmentsByRefId($a_server_id, $a_mid, $a_tree_id, $a_ref_id) as $assignment) {
  224. $status = ilECSCmsData::lookupStatusByCmsId($a_server_id, $a_mid, $a_tree_id, $assignment);
  225. switch ($status) {
  226. case ilECSCmsData::MAPPING_UNMAPPED:
  227. $toDelete[] = $assignment;
  228. break;
  229. case ilECSCmsData::MAPPING_PENDING_DISCONNECTABLE:
  230. $toDelete[] = $assignment;
  231. break;
  232. case ilECSCmsData::MAPPING_PENDING_NOT_DISCONNECTABLE:
  233. break;
  234. case ilECSCmsData::MAPPING_MAPPED:
  235. $toDelete[] = $assignment;
  236. break;
  237. case ilECSCmsData::MAPPING_DELETED:
  238. $toDelete[] = $assignment;
  239. break;
  240. }
  241. }
  242. self::deleteMappingsByCsId($a_server_id, $a_mid, $a_tree_id, $toDelete);
  243. }
  244. }