ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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::_hasUntrashedReference($obj_id)) {
46  return false;
47  }
48 
49  $ref_ids = ilObject::_getAllReferences($obj_id);
50 
51  if (!count($ref_ids)) {
52  return false;
53  }
54 
55  foreach ($ref_ids as $ref_id) {
56  if (!ilObject::_isInTrash($ref_id)) {
57  return $ref_id;
58  }
59  }
60  return false;
61  } else {
62  return false;
63  }
64  }
65 
70  public function hasMoreThanOneMatch($external_id)
71  {
72  global $DIC;
73 
74  $ilDB = $DIC->database();
75 
76  $query = "SELECT * FROM object_data " .
77  "INNER JOIN object_reference as ref on ref.obj_id = object_data.obj_id and ref.deleted is null ".
78  'WHERE object_data.type = "orgu" and import_id = ' . $ilDB->quote($external_id, "text") . " " .
79  "ORDER BY create_date DESC";
80  $res = $ilDB->query($query);
81 
82  if ($ilDB->numRows($res) > 1) {
83  return true;
84  } else {
85  return false;
86  }
87  }
88 
89 
90 
94  public function hasErrors()
95  {
96  return count($this->errors) != 0;
97  }
98 
99 
103  public function hasWarnings()
104  {
105  return count($this->warnings) != 0;
106  }
107 
108 
114  public function addWarning($lang_var, $import_id, $action = null)
115  {
116  $this->warnings[] = array( 'lang_var' => $lang_var, 'import_id' => $import_id, 'action' => $action );
117  }
118 
119 
125  public function addError($lang_var, $import_id, $action = null)
126  {
127  $this->errors[] = array( 'lang_var' => $lang_var, 'import_id' => $import_id, 'action' => $action );
128  }
129 
130 
134  public function getErrors()
135  {
136  return $this->errors;
137  }
138 
139 
143  public function getWarnings()
144  {
145  return $this->warnings;
146  }
147 
148 
152  public function getStats()
153  {
154  return $this->stats;
155  }
156 
157 
168  public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
169  {
170  $container_mappings = $a_mapping->getMappingsOfEntity("Services/Container", "objs");
171  foreach ($container_mappings as $old => $new) {
173  if (ilObject2::_lookupType($new) == "orgu") {
174  $a_mapping->addMapping("Modules/OrgUnit", "orgu", $old, $new);
175  }
176  }
177  }
178 }
hasMoreThanOneMatch($external_id)
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
$action
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
static _exists($a_id, $a_reference=false, $type="orgu")
static _isInTrash($a_ref_id)
checks wether object is in trash
addWarning($lang_var, $import_id, $action=null)
addError($lang_var, $import_id, $action=null)
static _getAllReferences($a_id)
get all reference ids of object
foreach($_POST as $key=> $value) $res
Class ilOrgUnitImporter.
importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping)
$query
static _lookupType($a_id, $a_reference=false)
global $ilDB
static _lookupObjIdByImportId($a_import_id)
Xml importer class.