ILIAS  release_8 Revision v8.24
class.ilOrgUnitSimpleUserImportGUI.php
Go to the documentation of this file.
1<?php
18/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
19
27{
30 protected ilCtrl $ctrl;
32 protected object $parent_object;
33 protected object $parent_gui;
34 protected ilLanguage $lng;
36 protected \ILIAS\DI\LoggingServices $ilLog;
37
38
39 public function __construct(object $parent_gui)
40 {
41 global $DIC;
42 $this->tpl = $DIC->ui()->mainTemplate();
43 $this->ctrl = $DIC->ctrl();
44 $this->parent_gui = $parent_gui;
45 $this->parent_object = $parent_gui->getObject();
46 $this->tabs_gui = $DIC->tabs();
47 $this->toolbar = $DIC->toolbar();
48 $this->lng = $DIC->language();
49 $this->ilLog = $DIC->logger();
50 $this->ilAccess = $DIC->access();
51 $this->lng->loadLanguageModule('user');
52 if (!$this->ilAccess->checkaccess('write', '', $this->parent_gui->getObject()->getRefId())) {
53 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
54 }
55 }
56
57 public function executeCommand(): bool
58 {
59 $cmd = $this->ctrl->getCmd();
60
61 $this->tabs_gui->clearTargets();
62 $this->tabs_gui->setBackTarget(
63 $this->lng->txt("back"),
64 $this->ctrl->getLinkTargetByClass('ilOrgUnitSimpleImportGUI', 'chooseImport')
65 );
66
67 switch ($cmd) {
68 case 'userImportScreen':
69 $this->userImportScreen();
70 break;
71 case 'startImport':
72 $this->startImport();
73 break;
74 }
75
76 return true;
77 }
78
79 public function userImportScreen(): void
80 {
81 $form = $this->initForm();
82 $this->tpl->setContent($form->getHTML());
83 }
84
85 private function initForm(): ilPropertyFormGUI
86 {
87 $form = new ilPropertyFormGUI();
88 $input = new ilFileInputGUI($this->lng->txt('import_xml_file'), 'import_file');
89 $input->setRequired(true);
90 $form->addItem($input);
91 $form->setFormAction($this->ctrl->getFormAction($this));
92 $form->addCommandButton('startImport', $this->lng->txt('import'));
93
94 return $form;
95 }
96
97 public function startImport(): void
98 {
99 $form = $this->initForm();
100 if (!$form->checkInput()) {
101 $this->tpl->setContent($form->getHTML());
102 } else {
103 $file = $form->getInput('import_file');
104 $importer = new ilOrgUnitSimpleUserImport();
105 try {
106 $importer->simpleUserImport($file['tmp_name']);
107 } catch (Exception $e) {
108 $this->ilLog->write($e->getMessage() . ' - ' . $e->getTraceAsString());
109 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('import_failed'), true);
110 $this->ctrl->redirect($this, 'render');
111 }
112 $this->displayImportResults($importer);
113 }
114 }
115
116 public function displayImportResults(ilOrgUnitImporter $importer): void
117 {
118 if (!$importer->hasErrors() and !$importer->hasWarnings()) {
119 $stats = $importer->getStats();
120 $this->tpl->setOnScreenMessage(
121 'success',
122 sprintf($this->lng->txt('user_import_successful'), $stats['created'], $stats['removed']),
123 true
124 );
125 }
126 if ($importer->hasWarnings()) {
127 $msg = $this->lng->txt('import_terminated_with_warnings') . '<br>';
128 foreach ($importer->getWarnings() as $warning) {
129 $msg .= '-' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
130 }
131 $this->tpl->setOnScreenMessage('info', $msg, true);
132 }
133 if ($importer->hasErrors()) {
134 $msg = $this->lng->txt('import_terminated_with_errors') . '<br>';
135 foreach ($importer->getErrors() as $warning) {
136 $msg .= '- ' . $this->lng->txt($warning['lang_var']) . ' (Import ID: ' . $warning['import_id'] . ')<br>';
137 }
138 $this->tpl->setOnScreenMessage('failure', $msg, true);
139 }
140 }
141}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
global $DIC
Definition: feed.php:28
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...