ILIAS  release_8 Revision v8.24
class.ilECSSettingsGUI.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
27{
28 public const MAPPING_EXPORT = 1;
29 public const MAPPING_IMPORT = 2;
30
31 private ilLogger $log;
34 private ilCtrl $ctrl;
37 private ilTree $tree;
42 private \ILIAS\HTTP\Services $http;
44
45 private ?ilPropertyFormGUI $form = null;
47
48 public function __construct()
49 {
50 global $DIC;
51
52 $this->tpl = $DIC->ui()->mainTemplate();
53 $this->lng = $DIC->language();
54 $this->ctrl = $DIC->ctrl();
55 $this->tabs_gui = $DIC->tabs();
56 $this->rbacreview = $DIC->rbac()->review();
57 $this->log = $DIC->logger()->wsrv();
58 $this->tree = $DIC->repositoryTree();
59 $this->access = $DIC->access();
60 $this->toolbar = $DIC->toolbar();
61 $this->objDataCache = $DIC['ilObjDataCache'];
62 $this->user = $DIC->user();
63 $this->http = $DIC->http();
64
65 $this->lng->loadLanguageModule('ecs');
66 $this->initSettings();
67 }
68
72 public function executeCommand(): void
73 {
74 $next_class = $this->ctrl->getNextClass($this);
75 $cmd = $this->ctrl->getCmd();
76
77 $this->setSubTabs();
78 switch ($next_class) {
79 case 'ilecsmappingsettingsgui':
80 $mapset = new ilECSMappingSettingsGUI($this, (int) $_REQUEST['server_id'], (int) $_REQUEST['mid']);
81 $this->ctrl->setReturn($this, 'communities');
82 $this->ctrl->forwardCommand($mapset);
83 break;
84
85 case 'ilecsparticipantsettingsgui':
87 (int) $_REQUEST['server_id'],
88 (int) $_REQUEST['mid']
89 );
90 $this->ctrl->setReturn($this, 'communities');
91 $this->ctrl->forwardCommand($part);
92 break;
93
94 default:
95
96 if ($cmd !== "overview" && $cmd !== "communities" && !$this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
97 $this->ctrl->redirect($this, "overview");
98 }
99
100 if (!$cmd || $cmd === 'view') {
101 $cmd = "overview";
102 }
103 $this->$cmd();
104 break;
105 }
106 }
107
111 public function overview(): void
112 {
113 $this->tabs_gui->setSubTabActive('overview');
114 if ($this->access->checkAccess('write', '', (int) $_REQUEST["ref_id"])) {
115 $this->toolbar->addButton(
116 $this->lng->txt('ecs_add_new_ecs'),
117 $this->ctrl->getLinkTarget($this, 'create')
118 );
119 }
120
122
123 $table = new ilECSServerTableGUI($this, 'overview');
124 $table->initTable();
125 $table->parse($servers);
126 $this->tpl->setContent($table->getHTML());
127 }
128
132 protected function activate(): void
133 {
134 $this->initSettings((int) $_REQUEST['server_id']);
135 $this->settings->setEnabledStatus(true);
136 $this->settings->update();
137 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
138 $this->ctrl->redirect($this, 'overview');
139 }
140
144 protected function deactivate(): void
145 {
146 $this->initSettings((int) $_REQUEST['server_id']);
147 $this->settings->setEnabledStatus(false);
148 $this->settings->update();
149 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
150 $this->ctrl->redirect($this, 'overview');
151 }
152
156 protected function readAll(): bool
157 {
158 try {
159 //TOOD fix somehow broken logic code of this foreach loop
161 (new ilECSEventQueueReader($server))->handleImportReset();
162 (new ilECSEventQueueReader($server))->handleExportReset();
163
164 ilECSTaskScheduler::_getInstanceByServerId($server->getServerId())->startTaskExecution();
165
166 $this->tpl->setOnScreenMessage('info', $this->lng->txt('ecs_remote_imported'));
167 $this->imported();
168 return true;
169 }
170 } catch (ilECSConnectorException $e1) {
171 $this->tpl->setOnScreenMessage('info', 'Cannot connect to ECS server: ' . $e1->getMessage());
172 $this->imported();
173 } catch (ilException $e2) {
174 $this->tpl->setOnScreenMessage('info', 'Update failed: ' . $e2->getMessage());
175 $this->imported();
176 }
177 return false;
178 }
179
183 protected function create(): void
184 {
185 $this->initSettings(0);
186
187 $this->tabs_gui->clearTargets();
188 $this->tabs_gui->clearSubTabs();
189 $this->tabs_gui->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'overview'));
190
191 $this->initSettingsForm('create');
192 $this->tabs_gui->setSubTabActive('ecs_settings');
193
194 $this->tpl->setContent($this->form->getHTML());
195 }
196
200 protected function edit(): void
201 {
202 $this->initSettings((int) $_REQUEST['server_id']);
203 $this->ctrl->saveParameter($this, 'server_id');
204
205 $this->tabs_gui->clearTargets();
206 $this->tabs_gui->clearSubTabs();
207 $this->tabs_gui->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'overview'));
208
209 $this->initSettingsForm();
210 $this->tabs_gui->setSubTabActive('ecs_settings');
211
212 $this->tpl->setContent($this->form->getHTML());
213 }
214
215 protected function cp(): void
216 {
217 $this->initSettings((int) $_REQUEST['server_id']);
218
219 $copy = clone $this->settings;
220 $copy->save();
221
222 $this->ctrl->setParameter($this, 'server_id', $copy->getServerId());
223 $this->tpl->setOnScreenMessage('success', $this->lng->txt('ecs_settings_cloned'), true);
224 $this->ctrl->redirect($this, 'edit');
225 }
226
230 protected function delete(): void
231 {
232 $this->initSettings((int) $_REQUEST['server_id']);
233
234 $this->tabs_gui->clearTargets();
235 $this->tabs_gui->clearSubTabs();
236 $this->tabs_gui->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, 'overview'));
237
238 $confirm = new ilConfirmationGUI();
239 $confirm->setFormAction($this->ctrl->getFormAction($this));
240 $confirm->setConfirm($this->lng->txt('delete'), 'doDelete');
241 $confirm->setCancel($this->lng->txt('cancel'), 'overview');
242 $confirm->setHeaderText($this->lng->txt('ecs_delete_setting'));
243
244 $confirm->addItem('', '', $this->settings->getServer());
245 $confirm->addHiddenItem('server_id', (string) $this->settings->getServerId());
246
247 $this->tpl->setContent($confirm->getHTML());
248 }
249
253 protected function doDelete(): void
254 {
255 $this->initSettings((int) $_REQUEST['server_id']);
256 $this->settings->delete();
257 $this->tpl->setOnScreenMessage('success', $this->lng->txt('ecs_setting_deleted'), true);
258 $this->ctrl->redirect($this, 'overview');
259 }
260
261
265 protected function settings(): void
266 {
267 $this->initSettingsForm();
268 $this->tabs_gui->setSubTabActive('ecs_settings');
269
270 $this->tpl->setContent($this->form->getHTML());
271 }
272
276 protected function initSettingsForm($a_mode = 'update'): void
277 {
278 if (isset($this->form) && is_object($this->form)) {
279 return;
280 }
281
282 $this->form = new ilPropertyFormGUI();
283 $this->form->setFormAction($this->ctrl->getFormAction($this, 'settings'));
284 $this->form->setTitle($this->lng->txt('ecs_connection_settings'));
285
286 $ena = new ilCheckboxInputGUI($this->lng->txt('ecs_active'), 'active');
287 $ena->setChecked($this->settings->isEnabled());
288 $ena->setValue("1");
289 $this->form->addItem($ena);
290
291 $server_title = new ilTextInputGUI($this->lng->txt('ecs_server_title'), 'title');
292 $server_title->setValue($this->settings->getTitle());
293 $server_title->setSize(80);
294 $server_title->setMaxLength(128);
295 $server_title->setRequired(true);
296 $this->form->addItem($server_title);
297
298 $ser = new ilTextInputGUI($this->lng->txt('ecs_server_url'), 'server');
299 $ser->setValue((string) $this->settings->getServer());
300 $ser->setRequired(true);
301 $this->form->addItem($ser);
302
303 $pro = new ilSelectInputGUI($this->lng->txt('ecs_protocol'), 'protocol');
304 // fixed to https
305 #$pro->setOptions(array(ilECSSetting::PROTOCOL_HTTP => $this->lng->txt('http'),
306 # ilECSSetting::PROTOCOL_HTTPS => $this->lng->txt('https')));
307 $pro->setOptions(array(ilECSSetting::PROTOCOL_HTTPS => 'HTTPS'));
308 $pro->setValue($this->settings->getProtocol());
309 $pro->setRequired(true);
310 $this->form->addItem($pro);
311
312 $por = new ilTextInputGUI($this->lng->txt('ecs_port'), 'port');
313 $por->setSize(5);
314 $por->setMaxLength(5);
315 $por->setValue((string) $this->settings->getPort());
316 $por->setRequired(true);
317 $this->form->addItem($por);
318
319 $tcer = new ilRadioGroupInputGUI($this->lng->txt('ecs_auth_type'), 'auth_type');
320 $tcer->setValue((string) $this->settings->getAuthType());
321 $this->form->addItem($tcer);
322
323 // Certificate based authentication
324 $cert_based = new ilRadioOption($this->lng->txt('ecs_auth_type_cert'), (string) ilECSSetting::AUTH_CERTIFICATE);
325 $tcer->addOption($cert_based);
326
327 $cli = new ilTextInputGUI($this->lng->txt('ecs_client_cert'), 'client_cert');
328 $cli->setSize(60);
329 $cli->setValue((string) $this->settings->getClientCertPath());
330 $cli->setRequired(true);
331 $cert_based->addSubItem($cli);
332
333 $key = new ilTextInputGUI($this->lng->txt('ecs_cert_key'), 'key_path');
334 $key->setSize(60);
335 $key->setValue((string) $this->settings->getKeyPath());
336 $key->setRequired(true);
337 $cert_based->addSubItem($key);
338
339 $cerp = new ilTextInputGUI($this->lng->txt('ecs_key_password'), 'key_password');
340 $cerp->setSize(12);
341 $cerp->setValue((string) $this->settings->getKeyPassword());
342 $cerp->setInputType('password');
343 $cerp->setRequired(true);
344 $cert_based->addSubItem($cerp);
345
346 $cer = new ilTextInputGUI($this->lng->txt('ecs_ca_cert'), 'ca_cert');
347 $cer->setSize(60);
348 $cer->setValue((string) $this->settings->getCACertPath());
349 $cer->setRequired(true);
350 $cert_based->addSubItem($cer);
351
352 // Apache auth
353 $apa_based = new ilRadioOption($this->lng->txt('ecs_auth_type_apache'), (string) ilECSSetting::AUTH_APACHE);
354 $tcer->addOption($apa_based);
355
356 $user = new ilTextInputGUI($this->lng->txt('ecs_apache_user'), 'auth_user');
357 $user->setSize(32);
358 $user->setValue($this->settings->getAuthUser());
359 $user->setRequired(true);
360 $apa_based->addSubItem($user);
361
362 $pass = new ilPasswordInputGUI($this->lng->txt('ecs_apache_pass'), 'auth_pass');
363 $pass->setRetype(false);
364 $pass->setSize(32);
365 $pass->setMaxLength(128);
366 $pass->setValue($this->settings->getAuthPass());
367 $pass->setRequired(true);
368 $pass->setSkipSyntaxCheck(true);
369 $apa_based->addSubItem($pass);
370
371
372 $ser = new ilNonEditableValueGUI($this->lng->txt('cert_serial'));
373 $ser->setValue($this->settings->getCertSerialNumber() ?: $this->lng->txt('ecs_no_value'));
374 $cert_based->addSubItem($ser);
375
376 $loc = new ilFormSectionHeaderGUI();
377 $loc->setTitle($this->lng->txt('ecs_local_settings'));
378 $this->form->addItem($loc);
379
380 $imp = new ilCustomInputGUI($this->lng->txt('ecs_import_id'));
381 $imp->setRequired(true);
382
383 $tpl = new ilTemplate('tpl.ecs_import_id_form.html', true, true, 'Services/WebServices/ECS');
384 $tpl->setVariable('SIZE', 5);
385 $tpl->setVariable('MAXLENGTH', 11);
386 $tpl->setVariable('POST_VAR', 'import_id');
387 $tpl->setVariable('PROPERTY_VALUE', $this->settings->getImportId());
388
389 if ($this->settings->getImportId()) {
390 $path = $this->buildPath($this->settings->getImportId());
391 if ($path === '') {
392 $imp->setAlert($this->lng->txt('err_check_input'));
393 } else {
394 $tpl->setVariable('COMPLETE_PATH', $this->buildPath($this->settings->getImportId()));
395 }
396 }
397
398 $imp->setHTML($tpl->get());
399 $imp->setInfo($this->lng->txt('ecs_import_id_info'));
400 $this->form->addItem($imp);
401
402 $loc = new ilFormSectionHeaderGUI();
403 $loc->setTitle($this->lng->txt('ecs_remote_user_settings'));
404 $this->form->addItem($loc);
405
406 $role = new ilSelectInputGUI($this->lng->txt('ecs_role'), 'global_role');
407 $role->setOptions($this->prepareRoleSelect());
408 $role->setValue($this->settings->getGlobalRole());
409 $role->setInfo($this->lng->txt('ecs_global_role_info'));
410 $role->setRequired(true);
411 $this->form->addItem($role);
412
413 $duration = new ilDurationInputGUI($this->lng->txt('ecs_account_duration'), 'duration');
414 $duration->setInfo($this->lng->txt('ecs_account_duration_info'));
415 $duration->setMonths($this->settings->getDuration());
416 $duration->setShowSeconds(false);
417 $duration->setShowMinutes(false);
418 $duration->setShowHours(false);
419 $duration->setShowDays(false);
420 $duration->setShowMonths(true);
421 $duration->setRequired(true);
422 $this->form->addItem($duration);
423
424 // Email recipients
425 $loc = new ilFormSectionHeaderGUI();
426 $loc->setTitle($this->lng->txt('ecs_notifications'));
427 $this->form->addItem($loc);
428
429 $rcp_user = new ilTextInputGUI($this->lng->txt('ecs_user_rcp'), 'user_recipients');
430 $rcp_user->setValue($this->settings->getUserRecipientsAsString());
431 $rcp_user->setInfo($this->lng->txt('ecs_user_rcp_info'));
432 $this->form->addItem($rcp_user);
433
434 $rcp_econ = new ilTextInputGUI($this->lng->txt('ecs_econ_rcp'), 'econtent_recipients');
435 $rcp_econ->setValue($this->settings->getEContentRecipientsAsString());
436 $rcp_econ->setInfo($this->lng->txt('ecs_econ_rcp_info'));
437 $this->form->addItem($rcp_econ);
438
439 $rcp_app = new ilTextInputGUI($this->lng->txt('ecs_approval_rcp'), 'approval_recipients');
440 $rcp_app->setValue($this->settings->getApprovalRecipientsAsString());
441 $rcp_app->setInfo($this->lng->txt('ecs_approval_rcp_info'));
442 $this->form->addItem($rcp_app);
443
444 if ($a_mode === 'update') {
445 $this->form->addCommandButton('update', $this->lng->txt('save'));
446 } else {
447 $this->form->addCommandButton('save', $this->lng->txt('save'));
448 }
449 $this->form->addCommandButton('overview', $this->lng->txt('cancel'));
450 }
451
455 protected function update(): void
456 {
457 $this->initSettings((int) $_REQUEST['server_id']);
458 $this->loadFromPost();
459
460 if (!$error = $this->settings->validate()) {
461 $this->settings->update();
462 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'), true);
463 } else {
464 $this->tpl->setOnScreenMessage('info', $this->lng->txt($error));
465 $this->edit();
466 }
467
468 $this->overview();
469 }
470
474 protected function save(): void
475 {
476 $this->initSettings(0);
477 $this->loadFromPost();
478
479 if (!$error = $this->settings->validate()) {
480 $this->settings->save();
481
482 #$this->updateTitle();
483 $this->tpl->setOnScreenMessage('info', $this->lng->txt('settings_saved'), true);
484 } else {
485 $this->tpl->setOnScreenMessage('info', $this->lng->txt($error));
486 }
487 $this->ctrl->redirect($this, 'overview');
488 }
489
493 protected function updateTitle(): void
494 {
495 try {
496 $reader = ilECSCommunityReader::getInstanceByServerId($this->settings->getServerId());
497
498 foreach ($reader->getCommunities() as $community) {
499 foreach ($community->getParticipants() as $part) {
500 $this->log->dump($community);
501 if ($part->isSelf()) {
502 $this->settings->setTitle($part->getParticipantName());
503 $this->settings->update();
504 return;
505 }
506 }
507 }
508 } catch (ilECSConnectorException $exc) {
509 $this->tpl->setOnScreenMessage('failure', $exc->getMessage());
510 }
511 $this->settings->setTitle('');
512 $this->settings->update();
513 }
514
518 protected function loadFromPost(): void
519 {
520 $this->settings->setEnabledStatus((bool) $_POST['active']);
521 $this->settings->setTitle(ilUtil::stripSlashes($_POST['title']));
522 $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
523 $this->settings->setPort((int) ilUtil::stripSlashes($_POST['port']));
524 $this->settings->setProtocol((int) ilUtil::stripSlashes($_POST['protocol']));
525 $this->settings->setClientCertPath(ilUtil::stripSlashes($_POST['client_cert']));
526 $this->settings->setCACertPath(ilUtil::stripSlashes($_POST['ca_cert']));
527 $this->settings->setKeyPath(ilUtil::stripSlashes($_POST['key_path']));
528 $this->settings->setKeyPassword(ilUtil::stripSlashes($_POST['key_password']));
529 $this->settings->setImportId((int) ilUtil::stripSlashes($_POST['import_id']));
530 $this->settings->setServer(ilUtil::stripSlashes($_POST['server']));
531 $this->settings->setGlobalRole((int) $_POST['global_role']);
532 $this->settings->setDuration((int) $_POST['duration']['MM']);
533 $this->settings->setUserRecipients(explode(',', ilUtil::stripSlashes($_POST['user_recipients'])));
534 $this->settings->setEContentRecipients(explode(',', ilUtil::stripSlashes($_POST['econtent_recipients'])));
535 $this->settings->setApprovalRecipients(explode(',', ilUtil::stripSlashes($_POST['approval_recipients'])));
536
537 $this->settings->setAuthType((int) $_POST['auth_type']);
538 $this->settings->setAuthPass(ilUtil::stripSlashes($_POST['auth_pass']));
539 $this->settings->setAuthUser(ilUtil::stripSlashes($_POST['auth_user']));
540 }
541
545 protected function refreshParticipants(): void
546 {
548 foreach ($servers->getServers(ilECSServerSettings::ALL_SERVER) as $server) {
549
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 'Services/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', 'Services/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, 'Services/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}
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:43
const IL_CAL_UNIX
const IL_CAL_DATETIME
static getInstancesByObjType($a_obj_type, $a_active_only=true)
static _lookupTitle(int $a_record_id)
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 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...
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_formaction)
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...
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 file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Remote course app class.
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
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.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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,...
$server
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...
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$path
Definition: ltiservices.php:32
static http()
Fetches the global http state from ILIAS.
string $key
Consumer key/client ID value.
Definition: System.php:193
form( $class_path, string $cmd)
$type