ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ImportOrgUnitTree.php
Go to the documentation of this file.
1 <?php
20 
22 
27 class ImportOrgUnitTree extends Base
28 {
29  public const ORG_UNIT_TREE = 'OrgUnitTree';
30 
36  protected function run(array $params): bool
37  {
38  global $DIC;
39  $DIC->language()->loadLanguageModule('orgu');
40 
41  $importer = new ilOrgUnitSimpleImport();
42 
43  $xml = simplexml_load_string($params['OrgUnitTree']);
44 
45  if ($xml) {
46  foreach ($xml->children() as $ou_id => $node) {
47  $importer->simpleImportElement(simplexml_load_string($node->asXML()));
48  }
49  } else {
50  throw new \ilSoapPluginException("Could not Read the XML File");
51  }
52 
53  if (count($importer->getErrors()) || count($importer->getWarnings())) {
54  $arr_msg = [];
55  if ($importer->hasWarnings()) {
56  $arr_msg[] = $DIC->language()->txt("import_terminated_with_warnings");
57  foreach ($importer->getWarnings() as $warning) {
58  $arr_msg[$warning["import_id"]] = $DIC->language()->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")";
59  }
60  }
61  if ($importer->hasErrors()) {
62  $arr_msg[] = $DIC->language()->txt("import_terminated_with_errors");
63  foreach ($importer->getErrors() as $error) {
64  $arr_msg[$error["import_id"]] = $DIC->language()->txt($error["lang_var"]) . " (Import ID: " . $error["import_id"] . ")";
65  }
66  }
67 
68  throw new \ilSoapPluginException(implode(" / ", $arr_msg));
69  }
70 
71  return true;
72  }
73 
74  public function getName(): string
75  {
76  return "importOrgUnitsSimpleXML";
77  }
78 
79  protected function getAdditionalInputParams(): array
80  {
81  return array(self::ORG_UNIT_TREE => Base::TYPE_STRING);
82  }
83 
84  public function getOutputParams(): array
85  {
86  return [];
87  }
88 
89  public function getDocumentation(): string
90  {
91  return "Imports ILIAS Organisational Units (SimpleXML)";
92  }
93 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
global $DIC
Definition: feed.php:28
$xml
Definition: metadata.php:351
ilErrorHandling $error
Definition: class.ilias.php:55
getOutputParams()
Get the output parameters in the same format as the input parameters.
getDocumentation()
Get the documentation of this method.