ILIAS  release_7 Revision v7.30-3-g800a261c036
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 {
93 $ilCtrl = $this->ctrl;
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;
151 $ilCtrl = $this->ctrl;
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;
178 $ilCtrl = $this->ctrl;
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 {
268 $ilCtrl = $this->ctrl;
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 {
295 $ilCtrl = $this->ctrl;
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 $img_upload->setUseCache(false);
358 $form->addItem($img_upload);
359 }
360
361 $valid = new ilTextInputGUI($lng->txt("badge_valid"), "valid");
362 $form->addItem($valid);
363
364 $custom = $a_type->getConfigGUIInstance();
365 if ($custom &&
366 $custom instanceof ilBadgeTypeGUI) {
367 $custom->initConfigForm($form, $this->parent_ref_id);
368 }
369
370 // :TODO: valid date/period
371
372 if ($a_mode == "create") {
373 $form->addCommandButton("saveBadge", $lng->txt("save"));
374 } else {
375 $form->addCommandButton("updateBadge", $lng->txt("save"));
376 }
377 $form->addCommandButton("listBadges", $lng->txt("cancel"));
378
379 return $form;
380 }
381
382 protected function saveBadge()
383 {
384 $ilCtrl = $this->ctrl;
386
387 $type_id = $_REQUEST["type"];
388 if (!$type_id ||
389 !$this->hasWrite()) {
390 $ilCtrl->redirect($this, "listBadges");
391 }
392
393 $ilCtrl->setParameter($this, "type", $type_id);
394
395 $handler = ilBadgeHandler::getInstance();
396 $type = $handler->getTypeInstanceByUniqueId($type_id);
397 if (!$type) {
398 $ilCtrl->redirect($this, "listBadges");
399 }
400
401 $form = $this->initBadgeForm("create", $type, $type_id);
402 $custom = $type->getConfigGUIInstance();
403
404 if ($form->checkInput() &&
405 (!$custom || $custom->validateForm($form))) {
406 $badge = new ilBadge();
407 $badge->setParentId($this->parent_obj_id); // :TODO: ref_id?
408 $badge->setTypeId($type_id);
409 $badge->setActive($form->getInput("act"));
410 $badge->setTitle($form->getInput("title"));
411 $badge->setDescription($form->getInput("desc"));
412 $badge->setCriteria($form->getInput("crit"));
413 $badge->setValid($form->getInput("valid"));
414
415 if ($custom &&
416 $custom instanceof ilBadgeTypeGUI) {
417 $badge->setConfiguration($custom->getConfigFromForm($form));
418 }
419
420 $badge->create();
421
422 if ($form->getInput("img_mode") == "up") {
423 $badge->uploadImage($_FILES["img"]);
424 } else {
425 $tmpl = new ilBadgeImageTemplate($form->getInput("tmpl"));
426 $badge->importImage($tmpl->getImage(), $tmpl->getImagePath());
427 }
428
429 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
430 $ilCtrl->redirect($this, "listBadges");
431 }
432
433 $form->setValuesByPost();
434 $this->addBadge($form);
435 }
436
437 protected function editBadge(ilPropertyFormGUI $a_form = null)
438 {
439 $ilCtrl = $this->ctrl;
442
443 $badge_id = $_REQUEST["bid"];
444 if (!$badge_id ||
445 !$this->hasWrite()) {
446 $ilCtrl->redirect($this, "listBadges");
447 }
448
449 $ilCtrl->setParameter($this, "bid", $badge_id);
450
451 $badge = new ilBadge($badge_id);
452
453 $static_cnt = ilBadgeHandler::getInstance()->countStaticBadgeInstances($badge);
454 if ($static_cnt) {
455 ilUtil::sendInfo(sprintf($lng->txt("badge_edit_with_published"), $static_cnt));
456 }
457
458 if (!$a_form) {
459 $type = $badge->getTypeInstance();
460 $a_form = $this->initBadgeForm("edit", $type, $badge->getTypeId());
461 $this->setBadgeFormValues($a_form, $badge, $type);
462 }
463
464 $tpl->setContent($a_form->getHTML());
465 }
466
467 protected function setBadgeFormValues(ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
468 {
469 $a_form->getItemByPostVar("act")->setChecked($a_badge->isActive());
470 $a_form->getItemByPostVar("title")->setValue($a_badge->getTitle());
471 $a_form->getItemByPostVar("desc")->setValue($a_badge->getDescription());
472 $a_form->getItemByPostVar("crit")->setValue($a_badge->getCriteria());
473 $a_form->getItemByPostVar("img")->setValue($a_badge->getImage());
474 $a_form->getItemByPostVar("img")->setImage($a_badge->getImagePath());
475 $a_form->getItemByPostVar("valid")->setValue($a_badge->getValid());
476
477 $custom = $a_type->getConfigGUIInstance();
478 if ($custom &&
479 $custom instanceof ilBadgeTypeGUI) {
480 $custom->importConfigToForm($a_form, $a_badge->getConfiguration());
481 }
482 }
483
484 protected function updateBadge()
485 {
486 $ilCtrl = $this->ctrl;
488
489 $badge_id = $_REQUEST["bid"];
490 if (!$badge_id ||
491 !$this->hasWrite()) {
492 $ilCtrl->redirect($this, "listBadges");
493 }
494
495 $ilCtrl->setParameter($this, "bid", $badge_id);
496
497 $badge = new ilBadge($badge_id);
498 $type = $badge->getTypeInstance();
499 $custom = $type->getConfigGUIInstance();
500 if ($custom &&
501 !($custom instanceof ilBadgeTypeGUI)) {
502 $custom = null;
503 }
504 $form = $this->initBadgeForm("update", $type, $badge->getTypeId());
505 if ($form->checkInput() &&
506 (!$custom || $custom->validateForm($form))) {
507 $badge->setActive($form->getInput("act"));
508 $badge->setTitle($form->getInput("title"));
509 $badge->setDescription($form->getInput("desc"));
510 $badge->setCriteria($form->getInput("crit"));
511 $badge->setValid($form->getInput("valid"));
512
513 if ($custom) {
514 $badge->setConfiguration($custom->getConfigFromForm($form));
515 }
516
517 $badge->update();
518
519 $badge->uploadImage($_FILES["img"]);
520
521 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
522 $ilCtrl->redirect($this, "listBadges");
523 }
524
525 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
526 $form->setValuesByPost();
527 $this->editBadge($form);
528 }
529
530 protected function confirmDeleteBadges()
531 {
532 $ilCtrl = $this->ctrl;
535 $ilTabs = $this->tabs;
536
537 $badge_ids = $this->getBadgesFromMultiAction();
538
539 $ilTabs->clearTargets();
540 $ilTabs->setBackTarget(
541 $lng->txt("back"),
542 $ilCtrl->getLinkTarget($this, "listBadges")
543 );
544
545 $confirmation_gui = new ilConfirmationGUI();
546 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
547 $confirmation_gui->setHeaderText($lng->txt("badge_deletion_confirmation"));
548 $confirmation_gui->setCancel($lng->txt("cancel"), "listBadges");
549 $confirmation_gui->setConfirm($lng->txt("delete"), "deleteBadges");
550
551 foreach ($badge_ids as $badge_id) {
552 $badge = new ilBadge($badge_id);
553 $confirmation_gui->addItem("id[]", $badge_id, $badge->getTitle() .
554 " (" . sizeof(ilBadgeAssignment::getInstancesByBadgeId($badge_id)) . ")");
555 }
556
557 $tpl->setContent($confirmation_gui->getHTML());
558 }
559
560 protected function deleteBadges()
561 {
562 $ilCtrl = $this->ctrl;
564
565 $badge_ids = $this->getBadgesFromMultiAction();
566
567 foreach ($badge_ids as $badge_id) {
568 $badge = new ilBadge($badge_id);
569 $badge->delete();
570 }
571
572 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
573 $ilCtrl->redirect($this, "listBadges");
574 }
575
576
577 //
578 // badges multi action
579 //
580
581 protected function getBadgesFromMultiAction()
582 {
583 $ilCtrl = $this->ctrl;
584
585 $badge_ids = $_REQUEST["id"];
586 if (!$badge_ids ||
587 !$this->hasWrite()) {
588 $ilCtrl->redirect($this, "listBadges");
589 }
590
591 return $badge_ids;
592 }
593
594 protected function copyBadges()
595 {
596 $ilCtrl = $this->ctrl;
597
598 $badge_ids = $this->getBadgesFromMultiAction();
599
600 $_SESSION[self::CLIPBOARD_ID] = array_unique(
601 array_merge((array) $_SESSION[self::CLIPBOARD_ID], $badge_ids)
602 );
603
604 $ilCtrl->redirect($this, "listBadges");
605 }
606
607 protected function clearClipboard()
608 {
609 $ilCtrl = $this->ctrl;
610
611 unset($_SESSION[self::CLIPBOARD_ID]);
612 $ilCtrl->redirect($this, "listBadges");
613 }
614
615 protected function getValidBadgesFromClipboard()
616 {
617 $res = array();
618
619 $valid_types = array_keys(ilBadgeHandler::getInstance()->getAvailableTypesForObjType($this->parent_obj_type));
620
621 foreach ($_SESSION[self::CLIPBOARD_ID] as $badge_id) {
622 $badge = new ilBadge($badge_id);
623 if (in_array($badge->getTypeId(), $valid_types)) {
624 $res[] = $badge;
625 }
626 }
627
628 return $res;
629 }
630
631 protected function pasteBadges()
632 {
633 $ilCtrl = $this->ctrl;
634
635 if (!$this->hasWrite() ||
636 !is_array($_SESSION[self::CLIPBOARD_ID])) {
637 $ilCtrl->redirect($this, "listBadges");
638 }
639
640 foreach ($this->getValidBadgesFromClipboard() as $badge) {
641 $badge->copy($this->parent_obj_id);
642 }
643
644 $ilCtrl->redirect($this, "listBadges");
645 }
646
647 protected function toggleBadges($a_status)
648 {
649 $ilCtrl = $this->ctrl;
651
652 $badge_ids = $this->getBadgesFromMultiAction();
653
654 foreach ($badge_ids as $badge_id) {
655 $badge = new ilBadge($badge_id);
656 $badge->setActive($a_status);
657 $badge->update();
658 }
659
660 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
661 $ilCtrl->redirect($this, "listBadges");
662 }
663
664 protected function activateBadges()
665 {
666 $this->toggleBadges(true);
667 }
668
669 protected function deactivateBadges()
670 {
671 $this->toggleBadges(false);
672 }
673
674
675 //
676 // users
677 //
678
679 protected function listUsers()
680 {
682 $ilCtrl = $this->ctrl;
683 $ilToolbar = $this->toolbar;
685
686 $this->setTabs("users");
687
688 if ($this->hasWrite()) {
689 $manual = ilBadgeHandler::getInstance()->getAvailableManualBadges($this->parent_obj_id, $this->parent_obj_type);
690 if (sizeof($manual)) {
691 $drop = new ilSelectInputGUI($lng->txt("badge_badge"), "bid");
692 $drop->setOptions($manual);
693 $ilToolbar->addInputItem($drop, true);
694
695 $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "awardBadgeUserSelection"));
696 $ilToolbar->addFormButton($lng->txt("badge_award_badge"), "awardBadgeUserSelection");
697 }
698 }
699
700 $tbl = new ilBadgeUserTableGUI($this, "listUsers", $this->parent_ref_id);
701 $tpl->setContent($tbl->getHTML());
702 }
703
704 protected function applyListUsers()
705 {
706 $tbl = new ilBadgeUserTableGUI($this, "listUsers", $this->parent_ref_id);
707 $tbl->resetOffset();
708 $tbl->writeFilterToSession();
709 $this->listUsers();
710 }
711
712 protected function resetListUsers()
713 {
714 $tbl = new ilBadgeUserTableGUI($this, "listUsers", $this->parent_ref_id);
715 $tbl->resetOffset();
716 $tbl->resetFilter();
717 $this->listUsers();
718 }
719
720 protected function awardBadgeUserSelection()
721 {
722 $ilCtrl = $this->ctrl;
724 $ilTabs = $this->tabs;
726
727 $bid = (int) $_REQUEST["bid"];
728 if (!$bid ||
729 !$this->hasWrite()) {
730 $ilCtrl->redirect($this, "listUsers");
731 }
732
733 $manual = array_keys(ilBadgeHandler::getInstance()->getAvailableManualBadges($this->parent_obj_id, $this->parent_obj_type));
734 if (!in_array($bid, $manual)) {
735 $ilCtrl->redirect($this, "listUsers");
736 }
737
738 $back_target = "listUsers";
739 if ($_REQUEST["tgt"] == "bdgl") {
740 $ilCtrl->saveParameter($this, "tgt");
741 $back_target = "listBadges";
742 }
743
744 $ilTabs->clearTargets();
745 $ilTabs->setBackTarget(
746 $lng->txt("back"),
747 $ilCtrl->getLinkTarget($this, $back_target)
748 );
749
750 $ilCtrl->setParameter($this, "bid", $bid);
751
752 $badge = new ilBadge($bid);
753
754 $tbl = new ilBadgeUserTableGUI($this, "awardBadgeUserSelection", $this->parent_ref_id, $badge);
755 $tpl->setContent($tbl->getHTML());
756 }
757
758 protected function applyAwardBadgeUserSelection()
759 {
760 $tbl = new ilBadgeUserTableGUI($this, "awardBadgeUserSelection", $this->parent_ref_id);
761 $tbl->resetOffset();
762 $tbl->writeFilterToSession();
764 }
765
766 protected function resetAwardBadgeUserSelection()
767 {
768 $tbl = new ilBadgeUserTableGUI($this, "awardBadgeUserSelection", $this->parent_ref_id);
769 $tbl->resetOffset();
770 $tbl->resetFilter();
772 }
773
774 protected function assignBadge()
775 {
776 $ilCtrl = $this->ctrl;
779
780 $user_ids = $_POST["id"];
781 $badge_id = $_REQUEST["bid"];
782 if (!$user_ids ||
783 !$badge_id ||
784 !$this->hasWrite()) {
785 $ilCtrl->redirect($this, "listUsers");
786 }
787
788 $new_badges = array();
789 foreach ($user_ids as $user_id) {
790 if (!ilBadgeAssignment::exists($badge_id, $user_id)) {
791 $ass = new ilBadgeAssignment($badge_id, $user_id);
792 $ass->setAwardedBy($ilUser->getId());
793 $ass->store();
794
795 $new_badges[$user_id][] = $badge_id;
796 }
797 }
798
799 ilBadgeHandler::getInstance()->sendNotification($new_badges, $this->parent_ref_id);
800
801 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
802 $ilCtrl->redirect($this, "listUsers");
803 }
804
805 protected function confirmDeassignBadge()
806 {
807 $ilCtrl = $this->ctrl;
810 $ilTabs = $this->tabs;
811
812 $user_ids = $_POST["id"];
813 $badge_id = $_REQUEST["bid"];
814 if (!$user_ids ||
815 !$badge_id ||
816 !$this->hasWrite()) {
817 $ilCtrl->redirect($this, "listUsers");
818 }
819
820 $ilTabs->clearTargets();
821 $ilTabs->setBackTarget(
822 $lng->txt("back"),
823 $ilCtrl->getLinkTarget($this, "listUsers")
824 );
825
826 $badge = new ilBadge($badge_id);
827
828 $ilCtrl->setParameter($this, "bid", $badge->getId());
829
830 $confirmation_gui = new ilConfirmationGUI();
831 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
832 $confirmation_gui->setHeaderText(sprintf($lng->txt("badge_assignment_deletion_confirmation"), $badge->getTitle()));
833 $confirmation_gui->setCancel($lng->txt("cancel"), "listUsers");
834 $confirmation_gui->setConfirm($lng->txt("delete"), "deassignBadge");
835
836 $assigned_users = ilBadgeAssignment::getAssignedUsers($badge->getId());
837
838 foreach ($user_ids as $user_id) {
839 if (in_array($user_id, $assigned_users)) {
840 $confirmation_gui->addItem(
841 "id[]",
842 $user_id,
843 ilUserUtil::getNamePresentation($user_id, false, false, "", true)
844 );
845 }
846 }
847
848 $tpl->setContent($confirmation_gui->getHTML());
849 }
850
851 protected function deassignBadge()
852 {
853 $ilCtrl = $this->ctrl;
855
856 $user_ids = $_POST["id"];
857 $badge_id = $_REQUEST["bid"];
858 if (!$user_ids ||
859 !$badge_id ||
860 !$this->hasWrite()) {
861 $ilCtrl->redirect($this, "listUsers");
862 }
863
864 foreach ($user_ids as $user_id) {
865 $ass = new ilBadgeAssignment($badge_id, $user_id);
866 $ass->delete();
867 }
868
869 ilUtil::sendSuccess($lng->txt("settings_saved"), true);
870 $ilCtrl->redirect($this, "listUsers");
871 }
872}
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
Badge type gui interface.
Badge type interface.
getCaption()
Get caption.
getConfigGUIInstance()
Get GUI config instance.
$type
foreach($_POST as $key=> $value) $res