ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBadgeManagementGUI.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
13{
17 protected $lng;
18
22 protected $ctrl;
23
27 protected $tabs;
28
32 protected $access;
33
37 protected $toolbar;
38
42 protected $tpl;
43
47 protected $user;
48
49 protected $parent_ref_id; // [int]
50 protected $parent_obj_id; // [int]
51 protected $parent_obj_type; // [string]
52
53 const CLIPBOARD_ID = "bdgclpbrd";
54
63 public function __construct($a_parent_ref_id, $a_parent_obj_id = null, $a_parent_obj_type = null)
64 {
65 global $DIC;
66
67 $this->lng = $DIC->language();
68 $this->ctrl = $DIC->ctrl();
69 $this->tabs = $DIC->tabs();
70 $this->access = $DIC->access();
71 $this->toolbar = $DIC->toolbar();
72 $this->tpl = $DIC["tpl"];
73 $this->user = $DIC->user();
74 $lng = $DIC->language();
75
76 $this->parent_ref_id = $a_parent_ref_id;
77 $this->parent_obj_id = $a_parent_obj_id
78 ? $a_parent_obj_id
79 : ilObject::_lookupObjId($a_parent_ref_id);
80 $this->parent_obj_type = $a_parent_obj_type
81 ? $a_parent_obj_type
82 : ilObject::_lookupType($this->parent_obj_id);
83
84 if (!ilBadgeHandler::getInstance()->isObjectActive($this->parent_obj_id)) {
85 throw new ilException("inactive object");
86 }
87
88 $lng->loadLanguageModule("badge");
89 }
90
91 public function executeCommand()
92 {
94 $ilTabs = $this->tabs;
96
97 $next_class = $ilCtrl->getNextClass($this);
98 $cmd = $ilCtrl->getCmd("listBadges");
99
100 switch ($next_class) {
101 case "ilpropertyformgui":
102 // ajax - update
103 if ((int) $_REQUEST["bid"]) {
104 $badge = new ilBadge((int) $_REQUEST["bid"]);
105 $type = $badge->getTypeInstance();
106 $form = $this->initBadgeForm("edit", $type, $badge->getTypeId());
107 $this->setBadgeFormValues($form, $badge, $type);
108 }
109 // ajax- create
110 else {
111 $type_id = $_REQUEST["type"];
112 $ilCtrl->setParameter($this, "type", $type_id);
113 $handler = ilBadgeHandler::getInstance();
114 $type = $handler->getTypeInstanceByUniqueId($type_id);
115 $form = $this->initBadgeForm("create", $type, $type_id);
116 }
117 $ilCtrl->forwardCommand($form);
118 break;
119
120 /*
121 case "illplistofsettingsgui":
122 $id = $_GET["lpid"];
123 if($id)
124 {
125 $ilCtrl->saveParameter($this, "bid");
126 $ilCtrl->saveParameter($this, "lpid");
127
128 $ilTabs->clearTargets();
129 $ilTabs->setBackTarget(
130 $lng->txt("back"),
131 $ilCtrl->getLinkTarget($this, "editBadge")
132 );
133 $lpgui = new ilLPListOfSettingsGUI(ilLearningProgressGUI::LP_CONTEXT_REPOSITORY, $id);
134 $ilCtrl->forwardCommand($lpgui);
135 break;
136 }
137 */
138
139 default:
140 $this->$cmd();
141 break;
142 }
143
144 return true;
145 }
146
147 protected function setTabs($a_active)
148 {
149 $ilTabs = $this->tabs;
152
153 $ilTabs->addSubTab(
154 "badges",
155 $lng->txt("obj_bdga"),
156 $ilCtrl->getLinkTarget($this, "listBadges")
157 );
158
159 $ilTabs->addSubTab(
160 "users",
161 $lng->txt("users"),
162 $ilCtrl->getLinkTarget($this, "listUsers")
163 );
164
165 $ilTabs->activateSubTab($a_active);
166 }
167
168 protected function hasWrite()
169 {
170 $ilAccess = $this->access;
171 return $ilAccess->checkAccess("write", "", $this->parent_ref_id);
172 }
173
174 protected function listBadges()
175 {
176 $ilToolbar = $this->toolbar;
180
181 $this->setTabs("badges");
182
183 if ($this->hasWrite()) {
184 $handler = ilBadgeHandler::getInstance();
185 $valid_types = $handler->getAvailableTypesForObjType($this->parent_obj_type);
186 if ($valid_types) {
187 $options = array();
188 foreach ($valid_types as $id => $type) {
189 $options[$id] = ($this->parent_obj_type != "bdga")
191 : $type->getCaption();
192 }
193 asort($options);
194
195 $drop = new ilSelectInputGUI($lng->txt("type"), "type");
196 $drop->setOptions($options);
197 $ilToolbar->addInputItem($drop, true);
198
199 $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "addBadge"));
200 $ilToolbar->addFormButton($lng->txt("create"), "addBadge");
201 } else {
202 ilUtil::sendInfo($lng->txt("badge_no_valid_types_for_obj"));
203 }
204
205 if (is_array($_SESSION[self::CLIPBOARD_ID])) {
206 if ($valid_types) {
207 $ilToolbar->addSeparator();
208 }
209
210 $tt = array();
211 foreach ($this->getValidBadgesFromClipboard() as $badge) {
212 $tt[] = $badge->getTitle();
213 }
214 $ttid = "bdgpst";
216 $ttid,
217 implode("<br />", $tt),
218 "",
219 "bottom center",
220 "top center",
221 false
222 );
223
224 $lng->loadLanguageModule("content");
225 $ilToolbar->addButton(
226 $lng->txt("cont_paste_from_clipboard") .
227 " (" . sizeof($tt) . ")",
228 $ilCtrl->getLinkTarget($this, "pasteBadges"),
229 "",
230 "",
231 "",
232 $ttid
233 );
234 $ilToolbar->addButton(
235 $lng->txt("clear_clipboard"),
236 $ilCtrl->getLinkTarget($this, "clearClipboard")
237 );
238 }
239 }
240
241 $tbl = new ilBadgeTableGUI($this, "listBadges", $this->parent_obj_id, $this->hasWrite());
242 $tpl->setContent($tbl->getHTML());
243 }
244
245 protected function applyBadgeFilter()
246 {
247 $tbl = new ilBadgeTableGUI($this, "listBadges", $this->parent_obj_id, $this->hasWrite());
248 $tbl->resetOffset();
249 $tbl->writeFilterToSession();
250 $this->listBadges();
251 }
252
253 protected function resetBadgeFilter()
254 {
255 $tbl = new ilBadgeTableGUI($this, "listBadges", $this->parent_obj_id, $this->hasWrite());
256 $tbl->resetOffset();
257 $tbl->resetFilter();
258 $this->listBadges();
259 }
260
261
262 //
263 // badge (CRUD)
264 //
265
266 protected function addBadge(ilPropertyFormGUI $a_form = null)
267 {
270
271 $type_id = $_REQUEST["type"];
272 if (!$type_id ||
273 !$this->hasWrite()) {
274 $ilCtrl->redirect($this, "listBadges");
275 }
276
277 $ilCtrl->setParameter($this, "type", $type_id);
278
279 $handler = ilBadgeHandler::getInstance();
280 $type = $handler->getTypeInstanceByUniqueId($type_id);
281 if (!$type) {
282 $ilCtrl->redirect($this, "listBadges");
283 }
284
285 if (!$a_form) {
286 $a_form = $this->initBadgeForm("create", $type, $type_id);
287 }
288
289 $tpl->setContent($a_form->getHTML());
290 }
291
292 protected function initBadgeForm($a_mode, ilBadgeType $a_type, $a_type_unique_id)
293 {
296
297 $form = new ilPropertyFormGUI();
298 $form->setFormAction($ilCtrl->getFormAction($this, "saveBadge"));
299 $form->setTitle($lng->txt("badge_badge") . ' "' . $a_type->getCaption() . '"');
300
301 $active = new ilCheckboxInputGUI($lng->txt("active"), "act");
302 $form->addItem($active);
303
304 $title = new ilTextInputGUI($lng->txt("title"), "title");
305 $title->setRequired(true);
306 $form->addItem($title);
307
308 $desc = new ilTextAreaInputGUI($lng->txt("description"), "desc");
309 $desc->setRequired(true);
310 $form->addItem($desc);
311
312 $crit = new ilTextAreaInputGUI($lng->txt("badge_criteria"), "crit");
313 $crit->setRequired(true);
314 $form->addItem($crit);
315
316 if ($a_mode == "create") {
317 // upload
318
319 $img_mode = new ilRadioGroupInputGUI($lng->txt("image"), "img_mode");
320 $img_mode->setRequired(true);
321 $form->addItem($img_mode);
322
323 $img_mode_tmpl = new ilRadioOption($lng->txt("badge_image_from_template"), "tmpl");
324 $img_mode->addOption($img_mode_tmpl);
325
326 $img_mode_up = new ilRadioOption($lng->txt("badge_image_from_upload"), "up");
327 $img_mode->addOption($img_mode_up);
328
329 $img_upload = new ilImageFileInputGUI($lng->txt("file"), "img");
330 $img_upload->setRequired(true);
331 $img_upload->setSuffixes(array("png", "svg"));
332 $img_mode_up->addSubItem($img_upload);
333
334 // templates
335
336 $valid_templates = ilBadgeImageTemplate::getInstancesByType($a_type_unique_id);
337 if (sizeof($valid_templates)) {
338 $options = array();
339 $options[""] = $lng->txt("please_select");
340 foreach ($valid_templates as $tmpl) {
341 $options[$tmpl->getId()] = $tmpl->getTitle();
342 }
343
344 $tmpl = new ilSelectInputGUI($lng->txt("badge_image_template_form"), "tmpl");
345 $tmpl->setRequired(true);
346 $tmpl->setOptions($options);
347 $img_mode_tmpl->addSubItem($tmpl);
348 } else {
349 // no templates, activate upload
350 $img_mode_tmpl->setDisabled(true);
351 $img_mode->setValue("up");
352 }
353 } else {
354 $img_upload = new ilImageFileInputGUI($lng->txt("image"), "img");
355 $img_upload->setSuffixes(array("png", "svg"));
356 $img_upload->setALlowDeletion(false);
357 $form->addItem($img_upload);
358 }
359
360 $valid = new ilTextInputGUI($lng->txt("badge_valid"), "valid");
361 $form->addItem($valid);
362
363 $custom = $a_type->getConfigGUIInstance();
364 if ($custom &&
365 $custom instanceof ilBadgeTypeGUI) {
366 $custom->initConfigForm($form, $this->parent_ref_id);
367 }
368
369 // :TODO: valid date/period
370
371 if ($a_mode == "create") {
372 $form->addCommandButton("saveBadge", $lng->txt("save"));
373 } else {
374 $form->addCommandButton("updateBadge", $lng->txt("save"));
375 }
376 $form->addCommandButton("listBadges", $lng->txt("cancel"));
377
378 return $form;
379 }
380
381 protected function saveBadge()
382 {
385
386 $type_id = $_REQUEST["type"];
387 if (!$type_id ||
388 !$this->hasWrite()) {
389 $ilCtrl->redirect($this, "listBadges");
390 }
391
392 $ilCtrl->setParameter($this, "type", $type_id);
393
394 $handler = ilBadgeHandler::getInstance();
395 $type = $handler->getTypeInstanceByUniqueId($type_id);
396 if (!$type) {
397 $ilCtrl->redirect($this, "listBadges");
398 }
399
400 $form = $this->initBadgeForm("create", $type, $type_id);
401 $custom = $type->getConfigGUIInstance();
402
403 if ($form->checkInput() &&
404 (!$custom || $custom->validateForm($form))) {
405 $badge = new ilBadge();
406 $badge->setParentId($this->parent_obj_id); // :TODO: ref_id?
407 $badge->setTypeId($type_id);
408 $badge->setActive($form->getInput("act"));
409 $badge->setTitle($form->getInput("title"));
410 $badge->setDescription($form->getInput("desc"));
411 $badge->setCriteria($form->getInput("crit"));
412 $badge->setValid($form->getInput("valid"));
413
414 if ($custom &&
415 $custom instanceof ilBadgeTypeGUI) {
416 $badge->setConfiguration($custom->getConfigFromForm($form));
417 }
418
419 $badge->create();
420
421 if ($form->getInput("img_mode") == "up") {
422 $badge->uploadImage($_FILES["img"]);
423 } else {
424 $tmpl = new ilBadgeImageTemplate($form->getInput("tmpl"));
425 $badge->importImage($tmpl->getImage(), $tmpl->getImagePath());
426 }
427
428 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
429 $ilCtrl->redirect($this, "listBadges");
430 }
431
432 $form->setValuesByPost();
433 $this->addBadge($form);
434 }
435
436 protected function editBadge(ilPropertyFormGUI $a_form = null)
437 {
441
442 $badge_id = $_REQUEST["bid"];
443 if (!$badge_id ||
444 !$this->hasWrite()) {
445 $ilCtrl->redirect($this, "listBadges");
446 }
447
448 $ilCtrl->setParameter($this, "bid", $badge_id);
449
450 $badge = new ilBadge($badge_id);
451
452 $static_cnt = ilBadgeHandler::getInstance()->countStaticBadgeInstances($badge);
453 if ($static_cnt) {
454 ilUtil::sendInfo(sprintf($lng->txt("badge_edit_with_published"), $static_cnt));
455 }
456
457 if (!$a_form) {
458 $type = $badge->getTypeInstance();
459 $a_form = $this->initBadgeForm("edit", $type, $badge->getTypeId());
460 $this->setBadgeFormValues($a_form, $badge, $type);
461 }
462
463 $tpl->setContent($a_form->getHTML());
464 }
465
466 protected function setBadgeFormValues(ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
467 {
468 $a_form->getItemByPostVar("act")->setChecked($a_badge->isActive());
469 $a_form->getItemByPostVar("title")->setValue($a_badge->getTitle());
470 $a_form->getItemByPostVar("desc")->setValue($a_badge->getDescription());
471 $a_form->getItemByPostVar("crit")->setValue($a_badge->getCriteria());
472 $a_form->getItemByPostVar("img")->setValue($a_badge->getImage());
473 $a_form->getItemByPostVar("img")->setImage($a_badge->getImagePath());
474 $a_form->getItemByPostVar("valid")->setValue($a_badge->getValid());
475
476 $custom = $a_type->getConfigGUIInstance();
477 if ($custom &&
478 $custom instanceof ilBadgeTypeGUI) {
479 $custom->importConfigToForm($a_form, $a_badge->getConfiguration());
480 }
481 }
482
483 protected function updateBadge()
484 {
487
488 $badge_id = $_REQUEST["bid"];
489 if (!$badge_id ||
490 !$this->hasWrite()) {
491 $ilCtrl->redirect($this, "listBadges");
492 }
493
494 $ilCtrl->setParameter($this, "bid", $badge_id);
495
496 $badge = new ilBadge($badge_id);
497 $type = $badge->getTypeInstance();
498 $custom = $type->getConfigGUIInstance();
499 if ($custom &&
500 !($custom instanceof ilBadgeTypeGUI)) {
501 $custom = null;
502 }
503 $form = $this->initBadgeForm("update", $type, $badge->getTypeId());
504 if ($form->checkInput() &&
505 (!$custom || $custom->validateForm($form))) {
506 $badge->setActive($form->getInput("act"));
507 $badge->setTitle($form->getInput("title"));
508 $badge->setDescription($form->getInput("desc"));
509 $badge->setCriteria($form->getInput("crit"));
510 $badge->setValid($form->getInput("valid"));
511
512 if ($custom) {
513 $badge->setConfiguration($custom->getConfigFromForm($form));
514 }
515
516 $badge->update();
517
518 $badge->uploadImage($_FILES["img"]);
519
520 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
521 $ilCtrl->redirect($this, "listBadges");
522 }
523
524 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
525 $form->setValuesByPost();
526 $this->editBadge($form);
527 }
528
529 protected function confirmDeleteBadges()
530 {
534 $ilTabs = $this->tabs;
535
536 $badge_ids = $this->getBadgesFromMultiAction();
537
538 $ilTabs->clearTargets();
539 $ilTabs->setBackTarget(
540 $lng->txt("back"),
541 $ilCtrl->getLinkTarget($this, "listBadges")
542 );
543
544 $confirmation_gui = new ilConfirmationGUI();
545 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
546 $confirmation_gui->setHeaderText($lng->txt("badge_deletion_confirmation"));
547 $confirmation_gui->setCancel($lng->txt("cancel"), "listBadges");
548 $confirmation_gui->setConfirm($lng->txt("delete"), "deleteBadges");
549
550 foreach ($badge_ids as $badge_id) {
551 $badge = new ilBadge($badge_id);
552 $confirmation_gui->addItem("id[]", $badge_id, $badge->getTitle() .
553 " (" . sizeof(ilBadgeAssignment::getInstancesByBadgeId($badge_id)) . ")");
554 }
555
556 $tpl->setContent($confirmation_gui->getHTML());
557 }
558
559 protected function deleteBadges()
560 {
563
564 $badge_ids = $this->getBadgesFromMultiAction();
565
566 foreach ($badge_ids as $badge_id) {
567 $badge = new ilBadge($badge_id);
568 $badge->delete();
569 }
570
571 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
572 $ilCtrl->redirect($this, "listBadges");
573 }
574
575
576 //
577 // badges multi action
578 //
579
580 protected function getBadgesFromMultiAction()
581 {
583
584 $badge_ids = $_REQUEST["id"];
585 if (!$badge_ids ||
586 !$this->hasWrite()) {
587 $ilCtrl->redirect($this, "listBadges");
588 }
589
590 return $badge_ids;
591 }
592
593 protected function copyBadges()
594 {
596
597 $badge_ids = $this->getBadgesFromMultiAction();
598
599 $_SESSION[self::CLIPBOARD_ID] = array_unique(
600 array_merge((array) $_SESSION[self::CLIPBOARD_ID], $badge_ids)
601 );
602
603 $ilCtrl->redirect($this, "listBadges");
604 }
605
606 protected function clearClipboard()
607 {
609
610 unset($_SESSION[self::CLIPBOARD_ID]);
611 $ilCtrl->redirect($this, "listBadges");
612 }
613
614 protected function getValidBadgesFromClipboard()
615 {
616 $res = array();
617
618 $valid_types = array_keys(ilBadgeHandler::getInstance()->getAvailableTypesForObjType($this->parent_obj_type));
619
620 foreach ($_SESSION[self::CLIPBOARD_ID] as $badge_id) {
621 $badge = new ilBadge($badge_id);
622 if (in_array($badge->getTypeId(), $valid_types)) {
623 $res[] = $badge;
624 }
625 }
626
627 return $res;
628 }
629
630 protected function pasteBadges()
631 {
633
634 if (!$this->hasWrite() ||
635 !is_array($_SESSION[self::CLIPBOARD_ID])) {
636 $ilCtrl->redirect($this, "listBadges");
637 }
638
639 foreach ($this->getValidBadgesFromClipboard() as $badge) {
640 $badge->copy($this->parent_obj_id);
641 }
642
643 $ilCtrl->redirect($this, "listBadges");
644 }
645
646 protected function toggleBadges($a_status)
647 {
650
651 $badge_ids = $this->getBadgesFromMultiAction();
652
653 foreach ($badge_ids as $badge_id) {
654 $badge = new ilBadge($badge_id);
655 $badge->setActive($a_status);
656 $badge->update();
657 }
658
659 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
660 $ilCtrl->redirect($this, "listBadges");
661 }
662
663 protected function activateBadges()
664 {
665 $this->toggleBadges(true);
666 }
667
668 protected function deactivateBadges()
669 {
670 $this->toggleBadges(false);
671 }
672
673
674 //
675 // users
676 //
677
678 protected function listUsers()
679 {
682 $ilToolbar = $this->toolbar;
684
685 $this->setTabs("users");
686
687 if ($this->hasWrite()) {
688 $manual = ilBadgeHandler::getInstance()->getAvailableManualBadges($this->parent_obj_id, $this->parent_obj_type);
689 if (sizeof($manual)) {
690 $drop = new ilSelectInputGUI($lng->txt("badge_badge"), "bid");
691 $drop->setOptions($manual);
692 $ilToolbar->addInputItem($drop, true);
693
694 $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "awardBadgeUserSelection"));
695 $ilToolbar->addFormButton($lng->txt("badge_award_badge"), "awardBadgeUserSelection");
696 }
697 }
698
699 $tbl = new ilBadgeUserTableGUI($this, "listUsers", $this->parent_ref_id);
700 $tpl->setContent($tbl->getHTML());
701 }
702
703 protected function applyListUsers()
704 {
705 $tbl = new ilBadgeUserTableGUI($this, "listUsers", $this->parent_ref_id);
706 $tbl->resetOffset();
707 $tbl->writeFilterToSession();
708 $this->listUsers();
709 }
710
711 protected function resetListUsers()
712 {
713 $tbl = new ilBadgeUserTableGUI($this, "listUsers", $this->parent_ref_id);
714 $tbl->resetOffset();
715 $tbl->resetFilter();
716 $this->listUsers();
717 }
718
719 protected function awardBadgeUserSelection()
720 {
723 $ilTabs = $this->tabs;
725
726 $bid = (int) $_REQUEST["bid"];
727 if (!$bid ||
728 !$this->hasWrite()) {
729 $ilCtrl->redirect($this, "listUsers");
730 }
731
732 $manual = array_keys(ilBadgeHandler::getInstance()->getAvailableManualBadges($this->parent_obj_id, $this->parent_obj_type));
733 if (!in_array($bid, $manual)) {
734 $ilCtrl->redirect($this, "listUsers");
735 }
736
737 $back_target = "listUsers";
738 if ($_REQUEST["tgt"] == "bdgl") {
739 $ilCtrl->saveParameter($this, "tgt");
740 $back_target = "listBadges";
741 }
742
743 $ilTabs->clearTargets();
744 $ilTabs->setBackTarget(
745 $lng->txt("back"),
746 $ilCtrl->getLinkTarget($this, $back_target)
747 );
748
749 $ilCtrl->setParameter($this, "bid", $bid);
750
751 $badge = new ilBadge($bid);
752
753 $tbl = new ilBadgeUserTableGUI($this, "awardBadgeUserSelection", $this->parent_ref_id, $badge);
754 $tpl->setContent($tbl->getHTML());
755 }
756
757 protected function applyAwardBadgeUserSelection()
758 {
759 $tbl = new ilBadgeUserTableGUI($this, "awardBadgeUserSelection", $this->parent_ref_id);
760 $tbl->resetOffset();
761 $tbl->writeFilterToSession();
763 }
764
765 protected function resetAwardBadgeUserSelection()
766 {
767 $tbl = new ilBadgeUserTableGUI($this, "awardBadgeUserSelection", $this->parent_ref_id);
768 $tbl->resetOffset();
769 $tbl->resetFilter();
771 }
772
773 protected function assignBadge()
774 {
778
779 $user_ids = $_POST["id"];
780 $badge_id = $_REQUEST["bid"];
781 if (!$user_ids ||
782 !$badge_id ||
783 !$this->hasWrite()) {
784 $ilCtrl->redirect($this, "listUsers");
785 }
786
787 $new_badges = array();
788 foreach ($user_ids as $user_id) {
789 if (!ilBadgeAssignment::exists($badge_id, $user_id)) {
790 $ass = new ilBadgeAssignment($badge_id, $user_id);
791 $ass->setAwardedBy($ilUser->getId());
792 $ass->store();
793
794 $new_badges[$user_id][] = $badge_id;
795 }
796 }
797
798 ilBadgeHandler::getInstance()->sendNotification($new_badges, $this->parent_ref_id);
799
800 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
801 $ilCtrl->redirect($this, "listUsers");
802 }
803
804 protected function confirmDeassignBadge()
805 {
809 $ilTabs = $this->tabs;
810
811 $user_ids = $_POST["id"];
812 $badge_id = $_REQUEST["bid"];
813 if (!$user_ids ||
814 !$badge_id ||
815 !$this->hasWrite()) {
816 $ilCtrl->redirect($this, "listUsers");
817 }
818
819 $ilTabs->clearTargets();
820 $ilTabs->setBackTarget(
821 $lng->txt("back"),
822 $ilCtrl->getLinkTarget($this, "listUsers")
823 );
824
825 $badge = new ilBadge($badge_id);
826
827 $ilCtrl->setParameter($this, "bid", $badge->getId());
828
829 $confirmation_gui = new ilConfirmationGUI();
830 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
831 $confirmation_gui->setHeaderText(sprintf($lng->txt("badge_assignment_deletion_confirmation"), $badge->getTitle()));
832 $confirmation_gui->setCancel($lng->txt("cancel"), "listUsers");
833 $confirmation_gui->setConfirm($lng->txt("delete"), "deassignBadge");
834
835 $assigned_users = ilBadgeAssignment::getAssignedUsers($badge->getId());
836
837 foreach ($user_ids as $user_id) {
838 if (in_array($user_id, $assigned_users)) {
839 $confirmation_gui->addItem(
840 "id[]",
841 $user_id,
842 ilUserUtil::getNamePresentation($user_id, false, false, "", true)
843 );
844 }
845 }
846
847 $tpl->setContent($confirmation_gui->getHTML());
848 }
849
850 protected function deassignBadge()
851 {
854
855 $user_ids = $_POST["id"];
856 $badge_id = $_REQUEST["bid"];
857 if (!$user_ids ||
858 !$badge_id ||
859 !$this->hasWrite()) {
860 $ilCtrl->redirect($this, "listUsers");
861 }
862
863 foreach ($user_ids as $user_id) {
864 $ass = new ilBadgeAssignment($badge_id, $user_id);
865 $ass->delete();
866 }
867
868 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
869 $ilCtrl->redirect($this, "listUsers");
870 }
871}
user()
Definition: user.php:4
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
Class ilBadgeAssignment.
static getAssignedUsers($a_badge_id)
static getInstancesByBadgeId($a_badge_id)
static exists($a_badge_id, $a_user_id)
static getInstance()
Constructor.
static getInstancesByType($a_type_unique_id)
Class ilBadgeManagementGUI.
initBadgeForm($a_mode, ilBadgeType $a_type, $a_type_unique_id)
setBadgeFormValues(ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
addBadge(ilPropertyFormGUI $a_form=null)
__construct($a_parent_ref_id, $a_parent_obj_id=null, $a_parent_obj_type=null)
Construct.
editBadge(ilPropertyFormGUI $a_form=null)
TableGUI class for badge listing.
TableGUI class for badge user listing.
Class ilBadge.
getImagePath($a_full_path=true)
static getExtendedTypeCaption(ilBadgeType $a_type)
getConfiguration()
This class represents a checkbox property in a property form.
Confirmation screen class.
Base class for ILIAS Exception handling.
This class represents an image file property in a property form.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
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 selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static addTooltip( $a_el_id, $a_text, $a_container="", $a_my="bottom center", $a_at="top center", $a_use_htmlspecialchars=true)
Adds a tooltip to an HTML element.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$valid
global $ilCtrl
Definition: ilias.php:18
Badge type gui interface.
Badge type interface.
$type
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46