ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public const MAPPING_EXPORT = 1;
30 public const MAPPING_IMPORT = 2;
31
32 private ilLogger $log;
35 private ilCtrl $ctrl;
38 private ilTree $tree;
43 private \ILIAS\HTTP\Services $http;
45
46 private ?ilPropertyFormGUI $form = null;
48
49 public function __construct()
50 {
51 global $DIC;
52
53 $this->tpl = $DIC->ui()->mainTemplate();
54 $this->lng = $DIC->language();
55 $this->ctrl = $DIC->ctrl();
56 $this->tabs_gui = $DIC->tabs();
57 $this->rbacreview = $DIC->rbac()->review();
58 $this->log = $DIC->logger()->wsrv();
59 $this->tree = $DIC->repositoryTree();
60 $this->access = $DIC->access();
61 $this->toolbar = $DIC->toolbar();
62 $this->objDataCache = $DIC['ilObjDataCache'];
63 $this->user = $DIC->user();
64 $this->http = $DIC->http();
65
66 $this->lng->loadLanguageModule('ecs');
67 $this->initSettings();
68 }
69
73 public function executeCommand(): void
74 {
75 $next_class = $this->ctrl->getNextClass($this);
76 $cmd = $this->ctrl->getCmd();
77
78 $this->setSubTabs();
79 switch ($next_class) {
80 case 'ilecsmappingsettingsgui':
81 $mapset = new ilECSMappingSettingsGUI($this, (int) $_REQUEST['server_id'], (int) $_REQUEST['mid']);
82 $this->ctrl->setReturn($this, 'communities');
83 $this->ctrl->forwardCommand($mapset);
84 break;
85
86 case 'ilecsparticipantsettingsgui':
88 (int) $_REQUEST['server_id'],
89 (int) $_REQUEST['mid']
90 );
91 $this->ctrl->setReturn($this, 'communities');
92 $this->ctrl->forwardCommand($part);
93 break;
94
95 default:
96
97 if ($cmd !== "overview" && $cmd !== "communities" && !$this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
98 $this->ctrl->redirect($this, "overview");
99 }
100
101 if (!$cmd || $cmd === 'view') {
102 $cmd = "overview";
103 }
104 $this->$cmd();
105 break;
106 }
107 }
108
112 public function overview(): void
113 {
114 $this->tabs_gui->setSubTabActive('overview');
115 if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
116 $this->toolbar->addButton(
117 $this->lng->txt('ecs_add_new_ecs'),
118 $this->ctrl->getLinkTarget($this, 'create')
119 );
120 }
121
123
124 $table = new ilECSServerTableGUI($this, 'overview');
125 $table->initTable();
126 $table->parse($servers);
127 $this->tpl->setContent($table->getHTML());
128 }
129
133 protected function activate(): void
134 {
135 $this->initSettings((int) $_REQUEST['server_id']);
136 $this->settings->setEnabledStatus(true);
137 $this->settings->update();
138 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
139 $this->ctrl->redirect($this, 'overview');
140 }
141
145 protected function deactivate(): void
146 {
147 $this->initSettings((int) $_REQUEST['server_id']);
148 $this->settings->setEnabledStatus(false);
149 $this->settings->update();
150 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
151 $this->ctrl->redirect($this, 'overview');
152 }
153
157 protected function readAll(): bool
158 {
159 try {
160 //TOOD fix somehow broken logic code of this foreach loop
162 (new ilECSEventQueueReader($server))->handleImportReset();
163 (new ilECSEventQueueReader($server))->handleExportReset();
164
165 ilECSTaskScheduler::_getInstanceByServerId($server->getServerId())->startTaskExecution();
166
167 $this->tpl->setOnScreenMessage('info', $this->lng->txt('ecs_remote_imported'));
168 $this->imported();
169 return true;
170 }
171 } catch (ilECSConnectorException $e1) {
172 $this->tpl->setOnScreenMessage('info', 'Cannot connect to ECS server: ' . $e1->getMessage());
173 $this->imported();
174 } catch (ilException $e2) {
175 $this->tpl->setOnScreenMessage('info', 'Update failed: ' . $e2->getMessage());
176 $this->imported();
177 }
178 return false;
179 }
180
184 protected function create(): void
185 {
186 $this->initSettings(0);
187
188 $this->tabs_gui->clearTargets();
189 $this->tabs_gui->clearSubTabs();
190 $this->tabs_gui->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'overview'));
191
192 $this->initSettingsForm('create');
193 $this->tabs_gui->setSubTabActive('ecs_settings');
194
195 $this->tpl->setContent($this->form->getHTML());
196 }
197
201 protected function edit(): void
202 {
203 $this->initSettings((int) $_REQUEST['server_id']);
204 $this->ctrl->saveParameter($this, 'server_id');
205
206 $this->tabs_gui->clearTargets();
207 $this->tabs_gui->clearSubTabs();
208 $this->tabs_gui->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'overview'));
209
210 $this->initSettingsForm();
211 $this->tabs_gui->setSubTabActive('ecs_settings');
212
213 $this->tpl->setContent($this->form->getHTML());
214 }
215
216 protected function cp(): void
217 {
218 $this->initSettings((int) $_REQUEST['server_id']);
219
220 $copy = clone $this->settings;
221 $copy->save();
222
223 $this->ctrl->setParameter($this, 'server_id', $copy->getServerId());
224 $this->tpl->setOnScreenMessage('success', $this->lng->txt('ecs_settings_cloned'), true);
225 $this->ctrl->redirect($this, 'edit');
226 }
227
231 protected function delete(): void
232 {
233 $this->initSettings((int) $_REQUEST['server_id']);
234
235 $this->tabs_gui->clearTargets();
236 $this->tabs_gui->clearSubTabs();
237 $this->tabs_gui->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'overview'));
238
239 $confirm = new ilConfirmationGUI();
240 $confirm->setFormAction($this->ctrl->getFormAction($this));
241 $confirm->setConfirm($this->lng->txt('delete'), 'doDelete');
242 $confirm->setCancel($this->lng->txt('cancel'), 'overview');
243 $confirm->setHeaderText($this->lng->txt('ecs_delete_setting'));
244
245 $confirm->addItem('', '', $this->settings->getServer());
246 $confirm->addHiddenItem('server_id', (string) $this->settings->getServerId());
247
248 $this->tpl->setContent($confirm->getHTML());
249 }
250
254 protected function doDelete(): void
255 {
256 $this->initSettings((int) $_REQUEST['server_id']);
257 $this->settings->delete();
258 $this->tpl->setOnScreenMessage('success', $this->lng->txt('ecs_setting_deleted'), true);
259 $this->ctrl->redirect($this, 'overview');
260 }
261
262
266 protected function settings(): void
267 {
268 $this->initSettingsForm();
269 $this->tabs_gui->setSubTabActive('ecs_settings');
270
271 $this->tpl->setContent($this->form->getHTML());
272 }
273
277 protected function initSettingsForm($a_mode = 'update'): void
278 {
279 if (isset($this->form) && is_object($this->form)) {
280 return;
281 }
282
283 $this->form = new ilPropertyFormGUI();
284 $this->form->setFormAction($this->ctrl->getFormAction($this, 'settings'));
285 $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
286
287 $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'), 'active');
288 $ena->setChecked($this->settings->isEnabled());
289 $ena->setValue("1");
290 $this->form->addItem($ena);
291
292 $server_title = new ilTextInputGUI($this->lng->txt('ecs_server_title'), 'title');
293 $server_title->setValue($this->settings->getTitle());
294 $server_title->setSize(80);
295 $server_title->setMaxLength(128);
296 $server_title->setRequired(true);
297 $this->form->addItem($server_title);
298
299 $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'), 'server');
300 $ser->setValue((string) $this->settings->getServer());
301 $ser->setRequired(true);
302 $this->form->addItem($ser);
303
304 $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'), 'protocol');
305 // fixed to https
306 #$pro->setOptions(array(ilECSSetting::PROTOCOL_HTTP => $this->lng->txt('http'),
307 # ilECSSetting::PROTOCOL_HTTPS => $this->lng->txt('https')));
308 $pro->setOptions(array(ilECSSetting::PROTOCOL_HTTPS => 'HTTPS'));
309 $pro->setValue($this->settings->getProtocol());
310 $pro->setRequired(true);
311 $this->form->addItem($pro);
312
313 $por = new ilTextInputGUI($this->lng->txt('ecs_port'), 'port');
314 $por->setSize(5);
315 $por->setMaxLength(5);
316 $por->setValue((string) $this->settings->getPort());
317 $por->setRequired(true);
318 $this->form->addItem($por);
319
320 $tcer = new ilRadioGroupInputGUI($this->lng->txt('ecs_auth_type'), 'auth_type');
321 $tcer->setValue((string) $this->settings->getAuthType());
322 $this->form->addItem($tcer);
323
324 // Certificate based authentication
325 $cert_based = new ilRadioOption($this->lng->txt('ecs_auth_type_cert'), (string) ilECSSetting::AUTH_CERTIFICATE);
326 $tcer->addOption($cert_based);
327
328 $cli = new ilTextInputGUI($this->lng->txt('ecs_client_cert'), 'client_cert');
329 $cli->setSize(60);
330 $cli->setValue((string) $this->settings->getClientCertPath());
331 $cli->setRequired(true);
332 $cert_based->addSubItem($cli);
333
334 $key = new ilTextInputGUI($this->lng->txt('ecs_cert_key'), 'key_path');
335 $key->setSize(60);
336 $key->setValue((string) $this->settings->getKeyPath());
337 $key->setRequired(true);
338 $cert_based->addSubItem($key);
339
340 $cerp = new ilTextInputGUI($this->lng->txt('ecs_key_password'), 'key_password');
341 $cerp->setSize(12);
342 $cerp->setValue((string) $this->settings->getKeyPassword());
343 $cerp->setInputType('password');
344 $cerp->setRequired(true);
345 $cert_based->addSubItem($cerp);
346
347 $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'), 'ca_cert');
348 $cer->setSize(60);
349 $cer->setValue((string) $this->settings->getCACertPath());
350 $cer->setRequired(true);
351 $cert_based->addSubItem($cer);
352
353 // Apache auth
354 $apa_based = new ilRadioOption($this->lng->txt('ecs_auth_type_apache'), (string) ilECSSetting::AUTH_APACHE);
355 $tcer->addOption($apa_based);
356
357 $user = new ilTextInputGUI($this->lng->txt('ecs_apache_user'), 'auth_user');
358 $user->setSize(32);
359 $user->setValue($this->settings->getAuthUser());
360 $user->setRequired(true);
361 $apa_based->addSubItem($user);
362
363 $pass = new ilPasswordInputGUI($this->lng->txt('ecs_apache_pass'), 'auth_pass');
364 $pass->setRetype(false);
365 $pass->setSize(32);
366 $pass->setMaxLength(128);
367 $pass->setValue($this->settings->getAuthPass());
368 $pass->setRequired(true);
369 $pass->setSkipSyntaxCheck(true);
370 $apa_based->addSubItem($pass);
371
372
373 $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
374 $ser->setValue($this->settings->getCertSerialNumber() ?: $this->lng->txt('ecs_no_value'));
375 $cert_based->addSubItem($ser);
376
377 $loc = new ilFormSectionHeaderGUI();
378 $loc->setTitle($this->lng->txt('ecs_local_settings'));
379 $this->form->addItem($loc);
380
381 $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
382 $imp->setRequired(true);
383
384 $tpl = new ilTemplate('tpl.ecs_import_id_form.html', true, true, 'components/ILIAS/WebServices/ECS');
385 $tpl->setVariable('SIZE', 5);
386 $tpl->setVariable('MAXLENGTH', 11);
387 $tpl->setVariable('POST_VAR', 'import_id');
388 $tpl->setVariable('PROPERTY_VALUE', $this->settings->getImportId());
389
390 if ($this->settings->getImportId()) {
391 $path = $this->buildPath($this->settings->getImportId());
392 if ($path === '') {
393 $imp->setAlert($this->lng->txt('err_check_input'));
394 } else {
395 $tpl->setVariable('COMPLETE_PATH', $this->buildPath($this->settings->getImportId()));
396 }
397 }
398
399 $imp->setHTML($tpl->get());
400 $imp->setInfo($this->lng->txt('ecs_import_id_info'));
401 $this->form->addItem($imp);
402
403 $loc = new ilFormSectionHeaderGUI();
404 $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
405 $this->form->addItem($loc);
406
407 $role = new ilSelectInputGUI($this->lng->txt('ecs_role'), 'global_role');
408 $role->setOptions($this->prepareRoleSelect());
409 $role->setValue($this->settings->getGlobalRole());
410 $role->setInfo($this->lng->txt('ecs_global_role_info'));
411 $role->setRequired(true);
412 $this->form->addItem($role);
413
414 $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'), 'duration');
415 $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
416 $duration->setMonths($this->settings->getDuration());
417 $duration->setShowSeconds(false);
418 $duration->setShowMinutes(false);
419 $duration->setShowHours(false);
420 $duration->setShowDays(false);
421 $duration->setShowMonths(true);
422 $duration->setRequired(true);
423 $this->form->addItem($duration);
424
425 // Email recipients
426 $loc = new ilFormSectionHeaderGUI();
427 $loc->setTitle($this->lng->txt('ecs_notifications'));
428 $this->form->addItem($loc);
429
430 $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'), 'user_recipients');
431 $rcp_user->setValue($this->settings->getUserRecipientsAsString());
432 $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
433 $this->form->addItem($rcp_user);
434
435 $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'), 'econtent_recipients');
436 $rcp_econ->setValue($this->settings->getEContentRecipientsAsString());
437 $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
438 $this->form->addItem($rcp_econ);
439
440 $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'), 'approval_recipients');
441 $rcp_app->setValue($this->settings->getApprovalRecipientsAsString());
442 $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
443 $this->form->addItem($rcp_app);
444
445 if ($a_mode === 'update') {
446 $this->form->addCommandButton('update', $this->lng->txt('save'));
447 } else {
448 $this->form->addCommandButton('save', $this->lng->txt('save'));
449 }
450 $this->form->addCommandButton('overview', $this->lng->txt('cancel'));
451 }
452
456 protected function update(): void
457 {
458 $this->initSettings((int) $_REQUEST['server_id']);
459 $this->loadFromPost();
460
461 if (!$error = $this->settings->validate()) {
462 $this->settings->update();
463 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'), true);
464 } else {
465 $this->tpl->setOnScreenMessage('info', $this->lng->txt($error));
466 $this->edit();
467 }
468
469 $this->overview();
470 }
471
475 protected function save(): void
476 {
477 $this->initSettings(0);
478 $this->loadFromPost();
479
480 if (!$error = $this->settings->validate()) {
481 $this->settings->save();
482
483 #$this->updateTitle();
484 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'), true);
485 } else {
486 $this->tpl->setOnScreenMessage('info', $this->lng->txt($error));
487 }
488 $this->ctrl->redirect($this, 'overview');
489 }
490
494 protected function updateTitle(): void
495 {
496 try {
497 $reader = ilECSCommunityReader::getInstanceByServerId($this->settings->getServerId());
498
499 foreach ($reader->getCommunities() as $community) {
500 foreach ($community->getParticipants() as $part) {
501 $this->log->dump($community);
502 if ($part->isSelf()) {
503 $this->settings->setTitle($part->getParticipantName());
504 $this->settings->update();
505 return;
506 }
507 }
508 }
509 } catch (ilECSConnectorException $exc) {
510 $this->tpl->setOnScreenMessage('failure', $exc->getMessage());
511 }
512 $this->settings->setTitle('');
513 $this->settings->update();
514 }
515
519 protected function loadFromPost(): void
520 {
521 $this->settings->setEnabledStatus((bool) $_POST['active']);
522 $this->settings->setTitle(ilUtil::stripSlashes($_POST['title']));
523 $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
524 $this->settings->setPort((int) ilUtil::stripSlashes($_POST['port']));
525 $this->settings->setProtocol((int) ilUtil::stripSlashes($_POST['protocol']));
526 $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
527 $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
528 $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
529 $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
530 $this->settings->setImportId((int) ilUtil::stripSlashes($_POST['import_id']));
531 $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
532 $this->settings->setGlobalRole((int) $_POST['global_role']);
533 $this->settings->setDuration((int) $_POST['duration']['MM']);
534 $this->settings->setUserRecipients(explode(',', ilUtil::stripSlashes($_POST['user_recipients'])));
535 $this->settings->setEContentRecipients(explode(',', ilUtil::stripSlashes($_POST['econtent_recipients'])));
536 $this->settings->setApprovalRecipients(explode(',', ilUtil::stripSlashes($_POST['approval_recipients'])));
537
538 $this->settings->setAuthType((int) $_POST['auth_type']);
539 $this->settings->setAuthPass(ilUtil::stripSlashes($_POST['auth_pass']));
540 $this->settings->setAuthUser(ilUtil::stripSlashes($_POST['auth_user']));
541 }
542
546 protected function refreshParticipants(): void
547 {
549 foreach ($servers->getServers(ilECSServerSettings::ALL_SERVER) as $server) {
550 // read community
551 try {
552 $creader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
553 foreach (ilECSParticipantSettings::getInstanceByServerId($server->getServerId())->getAvailabeMids() as $mid) {
554 if (!$creader->getParticipantByMID($mid)) {
555 $this->log->notice('Deleting deprecated participant: ' . $server->getServerId() . ' ' . $mid);
556 $part = new ilECSParticipantSetting($server->getServerId(), $mid);
557 $part->delete();
558 }
559 }
560 } catch (ilECSConnectorException $e) {
561 $this->tpl->setOnScreenMessage('failure', $server->getServer() . ': ' . $e->getMessage(), true);
562 }
563 }
564 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
565 $this->ctrl->redirect($this, 'communities');
566 }
567
571 public function communities(): void
572 {
573 $tpl = new \ilTemplate(
574 'tpl.ecs_communities.html',
575 true,
576 true,
577 'components/ILIAS/WebServices/ECS'
578 );
579
580 // add toolbar to refresh communities
581 if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
582 $this->toolbar->addButton(
583 $this->lng->txt('ecs_refresh_participants'),
584 $this->ctrl->getLinkTarget($this, 'refreshParticipants')
585 );
586 }
587
588
589 $this->tabs_gui->setSubTabActive('ecs_communities');
590
591 $tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'updateCommunities'));
592
593 if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
594 $tpl->setCurrentBlock("submit_buttons");
595 $tpl->setVariable('TXT_SAVE', $this->lng->txt('save'));
596 $tpl->setVariable('TXT_CANCEL', $this->lng->txt('cancel'));
597 $tpl->parseCurrentBlock();
598 }
599
601
602 foreach ($settings->getServers(ilECSServerSettings::ALL_SERVER) as $server) {
603 // Try to read communities
604 try {
606 foreach ($reader->getCommunities() as $community) {
607 $tpl->setCurrentBlock('table_community');
608 $table_gui = new ilECSCommunityTableGUI($server, $this, 'communities', $community->getId());
609 $table_gui->setTitle($community->getTitle() . ' (' . $community->getDescription() . ')');
610 $table_gui->parse($community->getParticipants());
611 $tpl->setVariable('TABLE_COMM', $table_gui->getHTML());
613 }
614 } catch (ilECSConnectorException $exc) {
615 // Maybe server is not fully configured
616 continue;
617 }
618
619 // Show section for each server
620 $tpl->setCurrentBlock('server');
621 $tpl->setVariable('TXT_SERVER_NAME', $server->getTitle());
623 }
624
625 $this->tpl->setContent($tpl->get());
626 }
627
632 protected function validateImportTypes(array $import_types): array
633 {
634 $num_cms = 0;
635 foreach ((array) $import_types as $sid => $server) {
636 foreach ((array) $server as $mid => $import_type) {
637 if ((int) $import_type === ilECSParticipantSetting::IMPORT_CMS) {
638 ++$num_cms;
639 }
640 }
641 }
642
643 if ($num_cms <= 1) {
644 return [];
645 }
646 // Change to import type "UNCHANGED"
647 $new_types = [];
648 foreach ((array) $import_types as $sid => $server) {
649 foreach ((array) $server as $mid => $import_type) {
650 if ((int) $import_type === ilECSParticipantSetting::IMPORT_CMS) {
651 $new_types[$sid][$mid] = ilECSParticipantSetting::IMPORT_UNCHANGED;
652 } else {
653 $new_types[$sid][$mid] = $import_type;
654 }
655 }
656 }
657 return $new_types;
658 }
659
663 protected function updateCommunities(): void
664 {
665 // @TODO: Delete deprecated communities
666 $validatedImportTypes = $this->validateImportTypes($_POST['import_type']);
667
669 foreach ($servers->getServers(ilECSServerSettings::ACTIVE_SERVER) as $server) {
670 try {
671 // Read communities
672 $cReader = ilECSCommunityReader::getInstanceByServerId($server->getServerId());
673
674 // Update community cache
675 foreach ($cReader->getCommunities() as $community) {
676 $cCache = ilECSCommunityCache::getInstance($server->getServerId(), $community->getId());
677 $cCache->setCommunityName($community->getTitle());
678 $cCache->setMids($community->getMids());
679 $cCache->setOwnId($community->getOwnId());
680 $cCache->update();
681 }
682 } catch (Exception $e) {
683 $this->log->error('Cannot read ecs communities: ' . $e->getMessage());
684 }
685 }
686 foreach ((array) $_POST['sci_mid'] as $sid => $mids) {
687 $this->log->info("server id is " . print_r($sid, true));
688 foreach ((array) $mids as $mid => $value) {
689 $set = new ilECSParticipantSetting($sid, $mid);
690 #$set->enableExport(array_key_exists($mid, (array) $_POST['export'][$sid]) ? true : false);
691 #$set->enableImport(array_key_exists($mid, (array) $_POST['import'][$sid]) ? true : false);
692 if ($validatedImportTypes) {
693 $set->setImportType((int) $validatedImportTypes[$sid][$mid]);
694 } else {
695 $set->setImportType((int) $_POST['import_type'][$sid][$mid]);
696 }
697
698 // update title/cname
699 try {
700 $part = ilECSCommunityReader::getInstanceByServerId($sid)->getParticipantByMID($mid);
701 if ($part instanceof ilECSParticipant) {
702 $set->setTitle($part->getParticipantName());
703 }
704 $com = ilECSCommunityReader::getInstanceByServerId($sid)->getCommunityByMID($mid);
705 if ($com instanceof ilECSCommunity) {
706 $set->setCommunityName($com->getTitle());
707 }
708 } catch (Exception $e) {
709 $this->log->error('Cannot read ecs communities: ' . $e->getMessage());
710 }
711
712 $set->update();
713 }
714 }
715 if ($validatedImportTypes) {
716 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('ecs_invalid_import_type_cms'), true);
717 } else {
718 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
719 }
720 $this->ctrl->redirect($this, 'communities');
721 // TODO: Do update of remote courses and ...
722 }
723
724
728 protected function setMappingTabs(int $a_active): void
729 {
730 $this->tabs_gui->clearTargets();
731 $this->tabs_gui->clearSubTabs();
732
733 $this->tabs_gui->setBackTarget(
734 $this->lng->txt('ecs_settings'),
735 $this->ctrl->getLinkTarget($this, 'overview')
736 );
737 if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
738 $this->tabs_gui->addTab(
739 'import',
740 $this->lng->txt('ecs_tab_import'),
741 $this->ctrl->getLinkTarget($this, 'importMappings')
742 );
743 }
744 $this->tabs_gui->addTab(
745 'export',
746 $this->lng->txt('ecs_tab_export'),
747 $this->ctrl->getLinkTarget($this, 'exportMappings')
748 );
749
750
751 switch ($a_active) {
753 $this->tabs_gui->activateTab('import');
754 break;
755
757 $this->tabs_gui->activateTab('export');
758 break;
759 }
760 }
761
765 public function importMappings(): void
766 {
767 $this->setMappingTabs(self::MAPPING_IMPORT);
768
770 if (!count($fields)) {
771 $this->tpl->setOnScreenMessage('info', $this->lng->txt('ecs_no_adv_md'));
772 return;
773 }
774
776
777 $sel_srv = (int) $_REQUEST["ecs_mapping_server"];
778
779 // Iterate all servers
780 $options = array(0 => $this->lng->txt("please_choose"));
781 foreach ($settings->getServers(ilECSServerSettings::ALL_SERVER) as $server) {
782 $title = $server->getTitle();
783 if (!$title) {
784 $title = "ECS (" . $server->getServerId() . ")";
785 }
786 $options[$server->getServerId()] = $title;
787 }
788
789 $sel = new ilSelectInputGUI("", "ecs_mapping_server");
790 $sel->setOptions($options);
791 $sel->setValue($sel_srv);
792 $this->toolbar->addInputItem($sel);
793
794 $this->toolbar->setFormAction($this->ctrl->getFormAction($this, "importMappings"));
795 $this->toolbar->addFormButton($this->lng->txt("submit"), "importMappings");
796
797 if ($sel_srv) {
798 $form = $this->initMappingsForm($sel_srv, self::MAPPING_IMPORT);
799 $this->tpl->setContent($form->getHTML());
800 }
801 }
802
806 protected function exportMappings(): void
807 {
808 $this->setMappingTabs(self::MAPPING_EXPORT);
809
811 if (!count($fields)) {
812 $this->tpl->setOnScreenMessage('info', $this->lng->txt('ecs_no_adv_md'));
813 return;
814 }
815
817
818 $sel_srv = (int) $_REQUEST["ecs_mapping_server"];
819
820 // Iterate all servers
821 $options = array(0 => $this->lng->txt("please_choose"));
822 foreach ($settings->getServers(ilECSServerSettings::ALL_SERVER) as $server) {
823 $title = $server->getTitle();
824 if (!$title) {
825 $title = "ECS (" . $server->getServerId() . ")";
826 }
827 $options[$server->getServerId()] = $title;
828 }
829
830 $sel = new ilSelectInputGUI("", "ecs_mapping_server");
831 $sel->setOptions($options);
832 $sel->setValue($sel_srv);
833 $this->toolbar->addInputItem($sel);
834
835 $this->toolbar->setFormAction($this->ctrl->getFormAction($this, "exportMappings"));
836 $this->toolbar->addFormButton($this->lng->txt("submit"), "exportMappings");
837
838 if ($sel_srv) {
839 $form = $this->initMappingsForm($sel_srv, self::MAPPING_EXPORT);
840 $this->tpl->setContent($form->getHTML());
841 }
842 }
843
847 protected function saveImportMappings(): void
848 {
849 foreach ((array) $_POST['mapping'] as $mtype => $mappings) {
850 foreach ((array) $mappings as $ecs_field => $advmd_id) {
851 $map = new ilECSDataMappingSetting(
852 (int) $_REQUEST['ecs_mapping_server'],
853 (int) $mtype,
854 $ecs_field
855 );
856 $map->setAdvMDId((int) $advmd_id);
857 $map->save();
858 }
859 }
860
861 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'), true);
862 $this->ctrl->setParameter($this, "ecs_mapping_server", (int) $_POST['ecs_mapping_server']);
863 $this->ctrl->redirect($this, 'importMappings');
864 }
865
869 protected function saveExportMappings(): void
870 {
871 foreach ((array) $_POST['mapping'] as $mtype => $mappings) {
872 foreach ((array) $mappings as $ecs_field => $advmd_id) {
873 $map = new ilECSDataMappingSetting(
874 (int) $_POST['ecs_mapping_server'],
875 (int) $mtype,
876 $ecs_field
877 );
878 $map->setAdvMDId((int) $advmd_id);
879 $map->save();
880 }
881 }
882
883 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'), true);
884 $this->ctrl->setParameter($this, "ecs_mapping_server", (int) $_POST['ecs_mapping_server']);
885 $this->ctrl->redirect($this, 'exportMappings');
886 }
887
891 protected function initMappingsForm(int $a_server_id, int $mapping_type): ilPropertyFormGUI
892 {
893 $mapping_settings = ilECSDataMappingSettings::getInstanceByServerId($a_server_id);
894
895 $form = new ilPropertyFormGUI();
896
897 if ($mapping_type === self::MAPPING_IMPORT) {
898 $form->setTitle($this->lng->txt('ecs_mapping_tbl'));
899 $form->addCommandButton('saveImportMappings', $this->lng->txt('save'));
900 $form->addCommandButton('importMappings', $this->lng->txt('cancel'));
901 } else {
902 $form->setTitle($this->lng->txt('ecs_mapping_exp_tbl'));
903 $form->addCommandButton('saveExportMappings', $this->lng->txt('save'));
904 $form->addCommandButton('exportMappings', $this->lng->txt('cancel'));
905 }
906
907 $form->setFormAction($this->ctrl->getFormAction($this, 'saveMappings'));
908
909 if ($mapping_type === self::MAPPING_IMPORT) {
910 $assignments = new ilCustomInputGUI($this->lng->txt('ecs_mapping_crs'));
911 $form->addItem($assignments);
912 }
913
915 $options = $this->prepareFieldSelection($fields);
916
917 // get all optional ecourse fields
919 foreach ($optional as $field_name) {
920 if ($mapping_type === self::MAPPING_IMPORT) {
921 $select = new ilSelectInputGUI(
922 $this->lng->txt('ecs_field_' . $field_name),
923 'mapping' . '[' . ilECSDataMappingSetting::MAPPING_IMPORT_CRS . '][' . $field_name . ']'
924 );
925
926 $select->setValue(
927 $mapping_settings->getMappingByECSName(
929 $field_name
930 )
931 );
932 $select->setOptions($options);
933 $assignments->addSubItem($select);
934 } else {
935 $select = new ilSelectInputGUI(
936 $this->lng->txt('ecs_field_' . $field_name),
937 'mapping' . '[' . ilECSDataMappingSetting::MAPPING_EXPORT . '][' . $field_name . ']'
938 );
939 $select->setValue(
940 (string) $mapping_settings->getMappingByECSName(
942 $field_name
943 )
944 );
945 $select->setOptions($options);
946 $form->addItem($select);
947 }
948 }
949
950 $server = new ilHiddenInputGUI('ecs_mapping_server');
951 $server->setValue((string) $a_server_id);
953
954 // Remote courses
955 // no remote course settings for export
956 if ($mapping_type === self::MAPPING_EXPORT) {
957 return $form;
958 }
959
960 $rcrs = new ilCustomInputGUI($this->lng->txt('ecs_mapping_rcrs'));
961 $form->addItem($rcrs);
962
964 $options = $this->prepareFieldSelection($fields);
965
966 // get all optional econtent fields
968 foreach ($optional as $field_name) {
969 $select = new ilSelectInputGUI(
970 $this->lng->txt('ecs_field_' . $field_name),
971 'mapping[' . ilECSDataMappingSetting::MAPPING_IMPORT_RCRS . '][' . $field_name . ']'
972 );
973 $select->setValue(
974 $mapping_settings->getMappingByECSName(
976 $field_name
977 )
978 );
979 $select->setOptions($options);
980 $rcrs->addSubItem($select);
981 }
982 return $form;
983 }
984
988 protected function categoryMapping(): void
989 {
990 $this->tabs_gui->setSubTabActive('ecs_category_mapping');
991 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.category_mapping.html', 'components/ILIAS/WebServices/ECS');
992
993 $this->initRule();
995
996
997 $this->tpl->setVariable('NEW_RULE_TABLE', $this->form->getHTML());
998 if ($html = $this->showRulesTable()) {
999 $this->tpl->setVariable('RULES_TABLE', $html);
1000 }
1001 }
1002
1006 protected function addCategoryMapping(): bool
1007 {
1008 $this->initRule();
1009
1010 $this->initCategoryMappingForm('add');
1011 if ($this->form->checkInput()) {
1012 $this->rule->setContainerId((int) $this->form->getInput('import_id'));
1013 $this->rule->setFieldName($this->form->getInput('field'));
1014 $this->rule->setMappingType((int) $this->form->getInput('type'));
1015
1016 switch ($this->form->getInput('type')) {
1018 $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1019 break;
1020
1022 if ($this->form->getItemByPostVar('dur_begin')) {
1023 $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1024 }
1025 if ($this->form->getItemByPostVar('dur_end')) {
1026 $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1027 }
1028 break;
1029
1031 $this->rule->setByType($this->form->getInput('by_type'));
1032 break;
1033 }
1034
1035 if ($err = $this->rule->validate()) {
1036 $this->tpl->setOnScreenMessage('info', $this->lng->txt($err));
1037 $this->form->setValuesByPost();
1038 $this->categoryMapping();
1039 return false;
1040 }
1041
1042 $this->rule->save();
1043 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'));
1044 unset($this->rule);
1045 $this->categoryMapping();
1046 return true;
1047 }
1048 $this->tpl->setOnScreenMessage('info', $this->lng->txt('err_check_input'));
1049 $this->form->setValuesByPost();
1050 $this->categoryMapping();
1051 return false;
1052 }
1053
1057 protected function editCategoryMapping(): bool
1058 {
1059 if (!$_REQUEST['rule_id']) {
1060 $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'));
1061 $this->categoryMapping();
1062 return false;
1063 }
1064
1065 $this->tabs_gui->setSubTabActive('ecs_category_mapping');
1066 $this->ctrl->saveParameter($this, 'rule_id');
1067 $this->initRule((int) $_REQUEST['rule_id']);
1068
1069 $this->initCategoryMappingForm('edit');
1070 $this->tpl->setContent($this->form->getHTML());
1071 return true;
1072 }
1073
1077 protected function updateCategoryMapping(): bool
1078 {
1079 if (!$_REQUEST['rule_id']) {
1080 $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'));
1081 $this->categoryMapping();
1082 return false;
1083 }
1084 $this->ctrl->saveParameter($this, 'rule_id');
1085 $this->initRule((int) $_REQUEST['rule_id']);
1086 $this->initCategoryMappingForm('edit');
1087 if ($this->form->checkInput()) {
1088 $this->rule->setContainerId((int) $this->form->getInput('import_id'));
1089 $this->rule->setFieldName($this->form->getInput('field'));
1090 $this->rule->setMappingType((int) $this->form->getInput('type'));
1091
1092
1093 switch ($this->form->getInput('type')) {
1095 $this->rule->setMappingValue($this->form->getInput('mapping_value'));
1096 break;
1097
1099 if ($this->form->getItemByPostVar('dur_begin')) {
1100 $this->rule->setDateRangeStart($this->form->getItemByPostVar('dur_begin')->getDate());
1101 }
1102 if ($this->form->getItemByPostVar('dur_end')) {
1103 $this->rule->setDateRangeEnd($this->form->getItemByPostVar('dur_end')->getDate());
1104 }
1105 break;
1106
1108 $this->rule->setByType($this->form->getInput('by_type'));
1109 break;
1110 }
1111
1112 if ($err = $this->rule->validate()) {
1113 $this->tpl->setOnScreenMessage('info', $this->lng->txt($err));
1114 $this->form->setValuesByPost();
1115 $this->editCategoryMapping();
1116 return false;
1117 }
1118
1119 $this->rule->update();
1120 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'), true);
1121 $this->ctrl->redirect($this, 'categoryMapping');
1122 return true;
1123 }
1124 $this->tpl->setOnScreenMessage('info', $this->lng->txt('err_check_input'));
1125 $this->form->setValuesByPost();
1126 $this->editCategoryMapping();
1127 return false;
1128 }
1129
1133 protected function deleteCategoryMappings(): bool
1134 {
1135 if (!is_array($_POST['rules']) || !$_POST['rules']) {
1136 $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'));
1137 $this->categoryMapping();
1138 return false;
1139 }
1140 foreach ($_POST['rules'] as $rule_id) {
1141 $rule = new ilECSCategoryMappingRule((int) $rule_id);
1142 $rule->delete();
1143 }
1144 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'));
1145 $this->categoryMapping();
1146 return true;
1147 }
1148
1152 protected function showRulesTable(): string
1153 {
1154 $rule_table = new ilECSCategoryMappingTableGUI($this, 'categoryMapping');
1155 $rule_table->parse(ilECSCategoryMapping::getActiveRules());
1156 return $rule_table->getHTML();
1157 }
1158
1163 protected function initRule(int $a_rule_id = 0): void
1164 {
1165 if (isset($this->rule) && is_object($this->rule)) {
1166 return;
1167 }
1168
1169 $this->rule = new ilECSCategoryMappingRule($a_rule_id);
1170 }
1171
1175 protected function initCategoryMappingForm($a_mode = 'add'): void
1176 {
1177 if (is_object($this->form)) {
1178 return;
1179 }
1180
1181 $this->form = new ilPropertyFormGUI();
1182
1183 if ($a_mode === 'add') {
1184 $this->form->setTitle($this->lng->txt('ecs_new_category_mapping'));
1185 $this->form->setFormAction($this->ctrl->getFormAction($this, 'categoryMapping'));
1186 $this->form->addCommandButton('addCategoryMapping', $this->lng->txt('save'));
1187 } else {
1188 $this->form->setTitle($this->lng->txt('ecs_edit_category_mapping'));
1189 $this->form->setFormAction($this->ctrl->getFormAction($this, 'editCategoryMapping'));
1190 $this->form->addCommandButton('updateCategoryMapping', $this->lng->txt('save'));
1191 }
1192 $this->form->addCommandButton('categoryMapping', $this->lng->txt('cancel'));
1193
1194 $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'), 'import_id');
1195 $imp->setRequired(true);
1196
1197 $tpl = new ilTemplate('tpl.ecs_import_id_form.html', true, true, 'components/ILIAS/WebServices/ECS');
1198 $tpl->setVariable('SIZE', 5);
1199 $tpl->setVariable('MAXLENGTH', 11);
1200 $tpl->setVariable('POST_VAR', 'import_id');
1201 $tpl->setVariable('PROPERTY_VALUE', $this->rule->getContainerId());
1202
1203 if ($this->rule->getContainerId()) {
1204 $tpl->setVariable('COMPLETE_PATH', $this->buildPath($this->rule->getContainerId()));
1205 }
1206
1207 $imp->setHTML($tpl->get());
1208 $imp->setInfo($this->lng->txt('ecs_import_id_info'));
1209 $this->form->addItem($imp);
1210
1211 $select = new ilSelectInputGUI($this->lng->txt('ecs_attribute_name'), 'field');
1212 $select->setValue($this->rule->getFieldName());
1213 $select->setRequired(true);
1214 $select->setOptions(ilECSCategoryMapping::getPossibleFields());
1215 $this->form->addItem($select);
1216
1217 // Value
1218 $value = new ilRadioGroupInputGUI($this->lng->txt('ecs_cat_mapping_type'), 'type');
1219 $value->setValue((string) $this->rule->getMappingType());
1220 $value->setRequired(true);
1221
1222 $fixed = new ilRadioOption($this->lng->txt('ecs_cat_mapping_fixed'), (string) ilECSCategoryMappingRule::TYPE_FIXED);
1223 $fixed->setInfo($this->lng->txt('ecs_cat_mapping_fixed_info'));
1224
1225 $fixed_val = new ilTextInputGUI($this->lng->txt('ecs_cat_mapping_values'), 'mapping_value');
1226 $fixed_val->setValue($this->rule->getMappingValue());
1227 $fixed_val->setMaxLength(255);
1228 $fixed_val->setSize(40);
1229 $fixed_val->setRequired(true);
1230 $fixed->addSubItem($fixed_val);
1231
1232 $value->addOption($fixed);
1233
1234 $duration = new ilRadioOption($this->lng->txt('ecs_cat_mapping_duration'), (string) ilECSCategoryMappingRule::TYPE_DURATION);
1235 $duration->setInfo($this->lng->txt('ecs_cat_mapping_duration_info'));
1236
1237 $dur_start = new ilDateTimeInputGUI($this->lng->txt('from'), 'dur_begin');
1238 $dur_start->setRequired(true);
1239 $dur_start->setDate($this->rule->getDateRangeStart());
1240 $duration->addSubItem($dur_start);
1241
1242 $dur_end = new ilDateTimeInputGUI($this->lng->txt('to'), 'dur_end');
1243 $dur_end->setRequired(true);
1244 $dur_end->setDate($this->rule->getDateRangeEnd());
1245 $duration->addSubItem($dur_end);
1246
1247 $value->addOption($duration);
1248
1249 $type = new ilRadioOption($this->lng->txt('ecs_cat_mapping_by_type'), (string) ilECSCategoryMappingRule::TYPE_BY_TYPE);
1250 $type->setInfo($this->lng->txt('ecs_cat_mapping_by_type_info'));
1251
1252 $options = ilECSUtils::getPossibleRemoteTypes(true);
1253
1254 $types = new ilSelectInputGUI($this->lng->txt('type'), 'by_type');
1255 $types->setOptions($options);
1256 $types->setValue($this->rule->getByType());
1257 $types->setRequired(true);
1258 $type->addSubitem($types);
1259
1260 $value->addOption($type);
1261
1262 $this->form->addItem($value);
1263 }
1264
1265
1269 protected function imported(): bool
1270 {
1271 $this->tabs_gui->setSubTabActive('ecs_import');
1272
1273 if (ilECSServerSettings::getInstance()->activeServerExists()) {
1274 $this->toolbar->addButton(
1275 $this->lng->txt('ecs_read_remote_links'),
1276 $this->ctrl->getLinkTarget($this, 'readAll')
1277 );
1278
1279 $this->toolbar->addSeparator();
1280 }
1281
1282
1283 $sel_type = $_REQUEST["otype"];
1284 if (!$sel_type) {
1285 $sel_type = "rcrs";
1286 }
1287
1288 $options = ilECSUtils::getPossibleRemoteTypes(true);
1289
1290 $sel = new ilSelectInputGUI("", "otype");
1291 $sel->setOptions($options);
1292 $sel->setValue($sel_type);
1293 $this->toolbar->addInputItem($sel);
1294
1295 $this->toolbar->setFormAction($this->ctrl->getFormAction($this, "imported"));
1296 $this->toolbar->addFormButton($this->lng->txt("submit"), "imported");
1297
1298 $robjs = ilUtil::_getObjectsByOperations($sel_type, 'visible', $this->user->getId(), -1);
1299 if (count($robjs)) {
1300 $this->toolbar->addSeparator();
1301
1302 $this->toolbar->addButton(
1303 $this->lng->txt('csv_export'),
1304 $this->ctrl->getLinkTarget($this, 'exportImported')
1305 );
1306 }
1307 $table_gui = new ilECSImportedContentTableGUI($this, 'imported');
1308 $table_gui->setTitle($this->lng->txt('ecs_imported_content'));
1309 $table_gui->parse($robjs);
1310 $this->tpl->setContent($table_gui->getHTML());
1311
1312 return true;
1313 }
1314
1318 protected function exportImported(): void
1319 {
1320 // :TODO: mind resource type and move to ilRemoteObjectBase...
1321
1322 $rcourses = ilUtil::_getObjectsByOperations('rcrs', 'visible', $this->user->getId(), -1);
1323
1324 // Read participants
1325 try {
1326 $reader = ilECSCommunityReader::getInstanceByServerId($this->settings->getServerId());
1327 } catch (ilECSConnectorException $e) {
1328 $reader = null;
1329 }
1330
1331 // read obj_ids
1332 $this->objDataCache->preloadReferenceCache($rcourses);
1333 $obj_ids = array();
1334 foreach ($rcourses as $rcrs_ref_id) {
1335 $obj_id = $this->objDataCache->lookupObjId((int) $rcrs_ref_id);
1336 $obj_ids[$obj_id] = $obj_id;
1337 }
1338
1339 $writer = new ilCSVWriter();
1340
1341 $writer->addColumn($this->lng->txt('title'));
1342 $writer->addColumn($this->lng->txt('description'));
1343 $writer->addColumn($this->lng->txt('ecs_imported_from'));
1344 $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1345 $writer->addColumn($this->lng->txt('ecs_field_term'));
1346 $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1347 $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1348 $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1349 $writer->addColumn($this->lng->txt('ecs_field_credits'));
1350 $writer->addColumn($this->lng->txt('ecs_field_room'));
1351 $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1352 $writer->addColumn($this->lng->txt('ecs_field_begin'));
1353 $writer->addColumn($this->lng->txt('ecs_field_end'));
1354 $writer->addColumn($this->lng->txt('last_update'));
1355
1356 // TODO fix getting proper datamappingsettings for each server
1358
1359 foreach ($obj_ids as $obj_id) {
1360 $rcourse = new ilObjRemoteCourse($obj_id, false);
1361 $values = ilECSUtils::getAdvancedMDValuesForObjId($obj_id);
1362
1363 $writer->addRow();
1364 $writer->addColumn(ilObject::_lookupTitle($obj_id));
1365 $writer->addColumn(ilObject::_lookupDescription($obj_id));
1366
1367 $mid = $rcourse->getMID();
1368 if ($reader && ($participant = $reader->getParticipantByMID($mid))) {
1369 $writer->addColumn($participant->getParticipantName());
1370 }
1371 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'courseID');
1372 $writer->addColumn($values[$field] ?? '');
1373
1374 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'term');
1375 $writer->addColumn($values[$field] ?? '');
1376
1377 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'lecturer');
1378 $writer->addColumn($values[$field] ?? '');
1379
1380 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'courseType');
1381 $writer->addColumn($values[$field] ?? '');
1382
1383 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'semester_hours');
1384 $writer->addColumn($values[$field] ?? '');
1385
1386 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'credits');
1387 $writer->addColumn($values[$field] ?? '');
1388
1389 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'room');
1390 $writer->addColumn($values[$field] ?? '');
1391
1392 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'cycle');
1393 $writer->addColumn($values[$field] ?? '');
1394
1395 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'begin');
1396 $dt = '';
1397 if (isset($values[$field])) {
1398 $dt = new ilDateTime($values[$field], IL_CAL_UNIX);
1399 $dt = $dt->get(IL_CAL_DATETIME);
1400 }
1401 $writer->addColumn($dt);
1402
1403 $field = $settings->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'end');
1404 $dt = '';
1405 if (isset($values[$field])) {
1406 $dt = new ilDateTime($values[$field], IL_CAL_UNIX);
1407 $dt = $dt->get(IL_CAL_DATETIME);
1408 }
1409 $writer->addColumn($dt);
1410
1411 $writer->addColumn($this->objDataCache->lookupLastUpdate((int) $obj_id));
1412 }
1413
1414 $stream = \ILIAS\Filesystem\Stream\Streams::ofString($writer->getCSVString());
1415 $this->http->saveResponse($this->http
1416 ->response()
1417 ->withAddedHeader('Content-Type', 'text/csv')
1418 ->withAddedHeader('Content-Disposition', 'attachment; filename="' . date("Y_m_d") . '_ecs_import.csv' . '"')
1419 ->withBody($stream));
1420 $this->http->sendResponse();
1421 $this->http->close();
1422 }
1423
1427 protected function released(): void
1428 {
1429 $this->tabs_gui->setSubTabActive('ecs_released');
1430
1431 if ($this->settings->isEnabled()) {
1432 $this->toolbar->addButton(
1433 $this->lng->txt('ecs_read_remote_links'),
1434 $this->ctrl->getLinkTarget($this, 'readAll')
1435 );
1436
1437 $this->toolbar->addSeparator();
1438 }
1439
1440 $sel_type = $_REQUEST["otype"];
1441 if (!$sel_type) {
1442 $sel_type = "rcrs";
1443 }
1444
1445 $options = ilECSUtils::getPossibleReleaseTypes(true);
1446
1447 $sel = new ilSelectInputGUI("", "otype");
1448 $sel->setOptions($options);
1449 $sel->setValue($sel_type);
1450 $this->toolbar->addInputItem($sel);
1451
1452 $this->toolbar->setFormAction($this->ctrl->getFormAction($this, "released"));
1453 $this->toolbar->addFormButton($this->lng->txt("submit"), "released");
1454
1455 $exported = ilECSExportManager::getInstance()->getExportedIdsByType($sel_type);
1456 if (count($exported)) {
1457 $this->toolbar->addSeparator();
1458
1459 $this->toolbar->addButton(
1460 $this->lng->txt('csv_export'),
1461 $this->ctrl->getLinkTarget($this, 'exportReleased')
1462 );
1463 }
1464
1465 $table_gui = new ilECSExportedContentTableGUI($this, 'released');
1466 $table_gui->setTitle($this->lng->txt('ecs_released_content'));
1467 $table_gui->parse($exported);
1468 $this->tpl->setContent($table_gui->getHTML());
1469 }
1470
1474 protected function exportReleased(): void
1475 {
1476 $exported = ilECSExportManager::getInstance()->getExportedIds();
1477 $this->objDataCache->preloadObjectCache($exported);
1478
1479 $writer = new ilCSVWriter();
1480
1481 $writer->addColumn($this->lng->txt('title'));
1482 $writer->addColumn($this->lng->txt('description'));
1483 $writer->addColumn($this->lng->txt('ecs_field_courseID'));
1484 $writer->addColumn($this->lng->txt('ecs_field_term'));
1485 $writer->addColumn($this->lng->txt('ecs_field_lecturer'));
1486 $writer->addColumn($this->lng->txt('ecs_field_courseType'));
1487 $writer->addColumn($this->lng->txt('ecs_field_semester_hours'));
1488 $writer->addColumn($this->lng->txt('ecs_field_credits'));
1489 $writer->addColumn($this->lng->txt('ecs_field_room'));
1490 $writer->addColumn($this->lng->txt('ecs_field_cycle'));
1491 $writer->addColumn($this->lng->txt('ecs_field_begin'));
1492 $writer->addColumn($this->lng->txt('ecs_field_end'));
1493 $writer->addColumn($this->lng->txt('last_update'));
1494
1495 $settings = ilECSDataMappingSettings::getInstanceByServerId($this->settings->getServerId());
1496
1497 foreach ($exported as $obj_id) {
1498 $values = ilECSUtils::getAdvancedMDValuesForObjId($obj_id);
1499
1500 $writer->addRow();
1501 $writer->addColumn(ilObject::_lookupTitle($obj_id));
1502 $writer->addColumn(ilObject::_lookupDescription($obj_id));
1503
1504 $field = $settings->getMappingByECSName(0, 'courseID');
1505 $writer->addColumn($values[$field] ?? '');
1506
1507 $field = $settings->getMappingByECSName(0, 'term');
1508 $writer->addColumn($values[$field] ?? '');
1509
1510 $field = $settings->getMappingByECSName(0, 'lecturer');
1511 $writer->addColumn($values[$field] ?? '');
1512
1513 $field = $settings->getMappingByECSName(0, 'courseType');
1514 $writer->addColumn($values[$field] ?? '');
1515
1516 $field = $settings->getMappingByECSName(0, 'semester_hours');
1517 $writer->addColumn($values[$field] ?? '');
1518
1519 $field = $settings->getMappingByECSName(0, 'credits');
1520 $writer->addColumn($values[$field] ?? '');
1521
1522 $field = $settings->getMappingByECSName(0, 'room');
1523 $writer->addColumn($values[$field] ?? '');
1524
1525 $field = $settings->getMappingByECSName(0, 'cycle');
1526 $writer->addColumn($values[$field] ?? '');
1527
1528 $field = $settings->getMappingByECSName(0, 'begin');
1529 $dt = '';
1530 if (isset($values[$field])) {
1531 $dt = new ilDateTime($values[$field], IL_CAL_UNIX);
1532 $dt = $dt->get(IL_CAL_DATETIME);
1533 }
1534 $writer->addColumn($dt);
1535
1536 $field = $settings->getMappingByECSName(0, 'end');
1537 $dt = '';
1538 if (isset($values[$field])) {
1539 $dt = new ilDateTime($values[$field], IL_CAL_UNIX);
1540 $dt = $dt->get(IL_CAL_DATETIME);
1541 }
1542 $writer->addColumn($dt);
1543
1544 $writer->addColumn($this->objDataCache->lookupLastUpdate((int) $obj_id));
1545 }
1546
1547 $stream = \ILIAS\Filesystem\Stream\Streams::ofString($writer->getCSVString());
1548 $this->http->saveResponse($this->http
1549 ->response()
1550 ->withAddedHeader('Content-Type', 'text/csv')
1551 ->withAddedHeader('Content-Disposition', 'attachment; filename="' . date("Y_m_d") . '_ecs_export.csv' . '"')
1552 ->withBody($stream));
1553 $this->http->sendResponse();
1554 $this->http->close();
1555 }
1556
1557
1562 protected function prepareFieldSelection($fields): array
1563 {
1564 $options[0] = $this->lng->txt('ecs_ignore_field');
1565 foreach ($fields as $field) {
1566 $title = ilAdvancedMDRecord::_lookupTitle($field->getRecordId());
1567 $options[$field->getFieldId()] = $title . ': ' . $field->getTitle();
1568 }
1569 return $options;
1570 }
1571
1572
1573
1577 protected function initSettings(int $a_server_id = 1): void
1578 {
1579 $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
1580 }
1581
1585 protected function setSubTabs(): void
1586 {
1587 $this->tabs_gui->clearSubTabs();
1588
1589 $this->tabs_gui->addSubTabTarget(
1590 "overview",
1591 $this->ctrl->getLinkTarget($this, 'overview'),
1592 "overview",
1593 get_class($this)
1594 );
1595
1596 // Disable all other tabs, if server hasn't been configured.
1597 if (ilECSServerSettings::getInstance()->serverExists()) {
1598 $this->tabs_gui->addSubTabTarget(
1599 "ecs_communities",
1600 $this->ctrl->getLinkTarget($this, 'communities'),
1601 "communities",
1602 get_class($this)
1603 );
1604
1605 if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
1606 $this->tabs_gui->addSubTabTarget(
1607 'ecs_mappings',
1608 $this->ctrl->getLinkTarget($this, 'importMappings'),
1609 'importMappings',
1610 get_class($this)
1611 );
1612
1613 $this->tabs_gui->addSubTabTarget(
1614 'ecs_category_mapping',
1615 $this->ctrl->getLinkTarget($this, 'categoryMapping')
1616 );
1617
1618 $this->tabs_gui->addSubTabTarget(
1619 'ecs_import',
1620 $this->ctrl->getLinkTarget($this, 'imported')
1621 );
1622
1623 $this->tabs_gui->addSubTabTarget(
1624 'ecs_released',
1625 $this->ctrl->getLinkTarget($this, 'released')
1626 );
1627 }
1628 }
1629 }
1630
1634 private function prepareRoleSelect(): array
1635 {
1636 $global_roles = ilUtil::_sortIds(
1637 $this->rbacreview->getGlobalRoles(),
1638 'object_data',
1639 'title',
1640 'obj_id'
1641 );
1642
1643 $select[0] = $this->lng->txt('links_select_one');
1644 foreach ($global_roles as $role_id) {
1645 $select[$role_id] = ilObject::_lookupTitle((int) $role_id);
1646 }
1647 return $select;
1648 }
1649
1650 private function buildPath(int $a_ref_id): string
1651 {
1652 if (!$this->tree->isInTree($a_ref_id) || $this->tree->isDeleted($a_ref_id)) {
1653 return '';
1654 }
1655 $loc = new ilLocatorGUI();
1656 $loc->setTextOnly(false);
1657 $loc->addContextItems($a_ref_id);
1658
1659 return $loc->getHTML();
1660 }
1661}
$duration
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
const IL_CAL_UNIX
const IL_CAL_DATETIME
static getInstancesByObjType($a_obj_type, $a_active_only=true)
static _lookupTitle(int $a_record_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
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 custom property in a property form.
This class represents a date/time property in a property form.
@classDescription Date and time handling
This class represents a duration (typical hh:mm:ss) property in a property form.
Defines a rule for the assignment of ECS remote courses to categories.
static getActiveRules()
get active rules
static getInstance(int $a_server_id, int $a_community_id)
Get instance.
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
static getInstanceByServerId(int $a_server_id)
Get singleton instance.
Reads ECS events and stores them in the database.
static getInstance()
Get the singelton instance of this ilECSExportManager.
Class for ECS node and directory mapping settings.
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
static getInstance()
Get singleton instance.
save()
save settings
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
initRule(int $a_rule_id=0)
Init rule.
updateCategoryMapping()
update category mapping
validateImportTypes(array $import_types)
Validate import types.
ilObjectDataCache $objDataCache
edit()
Edit server setting.
executeCommand()
Execute command.
initCategoryMappingForm($a_mode='add')
Init category mapping form.
editCategoryMapping()
Edit category mapping.
refreshParticipants()
Refresh participants.
create()
Create new settings.
overview()
List available servers.
released()
Show released materials.
saveExportMappings()
Save mappings.
updateTitle()
Update configuration title.
prepareFieldSelection($fields)
get options for field selection
activate()
activate server
communities()
show communities
exportMappings()
Show mapping settings (EContent-Data <-> (Remote)Course.
loadFromPost()
Load from post.
ilECSCategoryMappingRule $rule
readAll()
Read all importable econtent.
setMappingTabs(int $a_active)
Handle tabs for ECS data mapping.
prepareRoleSelect()
get global role array
updateCommunities()
update whitelist
ILIAS HTTP Services $http
ilPropertyFormGUI $form
initMappingsForm(int $a_server_id, int $mapping_type)
init mapping form
showRulesTable()
Show rules table.
initSettings(int $a_server_id=1)
Init settings.
ilGlobalTemplateInterface $tpl
exportImported()
csv export of imported remote courses
initSettingsForm($a_mode='update')
init settings form
addCategoryMapping()
save category mapping
deactivate()
activate server
imported()
Show imported materials.
importMappings()
Show mapping settings (EContent-Data <-> (Remote)Course.
saveImportMappings()
Save mappings.
exportReleased()
export released
deleteCategoryMappings()
Delete selected category mappings.
categoryMapping()
Category mappings.
static _getInstanceByServerId($a_server_id)
get singleton instance Private access use ilECSTaskScheduler::start() or ilECSTaskScheduler::startTas...
static getAdvancedMDValuesForObjId(int $a_obj_id)
Get advanced metadata values for object id.
static _getOptionalECourseFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions
static _getOptionalEContentFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions
static getPossibleReleaseTypes(bool $a_with_captions=false)
Get all possible release object types.
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
Base class for ILIAS Exception handling.
setFormAction(string $a_formaction)
This class represents a section header in a property form.
This class represents a hidden form 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...
Component logger with individual log levels by component id.
This class represents a non editable value in a property form.
Remote course app class.
User class.
class ilObjectDataCache
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
This class represents a password property in a property form.
This class represents a property form user interface.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
This class represents a property in a property form.
This class represents an option in a radio group.
class ilRbacReview Contains Review functions of core Rbac.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static _sortIds(array $a_ids, string $a_table, string $a_field, string $a_id_name)
Function that sorts ids by a given table field using WHERE IN E.g: __sort(array(6,...
static _getObjectsByOperations( $a_obj_type, string $a_operation, int $a_usr_id=0, int $limit=0)
Get all objects of a specific type and check access This function is not recursive,...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$_POST['cmd']
Definition: lti.php:27
$path
Definition: ltiservices.php:30
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26
$server
Definition: shib_login.php:28