ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ImportOrgUnitTree.php
Go to the documentation of this file.
1 <?php
2 
21 
23 
28 class ImportOrgUnitTree extends Base
29 {
30  public const ORG_UNIT_TREE = 'OrgUnitTree';
31 
37  protected function run(array $params): bool
38  {
39  global $DIC;
40  $DIC->language()->loadLanguageModule('orgu');
41 
42  $importer = new ilOrgUnitSimpleImport();
43 
44  $xml = simplexml_load_string($params['OrgUnitTree']);
45 
46  if ($xml) {
47  foreach ($xml->children() as $ou_id => $node) {
48  $importer->simpleImportElement(simplexml_load_string($node->asXML()));
49  }
50  } else {
51  throw new \ilSoapPluginException("Could not Read the XML File");
52  }
53 
54  if (count($importer->getErrors()) || count($importer->getWarnings())) {
55  $arr_msg = [];
56  if ($importer->hasWarnings()) {
57  $arr_msg[] = $DIC->language()->txt("import_terminated_with_warnings");
58  foreach ($importer->getWarnings() as $warning) {
59  $arr_msg[$warning["import_id"]] = $DIC->language()->txt($warning["lang_var"]) . " (Import ID: " . $warning["import_id"] . ")";
60  }
61  }
62  if ($importer->hasErrors()) {
63  $arr_msg[] = $DIC->language()->txt("import_terminated_with_errors");
64  foreach ($importer->getErrors() as $error) {
65  $arr_msg[$error["import_id"]] = $DIC->language()->txt($error["lang_var"]) . " (Import ID: " . $error["import_id"] . ")";
66  }
67  }
68 
69  throw new \ilSoapPluginException(implode(" / ", $arr_msg));
70  }
71 
72  return true;
73  }
74 
75  public function getName(): string
76  {
77  return "importOrgUnitsSimpleXML";
78  }
79 
80  protected function getAdditionalInputParams(): array
81  {
82  return array(self::ORG_UNIT_TREE => Base::TYPE_STRING);
83  }
84 
85  public function getOutputParams(): array
86  {
87  return [];
88  }
89 
90  public function getDocumentation(): string
91  {
92  return "Imports ILIAS Organisational Units (SimpleXML)";
93  }
94 }
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:31
global $DIC
Definition: shib_login.php:25
ilErrorHandling $error
Definition: class.ilias.php:69
getOutputParams()
Get the output parameters in the same format as the input parameters.
getDocumentation()
Get the documentation of this method.