ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilOrgUnitSimpleUserImportGUI.php
Go to the documentation of this file.
1<?php
2
26{
29 protected ilCtrl $ctrl;
31 protected object $parent_object;
32 protected object $parent_gui;
33 protected ilLanguage $lng;
35 protected \ILIAS\DI\LoggingServices $ilLog;
36
37
38 public function __construct(object $parent_gui)
39 {
40 global $DIC;
41 $this->tpl = $DIC->ui()->mainTemplate();
42 $this->ctrl = $DIC->ctrl();
43 $this->parent_gui = $parent_gui;
44 $this->parent_object = $parent_gui->getObject();
45 $this->tabs_gui = $DIC->tabs();
46 $this->toolbar = $DIC->toolbar();
47 $this->lng = $DIC->language();
48 $this->ilLog = $DIC->logger();
49 $this->ilAccess = $DIC->access();
50 $this->lng->loadLanguageModule('user');
51 if (!$this->ilAccess->checkaccess('write', '', $this->parent_gui->getObject()->getRefId())) {
52 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
53 }
54 }
55
56 public function executeCommand(): bool
57 {
58 $cmd = $this->ctrl->getCmd();
59
60 $this->tabs_gui->clearTargets();
61 $this->tabs_gui->setBackTarget(
62 $this->lng->txt("back"),
63 $this->ctrl->getLinkTargetByClass('ilOrgUnitSimpleImportGUI', 'chooseImport')
64 );
65
66 switch ($cmd) {
67 case 'userImportScreen':
68 $this->userImportScreen();
69 break;
70 case 'startImport':
71 $this->startImport();
72 break;
73 }
74
75 return true;
76 }
77
78 public function userImportScreen(): void
79 {
80 $form = $this->initForm();
81 $this->tpl->setContent($form->getHTML());
82 }
83
84 private function initForm(): ilPropertyFormGUI
85 {
86 $form = new ilPropertyFormGUI();
87 $input = new ilFileInputGUI($this->lng->txt('import_xml_file'), 'import_file');
88 $input->setRequired(true);
89 $form->addItem($input);
90 $form->setFormAction($this->ctrl->getFormAction($this));
91 $form->addCommandButton('startImport', $this->lng->txt('import'));
92
93 return $form;
94 }
95
96 public function startImport(): void
97 {
98 $form = $this->initForm();
99 if (!$form->checkInput()) {
100 $this->tpl->setContent($form->getHTML());
101 } else {
102 $file = $form->getInput('import_file');
103 $importer = new ilOrgUnitSimpleUserImport();
104 try {
105 $importer->simpleUserImport($file['tmp_name']);
106 } catch (Exception $e) {
107 $this->ilLog->write($e->getMessage() . ' - ' . $e->getTraceAsString());
108 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('import_failed'), true);
109 $this->ctrl->redirect($this, 'render');
110 }
111 $this->displayImportResults($importer);
112 }
113 }
114
115 public function displayImportResults(ilOrgUnitImporter $importer): void
116 {
117 if (!$importer->hasErrors() and !$importer->hasWarnings()) {
118 $stats = $importer->getStats();
119 $this->tpl->setOnScreenMessage(
120 'success',
121 sprintf($this->lng->txt('user_import_successful'), $stats['created'], $stats['removed']),
122 true
123 );
124 }
125 if ($importer->hasWarnings()) {
126 $msg = $this->lng->txt('import_terminated_with_warnings') . '<br>';
127 foreach ($importer->getWarnings() as $warning) {
128 $msg .= '-' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
129 }
130 $this->tpl->setOnScreenMessage('info', $msg, true);
131 }
132 if ($importer->hasErrors()) {
133 $msg = $this->lng->txt('import_terminated_with_errors') . '<br>';
134 foreach ($importer->getErrors() as $warning) {
135 $msg .= '- ' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
136 }
137 $this->tpl->setOnScreenMessage('failure', $msg, true);
138 }
139 }
140}
Class ilAccessHandler Checks access for ILIAS objects.
Class ilCtrl provides processing control methods.
This class represents a file property in a property form.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilLog.php:31
write(string $a_msg, $a_log_level=null)
logging
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
displayImportResults(ilOrgUnitImporter $importer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
global $DIC
Definition: shib_login.php:26