ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificateMigrationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
14 private $logger;
15
17 protected $ctrl;
18
20 protected $lng;
21
23 protected $access;
24
26 protected $tpl;
27
29 protected $user;
30
33
36
39
42
56 public function __construct(
57 \ilCtrl $ctrl = null,
58 \ilLanguage $lng = null,
60 \ILIAS\DI\BackgroundTaskServices $backgroundTasks = null,
61 \ilObjUser $user = null,
63 \ilSetting $certificateSettings = null,
66 \ilLog $logger = null
67 ) {
68 global $DIC;
69
70 if (null === $ctrl) {
71 $ctrl = $DIC->ctrl();
72 }
73 if (null === $lng) {
74 $lng = $DIC->language();
75 }
76 if (null === $access) {
77 $access = $DIC->access();
78 }
79 if (null === $backgroundTasks) {
80 $backgroundTasks = $DIC->backgroundTasks();
81 }
82 if (null === $user) {
83 $user = $DIC->user();
84 }
85 if (null === $learningHistoryService) {
86 $learningHistoryService = $DIC->learningHistory();
87 }
88
89 if (null === $certificateSettings) {
90 $certificateSettings = new \ilSetting('certificate');
91 }
92
93 if (null === $migrationValidator) {
94 $migrationValidator = new \ilCertificateMigrationValidator($certificateSettings);
95 }
96 $this->migrationValidator = $migrationValidator;
97
98 if (null === $errorHandler) {
99 $errorHandler = $DIC['ilErr'];
100 }
101 $this->errorHandler = $errorHandler;
102
103 if (null === $logger) {
104 $logger = $DIC->logger()->cert();
105 }
106 $this->logger = $logger;
107
108 $this->ctrl = $ctrl;
109 $lng->loadLanguageModule('cert');
110 $this->lng = $lng;
111 $this->access = $access;
112 $this->user = $user;
113 $this->backgroundTasks = $backgroundTasks;
114 $this->learningHistoryService = $learningHistoryService;
115 }
116
121 public function executeCommand()
122 {
123 $cmd = $this->ctrl->getCmd();
124 $next_class = $this->ctrl->getNextClass($this);
125
126 $cmd = $this->getCommand($cmd);
127 switch ($next_class) {
128 default:
129 $ret = $this->$cmd();
130 break;
131 }
132
133 return $ret;
134 }
135
141 public function getCommand(string $cmd) : string
142 {
143 return $cmd;
144 }
145
150 public function startMigrationAndReturnMessage() : string
151 {
152 $isMigrationAvailable = $this->migrationValidator->isMigrationAvailable(
153 $this->user,
154 new \ilCertificateMigration($this->user->getId())
155 );
156 if (false === $isMigrationAvailable) {
157 $this->logger->error('Tried to execute user certificate migration, but the migration has already been executed');
158 return '';
159 }
160
161 $factory = $this->backgroundTasks->taskFactory();
162 $taskManager = $this->backgroundTasks->taskManager();
163
164 $bucket = new \ILIAS\BackgroundTasks\Implementation\Bucket\BasicBucket();
165 $bucket->setUserId($this->user->getId());
166
167 $task = $factory->createTask(\ilCertificateMigrationJob::class, [(int) $this->user->getId()]);
168
169 $interaction = \ilCertificateMigrationInteraction::class;
170 if (!$this->learningHistoryService->isActive()) {
171 $interaction = \ilCertificateMigrationReducedInteraction::class;
172 }
173 $certificates_interaction = $factory->createTask($interaction, [
174 $task,
175 (int) $this->user->getId()
176 ]);
177
178 $bucket->setTask($certificates_interaction);
179 $bucket->setTitle('Certificate Migration');
180 $bucket->setDescription('Migrates certificates for active user');
181
182 $taskManager->run($bucket);
183
184 return $this->lng->txt('certificate_migration_confirm_started');
185 }
186}
user()
Definition: user.php:4
$factory
Definition: metadata.php:43
An exception for terminatinating execution or to throw for unit testing.
Class ilCertificateMigrationGUI.
getCommand(string $cmd)
Retrieves the ilCtrl command.
__construct(\ilCtrl $ctrl=null, \ilLanguage $lng=null, \ilAccessHandler $access=null, \ILIAS\DI\BackgroundTaskServices $backgroundTasks=null, \ilObjUser $user=null, \ilLearningHistoryService $learningHistoryService=null, \ilSetting $certificateSettings=null, \ilCertificateMigrationValidator $migrationValidator=null, \ilErrorHandling $errorHandler=null, \ilLog $logger=null)
ilCertificateMigrationGUI constructor.
Class ilCertificateMigration.
This class provides processing control methods.
language handling
logging
Definition: class.ilLog.php:19
ILIAS Setting Class.
Interface ilAccessHandler.
Class HTTPServicesTest.
Class BaseForm.
$ret
Definition: parser.php:6
global $DIC
Definition: saml.php:7