ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 {
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;
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 {
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->setALlowDeletion(false);
358 $form->addItem($img);
359
360 $types_mode = new ilRadioGroupInputGUI($lng->txt("badge_template_types"), "tmode");
361 $types_mode->setRequired(true);
362 $form->addItem($types_mode);
363
364 $type_all = new ilRadioOption($lng->txt("badge_template_types_all"), "all");
365 $types_mode->addOption($type_all);
366
367 $type_spec = new ilRadioOption($lng->txt("badge_template_types_specific"), "spec");
368 $types_mode->addOption($type_spec);
369
370 $types = new ilCheckboxGroupInputGUI($lng->txt("badge_types"), "type");
371 $types->setRequired(true);
372 $type_spec->addSubItem($types);
373
374 foreach (ilBadgeHandler::getInstance()->getAvailableTypes() as $id => $type) {
375 $types->addOption(new ilCheckboxOption($type->getCaption(), $id));
376 }
377
378 if ($a_mode == "create") {
379 $form->addCommandButton("saveImageTemplate", $lng->txt("save"));
380 } else {
381 $form->addCommandButton("updateImageTemplate", $lng->txt("save"));
382 }
383 $form->addCommandButton("listImageTemplates", $lng->txt("cancel"));
384
385 return $form;
386 }
387
388 protected function saveImageTemplate()
389 {
392
393 $this->checkPermission("write");
394
395 $form = $this->initImageTemplateForm("create");
396 if ($form->checkInput()) {
397 $tmpl = new ilBadgeImageTemplate();
398 $tmpl->setTitle($form->getInput("title"));
399 $tmpl->setTypes($form->getInput("type"));
400 $tmpl->create();
401
402 $tmpl->uploadImage($_FILES["img"]);
403
404 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
405 $ilCtrl->redirect($this, "listImageTemplates");
406 }
407
408 $form->setValuesByPost();
409 $this->addImageTemplate($form);
410 }
411
412 protected function editImageTemplate(ilPropertyFormGUI $a_form = null)
413 {
416
417 $this->checkPermission("write");
418
419 $this->assertActive();
420 $this->tabs_gui->setTabActive("imgtmpl");
421
422 $tmpl_id = $_REQUEST["tid"];
423 if (!$tmpl_id) {
424 $ilCtrl->redirect($this, "listImageTemplates");
425 }
426
427 $ilCtrl->setParameter($this, "tid", $tmpl_id);
428
429 $tmpl = new ilBadgeImageTemplate($tmpl_id);
430
431 if (!$a_form) {
432 $a_form = $this->initImageTemplateForm("edit");
433 $this->setImageTemplateFormValues($a_form, $tmpl);
434 }
435
436 $tpl->setContent($a_form->getHTML());
437 }
438
440 {
441 $a_form->getItemByPostVar("title")->setValue($a_tmpl->getTitle());
442 $a_form->getItemByPostVar("img")->setImage($a_tmpl->getImagePath());
443 $a_form->getItemByPostVar("img")->setValue($a_tmpl->getImage());
444
445 if ($a_tmpl->getTypes()) {
446 $a_form->getItemByPostVar("tmode")->setValue("spec");
447 $a_form->getItemByPostVar("type")->setValue($a_tmpl->getTypes());
448 } else {
449 $a_form->getItemByPostVar("tmode")->setValue("all");
450 }
451 }
452
453 protected function updateImageTemplate()
454 {
457
458 $this->checkPermission("write");
459
460 $tmpl_id = $_REQUEST["tid"];
461 if (!$tmpl_id) {
462 $ilCtrl->redirect($this, "listImageTemplates");
463 }
464
465 $ilCtrl->setParameter($this, "tid", $tmpl_id);
466
467 $tmpl = new ilBadgeImageTemplate($tmpl_id);
468
469 $form = $this->initImageTemplateForm("update");
470 if ($form->checkInput()) {
471 $tmpl->setTitle($form->getInput("title"));
472
473 if ($form->getInput("tmode") != "all") {
474 $tmpl->setTypes($form->getInput("type"));
475 } else {
476 $tmpl->setTypes(null);
477 }
478
479 $tmpl->update();
480
481 $tmpl->uploadImage($_FILES["img"]);
482
483 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
484 $ilCtrl->redirect($this, "listImageTemplates");
485 }
486
487 $this->setImageTemplateFormValues($form, $tmpl);
488 $form->setValuesByPost();
489 $this->editImageTemplate($form);
490 }
491
492 protected function confirmDeleteImageTemplates()
493 {
497 $ilTabs = $this->tabs;
498
499 $this->checkPermission("write");
500
501 $tmpl_ids = $_REQUEST["id"];
502 if (!$tmpl_ids) {
503 $ilCtrl->redirect($this, "listImageTemplates");
504 }
505
506 $ilTabs->clearTargets();
507 $ilTabs->setBackTarget(
508 $lng->txt("back"),
509 $ilCtrl->getLinkTarget($this, "listImageTemplates")
510 );
511
512 $confirmation_gui = new ilConfirmationGUI();
513 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
514 $confirmation_gui->setHeaderText($lng->txt("badge_template_deletion_confirmation"));
515 $confirmation_gui->setCancel($lng->txt("cancel"), "listImageTemplates");
516 $confirmation_gui->setConfirm($lng->txt("delete"), "deleteImageTemplates");
517
518 foreach ($tmpl_ids as $tmpl_id) {
519 $tmpl = new ilBadgeImageTemplate($tmpl_id);
520 $confirmation_gui->addItem("id[]", $tmpl_id, $tmpl->getTitle());
521 }
522
523 $tpl->setContent($confirmation_gui->getHTML());
524 }
525
526 protected function deleteImageTemplates()
527 {
530
531 $this->checkPermission("write");
532
533 $tmpl_ids = $_REQUEST["id"];
534 if ($tmpl_ids) {
535 foreach ($tmpl_ids as $tmpl_id) {
536 $tmpl = new ilBadgeImageTemplate($tmpl_id);
537 $tmpl->delete();
538 }
539
540 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
541 }
542
543 $ilCtrl->redirect($this, "listImageTemplates");
544 }
545
546
547 //
548 // object badges
549 //
550
551 protected function listObjectBadges()
552 {
553 $ilAccess = $this->access;
555
556 $this->assertActive();
557 $this->tabs_gui->setTabActive("obj_badges");
558
559 $tbl = new ilObjectBadgeTableGUI(
560 $this,
561 "listObjectBadges",
562 $ilAccess->checkAccess("write", "", $this->object->getRefId())
563 );
564 $tpl->setContent($tbl->getHTML());
565 }
566
567 protected function applyObjectFilter()
568 {
569 $ilAccess = $this->access;
570
571 $tbl = new ilObjectBadgeTableGUI(
572 $this,
573 "listObjectBadges",
574 $ilAccess->checkAccess("write", "", $this->object->getRefId())
575 );
576 $tbl->resetOffset();
577 $tbl->writeFilterToSession();
578 $this->listObjectBadges();
579 }
580
581 protected function resetObjectFilter()
582 {
583 $ilAccess = $this->access;
584
585 $tbl = new ilObjectBadgeTableGUI(
586 $this,
587 "listObjectBadges",
588 $ilAccess->checkAccess("write", "", $this->object->getRefId())
589 );
590 $tbl->resetOffset();
591 $tbl->resetFilter();
592 $this->listObjectBadges();
593 }
594
595 protected function listObjectBadgeUsers()
596 {
600
601 $parent_obj_id = $_REQUEST["pid"];
602 if (!$parent_obj_id) {
603 $ilCtrl->redirect($this, "listObjectBadges");
604 }
605
606 $this->assertActive();
607
608 $this->tabs_gui->clearTargets();
609 $this->tabs_gui->setBackTarget(
610 $lng->txt("back"),
611 $ilCtrl->getLinkTarget($this, "listObjectBadges")
612 );
613
614 $ilCtrl->saveParameter($this, "pid");
615
616 $tbl = new ilBadgeUserTableGUI($this, "listUsers", null, null, $parent_obj_id, (int) $_REQUEST["bid"]);
617 $tpl->setContent($tbl->getHTML());
618 }
619
620 protected function applyUserFilter()
621 {
622 $tbl = new ilBadgeUserTableGUI($this, "listUsers", null, null, $parent_obj_id, (int) $_REQUEST["bid"]);
623 $tbl->resetOffset();
624 $tbl->writeFilterToSession();
625 $this->listObjectBadgeUsers();
626 }
627
628 protected function resetUserFilter()
629 {
630 $tbl = new ilBadgeUserTableGUI($this, "listUsers", null, null, $parent_obj_id, (int) $_REQUEST["bid"]);
631 $tbl->resetOffset();
632 $tbl->resetFilter();
633 $this->listObjectBadgeUsers();
634 }
635
636
637 //
638 // see ilBadgeManagementGUI
639 //
640
642 {
643 $ilAccess = $this->access;
645
646 $badge_ids = $_REQUEST["id"];
647 if (!$badge_ids ||
648 !$ilAccess->checkAccess("write", "", $this->object->getRefId())) {
649 $ilCtrl->redirect($this, "listObjectBadges");
650 }
651
652 return $badge_ids;
653 }
654
655 protected function toggleObjectBadges($a_status)
656 {
659
660 $badge_ids = $this->getObjectBadgesFromMultiAction();
661
662 foreach ($badge_ids as $badge_id) {
663 $badge = new ilBadge($badge_id);
664 $badge->setActive($a_status);
665 $badge->update();
666 }
667
668 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
669 $ilCtrl->redirect($this, "listObjectBadges");
670 }
671
672 protected function activateObjectBadges()
673 {
674 $this->toggleObjectBadges(true);
675 }
676
677 protected function deactivateObjectBadges()
678 {
679 $this->toggleObjectBadges(false);
680 }
681
682 protected function confirmDeleteObjectBadges()
683 {
687 $ilTabs = $this->tabs;
688
689 $badge_ids = $this->getObjectBadgesFromMultiAction();
690
691 $ilTabs->clearTargets();
692 $ilTabs->setBackTarget(
693 $lng->txt("back"),
694 $ilCtrl->getLinkTarget($this, "listObjectBadges")
695 );
696
697 $confirmation_gui = new ilConfirmationGUI();
698 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
699 $confirmation_gui->setHeaderText($lng->txt("badge_deletion_confirmation"));
700 $confirmation_gui->setCancel($lng->txt("cancel"), "listObjectBadges");
701 $confirmation_gui->setConfirm($lng->txt("delete"), "deleteObjectBadges");
702
703 foreach ($badge_ids as $badge_id) {
704 $badge = new ilBadge($badge_id);
705 $parent = $badge->getParentMeta();
706
707 // :TODO: container presentation
708 $container = "(" . $parent["type"] . "/" .
709 $parent["id"] . ") " .
710 $parent["title"];
711 if ((bool) $parent["deleted"]) {
712 $container .= ' <span class="il_ItemAlertProperty">' . $lng->txt("deleted") . '</span>';
713 }
714
715 $confirmation_gui->addItem(
716 "id[]",
717 $badge_id,
718 $container . " - " .
719 $badge->getTitle() .
720 " (" . sizeof(ilBadgeAssignment::getInstancesByBadgeId($badge_id)) . ")"
721 );
722 }
723
724 $tpl->setContent($confirmation_gui->getHTML());
725 }
726
727 protected function deleteObjectBadges()
728 {
731
732 $badge_ids = $this->getObjectBadgesFromMultiAction();
733
734 foreach ($badge_ids as $badge_id) {
735 $badge = new ilBadge($badge_id);
736 $badge->delete();
737 }
738
739 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
740 $ilCtrl->redirect($this, "listObjectBadges");
741 }
742}
$_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 $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type
$container
Definition: wac.php:13
$DIC
Definition: xapitoken.php:46