ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilOrgUnitImporter.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  /* @var array $lang_var => language variable, import_id => the reference or import id, depending on the ou_id_type */
29  public array $errors = [];
30  /* @var array lang_var => language variable, import_id => the reference or import id, depending on the ou_id_type */
31  public array $warnings = [];
32  /* @var array keys in {updated, edited, deleted} */
33  public array $stats;
35 
36  public function __construct()
37  {
38  global $DIC;
39  $this->database = $DIC->database();
40  }
41 
46  protected function buildRef($id, string $type) /*: bool|int*/
47  {
48  if (!is_int($id) && !is_string($id)) {
49  throw new \InvalidArgumentException("Expected int or string as \$id, got: " . gettype($id));
50  }
51 
52  if ($type === 'reference_id') {
53  if (!ilObjOrgUnit::_exists((int) $id, true)) {
54  return false;
55  }
56 
57  return $id;
58  } elseif ($type === 'external_id') {
60 
61  if (ilObject::_lookupType($obj_id) !== 'orgu') {
62  return false;
63  }
64 
65  if (!ilObject::_hasUntrashedReference($obj_id)) {
66  return false;
67  }
68 
69  $ref_ids = ilObject::_getAllReferences($obj_id);
70 
71  if (!count($ref_ids)) {
72  return false;
73  }
74 
75  foreach ($ref_ids as $ref_id) {
76  if (!ilObject::_isInTrash($ref_id)) {
77  return $ref_id;
78  }
79  }
80 
81  return false;
82  } else {
83  return false;
84  }
85  }
86 
87  public function hasMoreThanOneMatch(string $external_id): bool
88  {
89  $query = "SELECT * FROM object_data " .
90  "INNER JOIN object_reference as ref on ref.obj_id = object_data.obj_id and ref.deleted is null " .
91  'WHERE object_data.type = "orgu" and import_id = ' . $this->database->quote($external_id, "text") . " " .
92  "ORDER BY create_date DESC";
93 
94  $res = $this->database->query($query);
95 
96  if ($this->database->numRows($res) > 1) {
97  return true;
98  } else {
99  return false;
100  }
101  }
102 
103  public function hasErrors(): bool
104  {
105  return count($this->errors) != 0;
106  }
107 
108  public function hasWarnings(): bool
109  {
110  return count($this->warnings) != 0;
111  }
112 
113  public function addWarning(string $lang_var, string $import_id, ?string $action = null): void
114  {
115  $this->warnings[] = array('lang_var' => $lang_var, 'import_id' => $import_id, 'action' => $action);
116  }
117 
118  public function addError(string $lang_var, string $import_id, ?string $action = null): void
119  {
120  $this->errors[] = array('lang_var' => $lang_var, 'import_id' => $import_id, 'action' => $action);
121  }
122 
123  public function getErrors(): array
124  {
125  return $this->errors;
126  }
127 
128  public function getWarnings(): array
129  {
130  return $this->warnings;
131  }
132 
133  public function getStats(): array
134  {
135  return $this->stats;
136  }
137 
139  public function importXmlRepresentation(
140  string $a_entity,
141  string $a_id,
142  string $a_xml,
143  ilImportMapping $a_mapping
144  ): void {
145  $container_mappings = $a_mapping->getMappingsOfEntity("components/ILIAS/Container", "objs");
146  foreach ($container_mappings as $old => $new) {
147  if (ilObject2::_lookupType($new) === 'orgu') {
148  $a_mapping->addMapping('components/ILIAS/OrgUnit', 'orgu', $old, $new);
149  }
150  }
151  }
152 }
static _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getAllReferences(int $id)
get all reference ids for object ID
static _hasUntrashedReference(int $obj_id)
checks whether an object has at least one reference that is not in trash
static _exists(int $id, bool $isReference=false, ?string $type="orgu")
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
hasMoreThanOneMatch(string $external_id)
importXmlRepresentation(string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
$ref_id
Definition: ltiauth.php:66
buildRef($id, string $type)
getMappingsOfEntity(string $a_comp, string $a_entity)
static _isInTrash(int $ref_id)
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addError(string $lang_var, string $import_id, ?string $action=null)
addWarning(string $lang_var, string $import_id, ?string $action=null)