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