ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilOrgUnitImporter.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13
17 public $errors = [];
21 public $warnings = [];
25 public $stats;
26
27
34 protected function buildRef($id, $type)
35 {
36 if ($type == 'reference_id') {
37 if (!ilObjOrgUnit::_exists($id, true)) {
38 return false;
39 }
40
41 return $id;
42 } elseif ($type == 'external_id') {
44
45 if(ilObject::_lookupType($obj_id) !== 'orgu') {
46 return false;
47 }
48
50 return false;
51 }
52
53 $ref_ids = ilObject::_getAllReferences($obj_id);
54
55 if (!count($ref_ids)) {
56 return false;
57 }
58
59 foreach ($ref_ids as $ref_id) {
60 if (!ilObject::_isInTrash($ref_id)) {
61 return $ref_id;
62 }
63 }
64
65 return false;
66 } else {
67 return false;
68 }
69 }
70
71
77 public function hasMoreThanOneMatch($external_id)
78 {
79 global $DIC;
80
81 $ilDB = $DIC->database();
82
83 $query = "SELECT * FROM object_data " .
84 "INNER JOIN object_reference as ref on ref.obj_id = object_data.obj_id and ref.deleted is null ".
85 'WHERE object_data.type = "orgu" and import_id = ' . $ilDB->quote($external_id, "text") . " " .
86 "ORDER BY create_date DESC";
87
88 $res = $ilDB->query($query);
89
90 if ($ilDB->numRows($res) > 1) {
91 return true;
92 } else {
93 return false;
94 }
95 }
96
97
101 public function hasErrors()
102 {
103 return count($this->errors) != 0;
104 }
105
106
110 public function hasWarnings()
111 {
112 return count($this->warnings) != 0;
113 }
114
115
121 public function addWarning($lang_var, $import_id, $action = null)
122 {
123 $this->warnings[] = array('lang_var' => $lang_var, 'import_id' => $import_id, 'action' => $action);
124 }
125
126
132 public function addError($lang_var, $import_id, $action = null)
133 {
134 $this->errors[] = array('lang_var' => $lang_var, 'import_id' => $import_id, 'action' => $action);
135 }
136
137
141 public function getErrors()
142 {
143 return $this->errors;
144 }
145
146
150 public function getWarnings()
151 {
152 return $this->warnings;
153 }
154
155
159 public function getStats()
160 {
161 return $this->stats;
162 }
163
164
175 public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
176 {
177 $container_mappings = $a_mapping->getMappingsOfEntity("Services/Container", "objs");
178 foreach ($container_mappings as $old => $new) {
179 if (ilObject2::_lookupType($new) === 'orgu') {
180 $a_mapping->addMapping('Modules/OrgUnit', 'orgu', $old, $new);
181 }
182 }
183 }
184}
An exception for terminatinating execution or to throw for unit testing.
static _exists($a_id, $a_reference=false, $type="orgu")
static _lookupType($a_id, $a_reference=false)
lookup object type
static _getAllReferences($a_id)
get all reference ids of object
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _lookupObjIdByImportId($a_import_id)
static _isInTrash($a_ref_id)
checks wether object is in trash
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilOrgUnitImporter.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
hasMoreThanOneMatch($external_id)
addError($lang_var, $import_id, $action=null)
addWarning($lang_var, $import_id, $action=null)
Xml importer class.
global $DIC
Definition: goto.php:24
$query
$type
foreach($_POST as $key=> $value) $res
global $ilDB