ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjBadgeAdministrationGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
14{
18 protected $rbacsystem;
19
23 protected $access;
24
28 protected $toolbar;
29
33 protected $tabs;
34
35 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
36 {
37 global $DIC;
38
39 $this->rbacsystem = $DIC->rbac()->system();
40 $this->ctrl = $DIC->ctrl();
41 $this->access = $DIC->access();
42 $this->lng = $DIC->language();
43 $this->toolbar = $DIC->toolbar();
44 $this->tpl = $DIC["tpl"];
45 $this->tabs = $DIC->tabs();
46 $this->type = "bdga";
47 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
48
49 $this->lng->loadLanguageModule("badge");
50 }
51
52 public function executeCommand()
53 {
54 $next_class = $this->ctrl->getNextClass($this);
55 $cmd = $this->ctrl->getCmd();
56
57 $this->prepareOutput();
58
59 switch ($next_class) {
60 case 'ilpermissiongui':
61 $this->tabs_gui->setTabActive('perm_settings');
62 $perm_gui = new ilPermissionGUI($this);
63 $this->ctrl->forwardCommand($perm_gui);
64 break;
65
66 case 'ilbadgemanagementgui':
67 $this->assertActive();
68 $this->tabs_gui->setTabActive('activity');
69 $gui = new ilBadgeManagementGUI($this->ref_id, $this->obj_id, $this->type);
70 $this->ctrl->forwardCommand($gui);
71 break;
72
73 default:
74 if (!$cmd || $cmd == 'view') {
75 $cmd = "editSettings";
76 }
77
78 $this->$cmd();
79 break;
80 }
81 return true;
82 }
83
84 public function getAdminTabs()
85 {
87
88 if ($rbacsystem->checkAccess("visible,read", $this->object->getRefId())) {
89 $this->tabs_gui->addTab(
90 "settings",
91 $this->lng->txt("settings"),
92 $this->ctrl->getLinkTarget($this, "editSettings")
93 );
94
95 if (ilBadgeHandler::getInstance()->isActive()) {
96 $this->tabs_gui->addTab(
97 "types",
98 $this->lng->txt("badge_types"),
99 $this->ctrl->getLinkTarget($this, "listTypes")
100 );
101
102 $this->tabs_gui->addTab(
103 "imgtmpl",
104 $this->lng->txt("badge_image_templates"),
105 $this->ctrl->getLinkTarget($this, "listImageTemplates")
106 );
107
108 $this->tabs_gui->addTab(
109 "activity",
110 $this->lng->txt("badge_activity_badges"),
111 $this->ctrl->getLinkTargetByClass("ilbadgemanagementgui", "")
112 );
113
114 $this->tabs_gui->addTab(
115 "obj_badges",
116 $this->lng->txt("badge_object_badges"),
117 $this->ctrl->getLinkTarget($this, "listObjectBadges")
118 );
119 }
120 }
121
122 if ($rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
123 $this->tabs_gui->addTab(
124 "perm_settings",
125 $this->lng->txt("perm_settings"),
126 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
127 );
128 }
129 }
130
131 protected function assertActive()
132 {
133 if (!ilBadgeHandler::getInstance()->isActive()) {
134 $this->ctrl->redirect($this, "editSettings");
135 }
136 }
137
138
139 //
140 // settings
141 //
142
143 protected function editSettings($a_form = null)
144 {
145 $this->tabs_gui->setTabActive("settings");
146
147 if (!$a_form) {
148 $a_form = $this->initFormSettings();
149 }
150
151 $this->tpl->setContent($a_form->getHTML());
152 }
153
154 protected function saveSettings()
155 {
156 $ilCtrl = $this->ctrl;
157
158 $this->checkPermission("write");
159
160 $form = $this->initFormSettings();
161 if ($form->checkInput()) {
162 $obi = (bool) $form->getInput("act")
163 ? (bool) $form->getInput("obi")
164 : null;
165
166 $handler = ilBadgeHandler::getInstance();
167 $handler->setActive((bool) $form->getInput("act"));
168 $handler->setObiActive($obi);
169 $handler->setObiOrganisation(trim($form->getInput("obi_org")));
170 $handler->setObiContact(trim($form->getInput("obi_cont")));
171 $handler->setObiSalt(trim($form->getInput("obi_salt")));
172
173 $handler->rebuildIssuerStaticUrl();
174
175 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
176 $ilCtrl->redirect($this, "editSettings");
177 }
178
179 $form->setValuesByPost();
180 $this->editSettings($form);
181 }
182
183 protected function initFormSettings()
184 {
185 $ilAccess = $this->access;
186
187 $form = new ilPropertyFormGUI();
188 $form->setFormAction($this->ctrl->getFormAction($this));
189 $form->setTitle($this->lng->txt("badge_settings"));
190
191 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
192 $form->addCommandButton("saveSettings", $this->lng->txt("save"));
193 $form->addCommandButton("editSettings", $this->lng->txt("cancel"));
194 }
195
196 $act = new ilCheckboxInputGUI($this->lng->txt("badge_service_activate"), "act");
197 $act->setInfo($this->lng->txt("badge_service_activate_info"));
198 $form->addItem($act);
199
200 /* see bug #0020124
201 $obi = new ilCheckboxInputGUI($this->lng->txt("badge_obi_activate"), "obi");
202 $obi->setInfo($this->lng->txt("badge_obi_activate_info"));
203 $form->addItem($obi);
204
205 $obi_org = new ilTextInputGUI($this->lng->txt("badge_obi_organisation"), "obi_org");
206 $obi_org->setRequired(true);
207 $obi_org->setInfo($this->lng->txt("badge_obi_organisation_info"));
208 $obi->addSubItem($obi_org);
209
210 $obi_contact = new ilEmailInputGUI($this->lng->txt("badge_obi_contact"), "obi_cont");
211 $obi_contact->setRequired(true);
212 $obi_contact->setInfo($this->lng->txt("badge_obi_contact_info"));
213 $obi->addSubItem($obi_contact);
214
215 $obi_salt = new ilTextInputGUI($this->lng->txt("badge_obi_salt"), "obi_salt");
216 $obi_salt->setRequired(true);
217 $obi_salt->setInfo($this->lng->txt("badge_obi_salt_info"));
218 $obi->addSubItem($obi_salt);
219 */
220
221 $handler = ilBadgeHandler::getInstance();
222 $act->setChecked($handler->isActive());
223
224 /* see bug 0020124
225 $obi->setChecked($handler->isObiActive());
226 $obi_org->setValue($handler->getObiOrganistation());
227 $obi_contact->setValue($handler->getObiContact());
228 $obi_salt->setValue($handler->getObiSalt());
229 */
230
231 return $form;
232 }
233
234
235 //
236 // types
237 //
238
239 protected function listTypes()
240 {
241 $ilAccess = $this->access;
242
243 $this->assertActive();
244 $this->tabs_gui->setTabActive("types");
245
246 $tbl = new ilBadgeTypesTableGUI(
247 $this,
248 "listTypes",
249 $ilAccess->checkAccess("write", "", $this->object->getRefId())
250 );
251 $this->tpl->setContent($tbl->getHTML());
252 }
253
254 protected function activateTypes()
255 {
257
258 $this->assertActive();
259
260 $ids = $_POST["id"];
261 if ($this->checkPermissionBool("write") && is_array($ids) && count($ids) > 0) {
262 $handler = ilBadgeHandler::getInstance();
263 $inactive = array();
264 foreach ($handler->getInactiveTypes() as $type) {
265 if (!in_array($type, $ids)) {
266 $inactive[] = $type;
267 }
268 }
269 $handler->setInactiveTypes($inactive);
270
271 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
272 }
273 $this->ctrl->redirect($this, "listTypes");
274 }
275
276 protected function deactivateTypes()
277 {
279
280 $this->assertActive();
281
282 $ids = $_POST["id"];
283 if ($this->checkPermissionBool("write") && is_array($ids) && count($ids) > 0) {
284 $handler = ilBadgeHandler::getInstance();
285 $inactive = array_merge($handler->getInactiveTypes(), $ids);
286 $handler->setInactiveTypes($inactive);
287
288 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
289 }
290 $this->ctrl->redirect($this, "listTypes");
291 }
292
293
294 //
295 // images templates
296 //
297
298 protected function listImageTemplates()
299 {
300 $ilAccess = $this->access;
302 $ilToolbar = $this->toolbar;
303 $ilCtrl = $this->ctrl;
304
305 $this->assertActive();
306 $this->tabs_gui->setTabActive("imgtmpl");
307
308 if ($this->checkPermissionBool("write")) {
309 $ilToolbar->addButton(
310 $lng->txt("badge_add_template"),
311 $ilCtrl->getLinkTarget($this, "addImageTemplate")
312 );
313 }
314
316 $this,
317 "listImageTemplates",
318 $ilAccess->checkAccess("write", "", $this->object->getRefId())
319 );
320 $this->tpl->setContent($tbl->getHTML());
321 }
322
323 protected function addImageTemplate(ilPropertyFormGUI $a_form = null)
324 {
326
327 $this->checkPermission("write");
328
329 $this->assertActive();
330 $this->tabs_gui->setTabActive("imgtmpl");
331
332 if (!$a_form) {
333 $a_form = $this->initImageTemplateForm("create");
334 }
335
336 $tpl->setContent($a_form->getHTML());
337 }
338
339 protected function initImageTemplateForm($a_mode)
340 {
342 $ilCtrl = $this->ctrl;
343
344 $form = new ilPropertyFormGUI();
345 $form->setFormAction($ilCtrl->getFormAction($this, "saveBadge"));
346 $form->setTitle($lng->txt("badge_image_template_form"));
347
348 $title = new ilTextInputGUI($lng->txt("title"), "title");
349 $title->setRequired(true);
350 $form->addItem($title);
351
352 $img = new ilImageFileInputGUI($lng->txt("image"), "img");
353 $img->setSuffixes(array("png", "svg"));
354 if ($a_mode == "create") {
355 $img->setRequired(true);
356 }
357 $img->setUseCache(false);
358 $img->setALlowDeletion(false);
359 $form->addItem($img);
360
361 $types_mode = new ilRadioGroupInputGUI($lng->txt("badge_template_types"), "tmode");
362 $types_mode->setRequired(true);
363 $form->addItem($types_mode);
364
365 $type_all = new ilRadioOption($lng->txt("badge_template_types_all"), "all");
366 $types_mode->addOption($type_all);
367
368 $type_spec = new ilRadioOption($lng->txt("badge_template_types_specific"), "spec");
369 $types_mode->addOption($type_spec);
370
371 $types = new ilCheckboxGroupInputGUI($lng->txt("badge_types"), "type");
372 $types->setRequired(true);
373 $type_spec->addSubItem($types);
374
375 foreach (ilBadgeHandler::getInstance()->getAvailableTypes() as $id => $type) {
376 $types->addOption(new ilCheckboxOption($type->getCaption(), $id));
377 }
378
379 if ($a_mode == "create") {
380 $form->addCommandButton("saveImageTemplate", $lng->txt("save"));
381 } else {
382 $form->addCommandButton("updateImageTemplate", $lng->txt("save"));
383 }
384 $form->addCommandButton("listImageTemplates", $lng->txt("cancel"));
385
386 return $form;
387 }
388
389 protected function saveImageTemplate()
390 {
391 $ilCtrl = $this->ctrl;
393
394 $this->checkPermission("write");
395
396 $form = $this->initImageTemplateForm("create");
397 if ($form->checkInput()) {
398 $tmpl = new ilBadgeImageTemplate();
399 $tmpl->setTitle($form->getInput("title"));
400 $tmpl->setTypes($form->getInput("type"));
401 $tmpl->create();
402
403 $tmpl->uploadImage($_FILES["img"]);
404
405 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
406 $ilCtrl->redirect($this, "listImageTemplates");
407 }
408
409 $form->setValuesByPost();
410 $this->addImageTemplate($form);
411 }
412
413 protected function editImageTemplate(ilPropertyFormGUI $a_form = null)
414 {
415 $ilCtrl = $this->ctrl;
417
418 $this->checkPermission("write");
419
420 $this->assertActive();
421 $this->tabs_gui->setTabActive("imgtmpl");
422
423 $tmpl_id = $_REQUEST["tid"];
424 if (!$tmpl_id) {
425 $ilCtrl->redirect($this, "listImageTemplates");
426 }
427
428 $ilCtrl->setParameter($this, "tid", $tmpl_id);
429
430 $tmpl = new ilBadgeImageTemplate($tmpl_id);
431
432 if (!$a_form) {
433 $a_form = $this->initImageTemplateForm("edit");
434 $this->setImageTemplateFormValues($a_form, $tmpl);
435 }
436
437 $tpl->setContent($a_form->getHTML());
438 }
439
441 {
442 $a_form->getItemByPostVar("title")->setValue($a_tmpl->getTitle());
443 $a_form->getItemByPostVar("img")->setImage($a_tmpl->getImagePath());
444 $a_form->getItemByPostVar("img")->setValue($a_tmpl->getImage());
445
446 if ($a_tmpl->getTypes()) {
447 $a_form->getItemByPostVar("tmode")->setValue("spec");
448 $a_form->getItemByPostVar("type")->setValue($a_tmpl->getTypes());
449 } else {
450 $a_form->getItemByPostVar("tmode")->setValue("all");
451 }
452 }
453
454 protected function updateImageTemplate()
455 {
456 $ilCtrl = $this->ctrl;
458
459 $this->checkPermission("write");
460
461 $tmpl_id = $_REQUEST["tid"];
462 if (!$tmpl_id) {
463 $ilCtrl->redirect($this, "listImageTemplates");
464 }
465
466 $ilCtrl->setParameter($this, "tid", $tmpl_id);
467
468 $tmpl = new ilBadgeImageTemplate($tmpl_id);
469
470 $form = $this->initImageTemplateForm("update");
471 if ($form->checkInput()) {
472 $tmpl->setTitle($form->getInput("title"));
473
474 if ($form->getInput("tmode") != "all") {
475 $tmpl->setTypes($form->getInput("type"));
476 } else {
477 $tmpl->setTypes(null);
478 }
479
480 $tmpl->update();
481
482 $tmpl->uploadImage($_FILES["img"]);
483
484 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
485 $ilCtrl->redirect($this, "listImageTemplates");
486 }
487
488 $this->setImageTemplateFormValues($form, $tmpl);
489 $form->setValuesByPost();
490 $this->editImageTemplate($form);
491 }
492
493 protected function confirmDeleteImageTemplates()
494 {
495 $ilCtrl = $this->ctrl;
498 $ilTabs = $this->tabs;
499
500 $this->checkPermission("write");
501
502 $tmpl_ids = $_REQUEST["id"];
503 if (!$tmpl_ids) {
504 $ilCtrl->redirect($this, "listImageTemplates");
505 }
506
507 $ilTabs->clearTargets();
508 $ilTabs->setBackTarget(
509 $lng->txt("back"),
510 $ilCtrl->getLinkTarget($this, "listImageTemplates")
511 );
512
513 $confirmation_gui = new ilConfirmationGUI();
514 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
515 $confirmation_gui->setHeaderText($lng->txt("badge_template_deletion_confirmation"));
516 $confirmation_gui->setCancel($lng->txt("cancel"), "listImageTemplates");
517 $confirmation_gui->setConfirm($lng->txt("delete"), "deleteImageTemplates");
518
519 foreach ($tmpl_ids as $tmpl_id) {
520 $tmpl = new ilBadgeImageTemplate($tmpl_id);
521 $confirmation_gui->addItem("id[]", $tmpl_id, $tmpl->getTitle());
522 }
523
524 $tpl->setContent($confirmation_gui->getHTML());
525 }
526
527 protected function deleteImageTemplates()
528 {
529 $ilCtrl = $this->ctrl;
531
532 $this->checkPermission("write");
533
534 $tmpl_ids = $_REQUEST["id"];
535 if ($tmpl_ids) {
536 foreach ($tmpl_ids as $tmpl_id) {
537 $tmpl = new ilBadgeImageTemplate($tmpl_id);
538 $tmpl->delete();
539 }
540
541 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
542 }
543
544 $ilCtrl->redirect($this, "listImageTemplates");
545 }
546
547
548 //
549 // object badges
550 //
551
552 protected function listObjectBadges()
553 {
554 $ilAccess = $this->access;
556
557 $this->assertActive();
558 $this->tabs_gui->setTabActive("obj_badges");
559
560 $tbl = new ilObjectBadgeTableGUI(
561 $this,
562 "listObjectBadges",
563 $ilAccess->checkAccess("write", "", $this->object->getRefId())
564 );
565 $tpl->setContent($tbl->getHTML());
566 }
567
568 protected function applyObjectFilter()
569 {
570 $ilAccess = $this->access;
571
572 $tbl = new ilObjectBadgeTableGUI(
573 $this,
574 "listObjectBadges",
575 $ilAccess->checkAccess("write", "", $this->object->getRefId())
576 );
577 $tbl->resetOffset();
578 $tbl->writeFilterToSession();
579 $this->listObjectBadges();
580 }
581
582 protected function resetObjectFilter()
583 {
584 $ilAccess = $this->access;
585
586 $tbl = new ilObjectBadgeTableGUI(
587 $this,
588 "listObjectBadges",
589 $ilAccess->checkAccess("write", "", $this->object->getRefId())
590 );
591 $tbl->resetOffset();
592 $tbl->resetFilter();
593 $this->listObjectBadges();
594 }
595
596 protected function listObjectBadgeUsers()
597 {
598 $ilCtrl = $this->ctrl;
601
602 $parent_obj_id = $_REQUEST["pid"];
603 if (!$parent_obj_id) {
604 $ilCtrl->redirect($this, "listObjectBadges");
605 }
606
607 $this->assertActive();
608
609 $this->tabs_gui->clearTargets();
610 $this->tabs_gui->setBackTarget(
611 $lng->txt("back"),
612 $ilCtrl->getLinkTarget($this, "listObjectBadges")
613 );
614
615 $ilCtrl->saveParameter($this, "pid");
616
617 $tbl = new ilBadgeUserTableGUI($this, "listUsers", null, null, $parent_obj_id, (int) $_REQUEST["bid"]);
618 $tpl->setContent($tbl->getHTML());
619 }
620
621 protected function applyUserFilter()
622 {
623 $tbl = new ilBadgeUserTableGUI($this, "listUsers", null, null, $parent_obj_id, (int) $_REQUEST["bid"]);
624 $tbl->resetOffset();
625 $tbl->writeFilterToSession();
626 $this->listObjectBadgeUsers();
627 }
628
629 protected function resetUserFilter()
630 {
631 $tbl = new ilBadgeUserTableGUI($this, "listUsers", null, null, $parent_obj_id, (int) $_REQUEST["bid"]);
632 $tbl->resetOffset();
633 $tbl->resetFilter();
634 $this->listObjectBadgeUsers();
635 }
636
637
638 //
639 // see ilBadgeManagementGUI
640 //
641
643 {
644 $ilAccess = $this->access;
645 $ilCtrl = $this->ctrl;
646
647 $badge_ids = $_REQUEST["id"];
648 if (!$badge_ids ||
649 !$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
650 $ilCtrl->redirect($this, "listObjectBadges");
651 }
652
653 return $badge_ids;
654 }
655
656 protected function toggleObjectBadges($a_status)
657 {
658 $ilCtrl = $this->ctrl;
660
661 $badge_ids = $this->getObjectBadgesFromMultiAction();
662
663 foreach ($badge_ids as $badge_id) {
664 $badge = new ilBadge($badge_id);
665 $badge->setActive($a_status);
666 $badge->update();
667 }
668
669 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
670 $ilCtrl->redirect($this, "listObjectBadges");
671 }
672
673 protected function activateObjectBadges()
674 {
675 $this->toggleObjectBadges(true);
676 }
677
678 protected function deactivateObjectBadges()
679 {
680 $this->toggleObjectBadges(false);
681 }
682
683 protected function confirmDeleteObjectBadges()
684 {
685 $ilCtrl = $this->ctrl;
688 $ilTabs = $this->tabs;
689
690 $badge_ids = $this->getObjectBadgesFromMultiAction();
691
692 $ilTabs->clearTargets();
693 $ilTabs->setBackTarget(
694 $lng->txt("back"),
695 $ilCtrl->getLinkTarget($this, "listObjectBadges")
696 );
697
698 $confirmation_gui = new ilConfirmationGUI();
699 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
700 $confirmation_gui->setHeaderText($lng->txt("badge_deletion_confirmation"));
701 $confirmation_gui->setCancel($lng->txt("cancel"), "listObjectBadges");
702 $confirmation_gui->setConfirm($lng->txt("delete"), "deleteObjectBadges");
703
704 foreach ($badge_ids as $badge_id) {
705 $badge = new ilBadge($badge_id);
706 $parent = $badge->getParentMeta();
707
708 // :TODO: container presentation
709 $container = "(" . $parent["type"] . "/" .
710 $parent["id"] . ") " .
711 $parent["title"];
712 if ((bool) $parent["deleted"]) {
713 $container .= ' <span class="il_ItemAlertProperty">' . $lng->txt("deleted") . '</span>';
714 }
715
716 $confirmation_gui->addItem(
717 "id[]",
718 $badge_id,
719 $container . " - " .
720 $badge->getTitle() .
721 " (" . sizeof(ilBadgeAssignment::getInstancesByBadgeId($badge_id)) . ")"
722 );
723 }
724
725 $tpl->setContent($confirmation_gui->getHTML());
726 }
727
728 protected function deleteObjectBadges()
729 {
730 $ilCtrl = $this->ctrl;
732
733 $badge_ids = $this->getObjectBadgesFromMultiAction();
734
735 foreach ($badge_ids as $badge_id) {
736 $badge = new ilBadge($badge_id);
737 $badge->delete();
738 }
739
740 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
741 $ilCtrl->redirect($this, "listObjectBadges");
742 }
743}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static getInstancesByBadgeId($a_badge_id)
static getInstance()
Constructor.
TableGUI class for badge template listing.
Class ilBadgeManagementGUI.
TableGUI class for badge type listing.
TableGUI class for badge user listing.
Class ilBadge.
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
Confirmation screen class.
This class represents an image file property in a property form.
setImageTemplateFormValues(ilPropertyFormGUI $a_form, ilBadgeImageTemplate $a_tmpl)
editImageTemplate(ilPropertyFormGUI $a_form=null)
addImageTemplate(ilPropertyFormGUI $a_form=null)
getAdminTabs()
administration tabs show only permissions and trash folder
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
TableGUI class for badge listing.
Class ilObjectGUI Basic methods of all Output classes.
checkPermission($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission and redirect on error.
prepareOutput($a_show_subobjects=true)
prepare output
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a text property in a property form.
global $DIC
Definition: goto.php:24
$img
Definition: imgupload.php:57
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type
$container
Definition: wac.php:13