ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilOrgUnitSimpleImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilOrgUnitSimpleImport:
+ Collaboration diagram for ilOrgUnitSimpleImport:

Public Member Functions

 simpleImport (string $file_path)
 
 simpleImportElement (SimpleXMLElement $o)
 
- Public Member Functions inherited from ilOrgUnitImporter
 __construct ()
 
 hasMoreThanOneMatch (string $external_id)
 
 hasErrors ()
 
 hasWarnings ()
 
 addWarning (string $lang_var, string $import_id, ?string $action=null)
 
 addError (string $lang_var, string $import_id, ?string $action=null)
 
 getErrors ()
 
 getWarnings ()
 
 getStats ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
- Public Member Functions inherited from ilXmlImporter
 __construct ()
 
 setImport (ilImport $a_val)
 
 getImport ()
 
 init ()
 
 setInstallId (string $a_val)
 
 getInstallId ()
 
 setInstallUrl (string $a_val)
 
 getInstallUrl ()
 
 setSchemaVersion (string $a_val)
 
 getSchemaVersion ()
 
 setImportDirectory (string $a_val)
 
 getImportDirectory ()
 
 setSkipEntities (array $a_val)
 
 getSkipEntities ()
 
 exportedFromSameInstallation ()
 
 importXmlRepresentation (string $a_entity, string $a_id, string $a_xml, ilImportMapping $a_mapping)
 
 finalProcessing (ilImportMapping $a_mapping)
 
 afterContainerImportProcessing (ilImportMapping $mapping)
 

Protected Member Functions

 moveObject (int $ref_id, int $parent_ref_id, string $ou_id, string $external_id)
 
- Protected Member Functions inherited from ilOrgUnitImporter
 buildRef ($id, string $type)
 

Additional Inherited Members

- Data Fields inherited from ilOrgUnitImporter
array $errors = []
 
array $warnings = []
 
array $stats
 
- Protected Attributes inherited from ilXmlImporter
array $skip_entities = array()
 
ilImport $imp
 
string $install_id
 
string $install_url
 
string $schema_version
 
string $import_directory
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilOrgUnitSimpleImport

Author
: Oskar Truffer ot@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
: Martin Studer ms@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 24 of file class.ilOrgUnitSimpleImport.php.

Member Function Documentation

◆ moveObject()

ilOrgUnitSimpleImport::moveObject ( int  $ref_id,
int  $parent_ref_id,
string  $ou_id,
string  $external_id 
)
protected
Parameters
string$ou_idthis is only needed for displaying the warning.
string$external_idthis is only needed for displaying the warning.

Definition at line 158 of file class.ilOrgUnitSimpleImport.php.

159 {
160 global $DIC;
161 $tree = $DIC['tree'];
162 if ($parent_ref_id != $tree->getParentId($ref_id)) {
163 try {
164 $path = $tree->getPathId($parent_ref_id);
165 if (in_array($ref_id, $path)) {
166 $this->addWarning("not_movable_to_subtree", $ou_id ? $ou_id : $external_id, "update");
167 } else {
168 $tree->moveTree($ref_id, $parent_ref_id);
169 }
170 } catch (Exception $e) {
171 global $DIC;
172 $ilLog = $DIC['ilLog'];
173 $this->addWarning("not_movable", $ou_id ? $ou_id : $external_id, "update");
174 $ilLog->write($e->getMessage() . "\\n" . $e->getTraceAsString());
175 error_log($e->getMessage() . "\\n" . $e->getTraceAsString());
176 }
177 }
178 }
addWarning(string $lang_var, string $import_id, ?string $action=null)
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30
global $DIC
Definition: shib_login.php:26

References $DIC, Vendor\Package\$e, $path, $ref_id, and ilOrgUnitImporter\addWarning().

Referenced by simpleImportElement().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simpleImport()

ilOrgUnitSimpleImport::simpleImport ( string  $file_path)

Definition at line 26 of file class.ilOrgUnitSimpleImport.php.

27 {
28 $this->stats = array("created" => 0, "updated" => 0, "deleted" => 0);
29 $a = file_get_contents($file_path, "r");
30 $xml = new SimpleXMLElement($a);
31
32 if (!count($xml->OrgUnit)) {
33 $this->addError("no_orgunit", $xml->external_id, null);
34 return;
35 }
36
37 foreach ($xml->OrgUnit as $o) {
38 $this->simpleImportElement($o);
39 }
40 }
addError(string $lang_var, string $import_id, ?string $action=null)
simpleImportElement(SimpleXMLElement $o)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, ilOrgUnitImporter\addError(), and simpleImportElement().

+ Here is the call graph for this function:

◆ simpleImportElement()

ilOrgUnitSimpleImport::simpleImportElement ( SimpleXMLElement  $o)

Definition at line 42 of file class.ilOrgUnitSimpleImport.php.

43 {
44 global $DIC;
45 $ilUser = $DIC['ilUser'];
46 $title = (string) $o->title;
47 $description = (string) $o->description;
48 $external_id = (string) $o->external_id;
49 $create_mode = true;
50 $attributes = $o->attributes();
51 $action = (string) $attributes->action;
52 $ou_id = (string) $attributes->ou_id;
53 $ou_id_type = (string) $attributes->ou_id_type;
54 $ou_parent_id = (string) $attributes->ou_parent_id;
55 $ou_parent_id_type = (string) $attributes->ou_parent_id_type;
56
57 if ($ou_id == ilObjOrgUnit::getRootOrgRefId()) {
58 $this->addWarning("cannot_change_root_node", $ou_id ? $ou_id : $external_id, $action);
59
60 return;
61 }
62
63 if ($ou_parent_id == "__ILIAS") {
64 $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
65 $ou_parent_id_type = "reference_id";
66 }
67
68 //see mantis 0024601
69 if ($ou_id_type == 'external_id') {
70 if (strlen($external_id) == 0) {
71 $external_id = $ou_id;
72 }
73
74 if ($this->hasMoreThanOneMatch($external_id)) {
75 $this->addError("ou_more_than_one_match_found", $external_id, $action);
76
77 return;
78 }
79 }
80
81 $ref_id = $this->buildRef($ou_id, $ou_id_type);
82 $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
83
84 if ($action == "delete") {
85 if (!$parent_ref_id) {
86 $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
87
88 return;
89 }
90 if (!$ref_id) {
91 $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
92
93 return;
94 }
95 $ru = new ilRepUtil($this);
96 try {
97 $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
98 $this->stats["deleted"]++;
99 } catch (Exception $e) {
100 $this->addWarning("orgu_already_deleted", $ou_id ? $ou_id : $external_id, $action);
101 }
102
103 return;
104 } elseif ($action == "update") {
105 if (!$parent_ref_id) {
106 $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
107
108 return;
109 }
110 if (!$ref_id) {
111 $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
112
113 return;
114 }
115 $object = new ilObjOrgUnit($ref_id);
116 $object->setTitle($title);
117
118 $object->updateTranslation($title, $description, $ilUser->getLanguage(), "");
119
120 $object->setDescription($description);
121 $object->update();
122 $object->setImportId($external_id);
123 $this->moveObject($ref_id, $parent_ref_id, $ou_id, $external_id);
124
125 $this->stats["updated"]++;
126 } elseif ($action == "create") {
127 if (!$parent_ref_id) {
128 $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
129
130 return;
131 }
132 if ($external_id) {
133 $obj_id = ilObject::_lookupObjIdByImportId($external_id);
134 if (ilObject::_hasUntrashedReference($obj_id) && ilObject::_lookupType($obj_id) == 'orgu') {
135 $this->addError("ou_external_id_exists", $ou_id ? $ou_id : $external_id, $action);
136
137 return;
138 }
139 }
140 $object = new ilObjOrgUnit();
141 $object->setTitle($title);
142 $object->setDescription($description);
143 $object->setImportId($external_id);
144 $object->create();
145 $object->createReference();
146 $object->putInTree($parent_ref_id);
147 $object->setPermissions($parent_ref_id);
148 $this->stats["created"]++;
149 } else {
150 $this->addError("no_valid_action_given", $ou_id, $action);
151 }
152 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRootOrgRefId()
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 _lookupObjIdByImportId(string $import_id)
Get (latest) object id for an import id.
buildRef($id, string $type)
hasMoreThanOneMatch(string $external_id)
moveObject(int $ref_id, int $parent_ref_id, string $ou_id, string $external_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))

References $DIC, Vendor\Package\$e, $ref_id, ilObject\_hasUntrashedReference(), ilObject\_lookupObjIdByImportId(), ilObject\_lookupType(), ilOrgUnitImporter\addError(), ilOrgUnitImporter\addWarning(), ilOrgUnitImporter\buildRef(), ilObjOrgUnit\getRootOrgRefId(), ilOrgUnitImporter\hasMoreThanOneMatch(), if, and moveObject().

Referenced by simpleImport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: