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