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