ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilBadgeManagementGUI Class Reference

ilBadgeManagementGUI: ilPropertyFormGUI More...

+ Inheritance diagram for ilBadgeManagementGUI:
+ Collaboration diagram for ilBadgeManagementGUI:

Public Member Functions

 __construct (private readonly int $parent_ref_id, int $a_parent_obj_id=null, string $a_parent_obj_type=null)
 
 executeCommand ()
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 

Data Fields

const TABLE_ALL_OBJECTS_ACTION = 'ALL_OBJECTS'
 

Protected Member Functions

 setTabs (string $a_active)
 
 hasWrite ()
 
 listBadges ()
 
 addBadge (ilPropertyFormGUI $a_form=null)
 
 initBadgeForm (string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
 
 saveBadge ()
 
 editBadge (ilPropertyFormGUI $a_form=null)
 
 setBadgeFormValues (ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
 
 updateBadge ()
 
 confirmDeleteBadges ()
 
 deleteBadges ()
 
 getBadgesFromMultiAction ()
 
 copyBadges ()
 
 clearClipboard ()
 
 getValidBadgesFromClipboard ()
 
 pasteBadges ()
 
 toggleBadges (bool $a_status)
 
 activateBadges ()
 
 deactivateBadges ()
 
 listUsers ()
 
 awardBadgeUserSelection ()
 
 assignBadge ()
 
 confirmDeassignBadge ()
 
 deassignBadge ()
 
 cloneBadgeTemplate (ilBadge $badge, ?ResourceIdentification $rid)
 
 removeResourceStorageImage (ilBadge $badge)
 

Private Member Functions

 splitBadgeAndUserIdsFromString (array $splittable_user_ids)
 
 selectBadgeForAwardingOrRevoking ()
 

Private Attributes

ilBadgeGUIRequest $request
 
ilBadgeManagementSessionRepository $session_repo
 
ilLanguage $lng
 
ilCtrl $ctrl
 
ilTabsGUI $tabs
 
ilAccessHandler $access
 
ilToolbarGUI $toolbar
 
ilGlobalTemplateInterface $tpl
 
ilObjUser $user
 
ILIAS UI Factory $ui_factory
 
int $parent_obj_id
 
string $parent_obj_type
 
ilBadgeImage $badge_image_service = null
 
Services $resource_storage
 
FileUpload $upload_service
 
ilBadgePictureDefinition $flavour_definition = null
 
ILIAS HTTP Services $http
 
Factory $refinery
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBadgeManagementGUI::__construct ( private readonly int  $parent_ref_id,
int  $a_parent_obj_id = null,
string  $a_parent_obj_type = null 
)

Definition at line 56 of file class.ilBadgeManagementGUI.php.

References $DIC, ilObject\_lookupObjId(), ilObject\_lookupType(), ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ilBadgeHandler\getInstance(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ilLanguage\loadLanguageModule(), ILIAS\Repository\refinery(), ILIAS\Repository\tabs(), ILIAS\Repository\toolbar(), and ILIAS\Repository\user().

60  {
61  global $DIC;
62 
63  $this->lng = $DIC->language();
64  $this->ctrl = $DIC->ctrl();
65  $this->tabs = $DIC->tabs();
66  $this->access = $DIC->access();
67  $this->http = $DIC->http();
68  $this->refinery = $DIC->refinery();
69  $this->toolbar = $DIC->toolbar();
70  $this->ui_factory = $DIC->ui()->factory();
71  $this->resource_storage = $DIC->resourceStorage();
72  $this->upload_service = $DIC->upload();
73  $this->tpl = $DIC->ui()->mainTemplate();
74  $this->user = $DIC->user();
75  $lng = $DIC->language();
76  $this->parent_obj_id = $a_parent_obj_id
77  ?: ilObject::_lookupObjId($parent_ref_id);
78  $this->parent_obj_type = $a_parent_obj_type
79  ?: ilObject::_lookupType($this->parent_obj_id);
80 
81  if (!ilBadgeHandler::getInstance()->isObjectActive($this->parent_obj_id)) {
82  throw new ilException('inactive object');
83  }
84 
85  $lng->loadLanguageModule('badge');
86 
87  $this->request = new ilBadgeGUIRequest(
88  $DIC->http(),
89  $DIC->refinery()
90  );
91 
92  $this->session_repo = new ilBadgeManagementSessionRepository();
93  $this->badge_image_service = new ilBadgeImage(
94  $DIC->resourceStorage(),
95  $DIC->upload(),
96  $DIC->ui()->mainTemplate()
97  );
98  $this->flavour_definition = new ilBadgePictureDefinition();
99  }
loadLanguageModule(string $a_module)
Load language module.
static _lookupObjId(int $ref_id)
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:25
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

Member Function Documentation

◆ activateBadges()

ilBadgeManagementGUI::activateBadges ( )
protected

Definition at line 793 of file class.ilBadgeManagementGUI.php.

References toggleBadges().

793  : void
794  {
795  $this->toggleBadges(true);
796  }
+ Here is the call graph for this function:

◆ addBadge()

ilBadgeManagementGUI::addBadge ( ilPropertyFormGUI  $a_form = null)
protected

Definition at line 330 of file class.ilBadgeManagementGUI.php.

References $ctrl, $handler, $tpl, ilBadgeHandler\getInstance(), hasWrite(), initBadgeForm(), and ilGlobalTemplateInterface\setContent().

Referenced by saveBadge().

330  : void
331  {
332  $ilCtrl = $this->ctrl;
333  $tpl = $this->tpl;
334 
335  $type_id = $this->request->getType();
336  if (!$type_id ||
337  !$this->hasWrite()) {
338  $ilCtrl->redirect($this, 'listBadges');
339  }
340 
341  $ilCtrl->setParameter($this, 'type', $type_id);
342 
344  $type = $handler->getTypeInstanceByUniqueId($type_id);
345  if (!$type) {
346  $ilCtrl->redirect($this, 'listBadges');
347  }
348 
349  if (!$a_form) {
350  $a_form = $this->initBadgeForm('create', $type, $type_id);
351  }
352 
353  $tpl->setContent($a_form->getHTML());
354  }
initBadgeForm(string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
setContent(string $a_html)
Sets content for standard template.
ilGlobalTemplateInterface $tpl
$handler
Definition: oai.php:14
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assignBadge()

ilBadgeManagementGUI::assignBadge ( )
protected

Definition at line 896 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $user, $user_id, ilBadgeAssignment\exists(), ilBadgeHandler\getInstance(), hasWrite(), splitBadgeAndUserIdsFromString(), and ilLanguage\txt().

896  : void
897  {
898  $ilCtrl = $this->ctrl;
899  $ilUser = $this->user;
900  $lng = $this->lng;
901 
902  $splittable_user_ids = $this->request->getBadgeAssignableUsers();
903  [$user_ids, $badge_id] = $this->splitBadgeAndUserIdsFromString($splittable_user_ids);
904 
905  if (!$user_ids ||
906  !$badge_id ||
907  !$this->hasWrite()) {
908  $ilCtrl->redirect($this, 'listUsers');
909  }
910 
911  $new_badges = [];
912  foreach ($user_ids as $user_id) {
913  if (!ilBadgeAssignment::exists($badge_id, $user_id)) {
914  $ass = new ilBadgeAssignment($badge_id, $user_id);
915  $ass->setAwardedBy($ilUser->getId());
916  $ass->store();
917 
918  $new_badges[$user_id][] = $badge_id;
919  }
920  }
921 
922  ilBadgeHandler::getInstance()->sendNotification($new_badges, $this->parent_ref_id);
923 
924  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
925  $ilCtrl->redirect($this, 'listUsers');
926  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
splitBadgeAndUserIdsFromString(array $splittable_user_ids)
static exists(int $a_badge_id, int $a_user_id)
+ Here is the call graph for this function:

◆ awardBadgeUserSelection()

ilBadgeManagementGUI::awardBadgeUserSelection ( )
protected

Definition at line 847 of file class.ilBadgeManagementGUI.php.

References ILIAS\Repository\ctrl(), ilBadgeHandler\getInstance(), hasWrite(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\tabs().

847  : void
848  {
849  $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
850  $bid = null;
851 
852  if ($badge_ids === []) {
853  if ($this->http->wrapper()->post()->has('bid')) {
854  $bid = $this->http->wrapper()->post()->retrieve('bid', $this->refinery->kindlyTo()->int());
855  } elseif ($this->http->wrapper()->query()->has('bid')) {
856  $bid = $this->http->wrapper()->query()->retrieve('bid', $this->refinery->kindlyTo()->int());
857  }
858  } elseif (count($badge_ids) === 1) {
859  $bid = (int) $badge_ids[0];
860  }
861 
862  if (!$bid ||
863  !$this->hasWrite()) {
864  $this->ctrl->redirect($this, 'listUsers');
865  }
866 
867  $manual = array_keys(
868  ilBadgeHandler::getInstance()->getAvailableManualBadges($this->parent_obj_id, $this->parent_obj_type)
869  );
870 
871  if (!in_array($bid, $manual, true)) {
872  $this->ctrl->redirect($this, 'listUsers');
873  }
874 
875  $back_target = 'listUsers';
876  if ($this->request->getTgt() === 'bdgl') {
877  $this->ctrl->saveParameter($this, 'tgt');
878  $back_target = 'listBadges';
879  }
880 
881  $this->tabs->clearTargets();
882  $this->tabs->setBackTarget(
883  $this->lng->txt('back'),
884  $this->ctrl->getLinkTarget($this, $back_target)
885  );
886 
887  $this->ctrl->setParameter($this, 'bid', $bid);
888 
889  $badge = new ilBadge($bid);
890 
891  $tbl = new ilBadgeUserTableGUI($this->parent_ref_id, $badge);
892  $this->ctrl->setParameter($this, 'returnCmd', __FUNCTION__);
893  $tbl->renderTable(ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, 'action'));
894  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ clearClipboard()

ilBadgeManagementGUI::clearClipboard ( )
protected

Definition at line 721 of file class.ilBadgeManagementGUI.php.

References $ctrl, and ilCtrl\redirect().

721  : void
722  {
723  $ilCtrl = $this->ctrl;
724 
725  $this->session_repo->clear();
726  $ilCtrl->redirect($this, 'listBadges');
727  }
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
+ Here is the call graph for this function:

◆ cloneBadgeTemplate()

ilBadgeManagementGUI::cloneBadgeTemplate ( ilBadge  $badge,
?ResourceIdentification  $rid 
)
protected
Exceptions
Exception

Definition at line 1008 of file class.ilBadgeManagementGUI.php.

References ilBadge\setImageRid(), and ilBadge\update().

Referenced by saveBadge(), and updateBadge().

1008  : void
1009  {
1010  if ($rid !== null) {
1011  $new_rid = $this->badge_image_service->cloneBadgeImageByRid($rid);
1012  $badge->setImageRid($new_rid);
1013  $badge->update();
1014  }
1015  }
setImageRid(?string $image_rid)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ confirmDeassignBadge()

ilBadgeManagementGUI::confirmDeassignBadge ( )
protected

Definition at line 928 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $tabs, $tpl, $user_id, ilBadgeAssignment\getAssignedUsers(), ilUserUtil\getNamePresentation(), hasWrite(), ilGlobalTemplateInterface\setContent(), splitBadgeAndUserIdsFromString(), and ilLanguage\txt().

928  : void
929  {
930  $ilCtrl = $this->ctrl;
931  $lng = $this->lng;
932  $tpl = $this->tpl;
933  $ilTabs = $this->tabs;
934 
935  $splittable_user_ids = $this->request->getMultiActionBadgeIdsFromUrl();
936  [$user_ids, $badge_id] = $this->splitBadgeAndUserIdsFromString($splittable_user_ids);
937 
938  if (!$user_ids ||
939  !$badge_id ||
940  !$this->hasWrite()) {
941  $ilCtrl->redirect($this, 'listUsers');
942  }
943 
944  $ilTabs->clearTargets();
945  $ilTabs->setBackTarget(
946  $lng->txt('back'),
947  $ilCtrl->getLinkTarget($this, 'listUsers')
948  );
949 
950  $badge = new ilBadge($badge_id);
951 
952  $ilCtrl->setParameter($this, 'bid', $badge->getId());
953 
954  $confirmation_gui = new ilConfirmationGUI();
955  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
956  $confirmation_gui->setHeaderText(
957  sprintf($lng->txt('badge_assignment_deletion_confirmation'), $badge->getTitle())
958  );
959  $confirmation_gui->setCancel($lng->txt('cancel'), 'listUsers');
960  $confirmation_gui->setConfirm($lng->txt('badge_remove_badge'), 'deassignBadge');
961 
962  $assigned_users = ilBadgeAssignment::getAssignedUsers($badge->getId());
963 
964  foreach ($user_ids as $user_id) {
965  if (in_array($user_id, $assigned_users, true)) {
966  $confirmation_gui->addItem(
967  "id[$user_id]",
968  (string) $badge_id,
969  ilUserUtil::getNamePresentation($user_id, false, false, '', true)
970  );
971  }
972  }
973 
974  $tpl->setContent($confirmation_gui->getHTML());
975  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getAssignedUsers(int $a_badge_id)
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path='ilpublicuserprofilegui')
Default behaviour is:
setContent(string $a_html)
Sets content for standard template.
ilGlobalTemplateInterface $tpl
splitBadgeAndUserIdsFromString(array $splittable_user_ids)
+ Here is the call graph for this function:

◆ confirmDeleteBadges()

ilBadgeManagementGUI::confirmDeleteBadges ( )
protected

Definition at line 625 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $tabs, $tpl, ilTabsGUI\clearTargets(), ilBadgeAssignment\getInstancesByBadgeId(), ilBadge\getInstancesByParentId(), ilGlobalTemplateInterface\setContent(), and ilLanguage\txt().

625  : void
626  {
627  $ilCtrl = $this->ctrl;
628  $lng = $this->lng;
629  $tpl = $this->tpl;
630  $ilTabs = $this->tabs;
631 
632  $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
633  if ($badge_ids === ['ALL_OBJECTS']) {
634  $badge_ids = [];
635  foreach (ilBadge::getInstancesByParentId($this->parent_obj_id) as $badge) {
636  $badge_ids[] = $badge->getId();
637  }
638  }
639 
640  $ilTabs->clearTargets();
641  $ilTabs->setBackTarget(
642  $lng->txt('back'),
643  $ilCtrl->getLinkTarget($this, 'listBadges')
644  );
645 
646  $confirmation_gui = new ilConfirmationGUI();
647  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
648  $confirmation_gui->setHeaderText($lng->txt('badge_deletion_confirmation'));
649  $confirmation_gui->setCancel($lng->txt('cancel'), 'listBadges');
650  $confirmation_gui->setConfirm($lng->txt('delete'), 'deleteBadges');
651 
652  foreach ($badge_ids as $badge_id) {
653  $badge = new ilBadge((int) $badge_id);
654  $confirmation_gui->addItem(
655  'id[]',
656  (string) $badge_id,
657  $badge->getTitle() .
658  ' (' . count(ilBadgeAssignment::getInstancesByBadgeId($badge_id)) . ')'
659  );
660  }
661 
662  $tpl->setContent($confirmation_gui->getHTML());
663  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setContent(string $a_html)
Sets content for standard template.
static getInstancesByBadgeId(int $a_badge_id)
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
ilGlobalTemplateInterface $tpl
clearTargets()
clear all targets
+ Here is the call graph for this function:

◆ copyBadges()

ilBadgeManagementGUI::copyBadges ( )
protected

Definition at line 706 of file class.ilBadgeManagementGUI.php.

References $ctrl, and getBadgesFromMultiAction().

706  : void
707  {
708  $ilCtrl = $this->ctrl;
709 
710  $badge_ids = $this->getBadgesFromMultiAction();
711 
712  $clip_ids = $this->session_repo->getBadgeIds();
713  $clip_ids = array_unique(
714  array_merge($clip_ids, $badge_ids)
715  );
716  $this->session_repo->setBadgeIds(array_map(intval(...), $clip_ids));
717 
718  $ilCtrl->redirect($this, 'listBadges');
719  }
+ Here is the call graph for this function:

◆ deactivateBadges()

ilBadgeManagementGUI::deactivateBadges ( )
protected

Definition at line 798 of file class.ilBadgeManagementGUI.php.

References toggleBadges().

798  : void
799  {
800  $this->toggleBadges(false);
801  }
+ Here is the call graph for this function:

◆ deassignBadge()

ilBadgeManagementGUI::deassignBadge ( )
protected

Definition at line 977 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $user_id, hasWrite(), and ilLanguage\txt().

977  : void
978  {
979  $ilCtrl = $this->ctrl;
980  $lng = $this->lng;
981 
982  $post_values = $this->request->getIds();
983  $user_ids = [];
984  $badge_id = null;
985  foreach ($post_values as $usr_id => $found_badge_id) {
986  $badge_id = $found_badge_id;
987  $user_ids[] = $usr_id;
988  }
989 
990  if (!$user_ids ||
991  !$badge_id ||
992  !$this->hasWrite()) {
993  $ilCtrl->redirect($this, 'listUsers');
994  }
995 
996  foreach ($user_ids as $user_id) {
997  $ass = new ilBadgeAssignment((int) $badge_id, (int) $user_id);
998  $ass->delete();
999  }
1000 
1001  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
1002  $ilCtrl->redirect($this, 'listUsers');
1003  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
+ Here is the call graph for this function:

◆ deleteBadges()

ilBadgeManagementGUI::deleteBadges ( )
protected

Definition at line 665 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, and ilLanguage\txt().

665  : void
666  {
667  $ilCtrl = $this->ctrl;
668  $lng = $this->lng;
669 
670  $badge_ids = $this->request->getIds();
671 
672  if (count($badge_ids) > 0) {
673  foreach ($badge_ids as $badge_id) {
674  $badge = new ilBadge((int) $badge_id);
675  $badge->delete();
676  }
677  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
678  } else {
679  $this->tpl->setOnScreenMessage('failure', $lng->txt('badge_select_one'), true);
680  }
681 
682  $ilCtrl->redirect($this, 'listBadges');
683  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
+ Here is the call graph for this function:

◆ editBadge()

ilBadgeManagementGUI::editBadge ( ilPropertyFormGUI  $a_form = null)
protected

Definition at line 511 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $tpl, ilBadgeHandler\getInstance(), hasWrite(), initBadgeForm(), setBadgeFormValues(), ilGlobalTemplateInterface\setContent(), and ilLanguage\txt().

Referenced by updateBadge().

511  : void
512  {
513  $ilCtrl = $this->ctrl;
514  $tpl = $this->tpl;
515  $lng = $this->lng;
516 
517  $badge_id = $this->request->getBadgeIdFromUrl();
518  if (!$badge_id ||
519  !$this->hasWrite()) {
520  $ilCtrl->redirect($this, 'listBadges');
521  }
522 
523  $ilCtrl->setParameter($this, 'bid', $badge_id);
524 
525  $badge = new ilBadge($badge_id);
526 
527  $static_cnt = ilBadgeHandler::getInstance()->countStaticBadgeInstances($badge);
528  if ($static_cnt) {
529  $this->tpl->setOnScreenMessage('info', sprintf($lng->txt('badge_edit_with_published'), $static_cnt));
530  }
531 
532  if (!$a_form) {
533  $type = $badge->getTypeInstance();
534  $a_form = $this->initBadgeForm('edit', $type, $badge->getTypeId());
535  $this->setBadgeFormValues($a_form, $badge, $type);
536  }
537 
538  $tpl->setContent($a_form->getHTML());
539  }
initBadgeForm(string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setBadgeFormValues(ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
setContent(string $a_html)
Sets content for standard template.
ilGlobalTemplateInterface $tpl
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilBadgeManagementGUI::executeCommand ( )

Definition at line 145 of file class.ilBadgeManagementGUI.php.

References $ctrl, $DIC, $handler, $id, ilBadgeHandler\getInstance(), ilCtrl\getNextClass(), ilBadge\getTypeId(), initBadgeForm(), and setBadgeFormValues().

145  : void
146  {
147  $ilCtrl = $this->ctrl;
148 
149  $next_class = $ilCtrl->getNextClass($this);
150  $cmd = $ilCtrl->getCmd('listBadges');
151 
152  switch ($next_class) {
153  case 'ilpropertyformgui':
154  // ajax - update
155  if ($this->request->getBadgeId()) {
156  $badge = new ilBadge($this->request->getBadgeId());
157  $type = $badge->getTypeInstance();
158  $form = $this->initBadgeForm('edit', $type, $badge->getTypeId());
159  $this->setBadgeFormValues($form, $badge, $type);
160  } // ajax- create
161  else {
162  $type_id = $this->request->getType();
163  $ilCtrl->setParameter($this, 'type', $type_id);
165  $type = $handler->getTypeInstanceByUniqueId($type_id);
166  $form = $this->initBadgeForm('create', $type, $type_id);
167  }
168  $ilCtrl->forwardCommand($form);
169  break;
170 
171  default:
172  $render_default = true;
173  global $DIC;
174  $action_parameter_token = 'tid_id';
175  $parameter = 'tid_table_action';
176 
177  $query = $DIC->http()->wrapper()->query();
178  if ($query->has($action_parameter_token)) {
179  if ($query->has($action_parameter_token)) {
180  $id = $query->retrieve(
181  $action_parameter_token,
182  $DIC->refinery()->kindlyTo()->listOf($DIC->refinery()->kindlyTo()->string())
183  );
184  if (is_array($id)) {
185  $id = array_pop($id);
186  }
187  $DIC->ctrl()->setParameter($this, "tid", $id);
188  }
189  }
190 
191  $get = fn(string $key) => $query->has($key) ?
192  $query->retrieve($key, $DIC->refinery()->kindlyTo()->string()) :
193  '';
194 
195  $action = $get($parameter);
196  $return_cmd = $get('returnCmd');
197 
198  $actions = [
199  'badge_table_activate' => ['activateBadges', true],
200  'badge_table_deactivate' => ['deactivateBadges', true],
201  'badge_table_edit' => 'editBadge',
202  'badge_table_delete' => 'confirmDeleteBadges',
203  'award_revoke_badge' => 'awardBadgeUserSelection',
204  'revokeBadge' => 'confirmDeassignBadge',
205  'assignBadge' => 'assignBadge',
206  ];
207 
208  $entry = $actions[$action] ?? null;
209  if ($cmd !== 'action' || !$entry) {
210  $this->$cmd();
211  return;
212  }
213 
214  $entry = is_array($entry) ? $entry : [$entry, false];
215  $this->{$entry[0]}();
216  if ($entry[1] && in_array($return_cmd, ['awardBadgeUserSelection', 'listUsers', 'listUsers', 'listBadges'], true)) {
217  $this->$return_cmd();
218  }
219  break;
220  }
221  }
initBadgeForm(string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
setBadgeFormValues(ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
getNextClass($a_gui_class=null)
global $DIC
Definition: shib_login.php:25
$handler
Definition: oai.php:14
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the call graph for this function:

◆ getBadgesFromMultiAction()

ilBadgeManagementGUI::getBadgesFromMultiAction ( )
protected
Returns
int[]

Definition at line 693 of file class.ilBadgeManagementGUI.php.

References $ctrl, hasWrite(), and ilCtrl\redirect().

Referenced by copyBadges().

693  : array
694  {
695  $ilCtrl = $this->ctrl;
696 
697  $badge_ids = $this->request->getIds();
698  if (!$badge_ids ||
699  !$this->hasWrite()) {
700  $ilCtrl->redirect($this, 'listBadges');
701  }
702 
703  return $badge_ids;
704  }
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSafePostCommands()

ilBadgeManagementGUI::getSafePostCommands ( )

This method must return a list of safe POST commands.

Safe post commands returned by this method will no longer be CSRF protected and will NOT be appended by an ilCtrlToken.

Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 223 of file class.ilBadgeManagementGUI.php.

223  : array
224  {
225  return [];
226  }

◆ getUnsafeGetCommands()

ilBadgeManagementGUI::getUnsafeGetCommands ( )

This method must return a list of unsafe GET commands.

Unsafe get commands returned by this method will now be CSRF protected, which means an ilCtrlToken is appended each time a link-target is generated to the class implementing this interface with a command from that list.

Tokens will be validated in

See also
ilCtrlInterface::getCmd(), whereas the fallback command will be used if the CSRF validation fails.
Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 228 of file class.ilBadgeManagementGUI.php.

228  : array
229  {
230  return ['action'];
231  }

◆ getValidBadgesFromClipboard()

ilBadgeManagementGUI::getValidBadgesFromClipboard ( )
protected
Returns
ilBadge[]

Definition at line 732 of file class.ilBadgeManagementGUI.php.

References $res, and ilBadgeHandler\getInstance().

Referenced by listBadges(), and pasteBadges().

732  : array
733  {
734  $res = [];
735 
736  $valid_types = array_keys(ilBadgeHandler::getInstance()->getAvailableTypesForObjType($this->parent_obj_type));
737 
738  foreach ($this->session_repo->getBadgeIds() as $badge_id) {
739  $badge = new ilBadge($badge_id);
740  if (in_array($badge->getTypeId(), $valid_types, true)) {
741  $res[] = $badge;
742  }
743  }
744 
745  return $res;
746  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasWrite()

ilBadgeManagementGUI::hasWrite ( )
protected

Definition at line 254 of file class.ilBadgeManagementGUI.php.

References $access, and ilRBACAccessHandler\checkAccess().

Referenced by addBadge(), assignBadge(), awardBadgeUserSelection(), confirmDeassignBadge(), deassignBadge(), editBadge(), getBadgesFromMultiAction(), listBadges(), listUsers(), pasteBadges(), saveBadge(), and updateBadge().

254  : bool
255  {
256  $ilAccess = $this->access;
257  return $ilAccess->checkAccess('write', '', $this->parent_ref_id);
258  }
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance) ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initBadgeForm()

ilBadgeManagementGUI::initBadgeForm ( string  $a_mode,
ilBadgeType  $a_type,
string  $a_type_unique_id 
)
protected

Definition at line 356 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $valid, ilBadgeType\getCaption(), ilBadgeType\getConfigGUIInstance(), ilBadgeImageTemplate\getInstancesByType(), ilTextAreaInputGUI\setMaxNumOfChars(), ilFormPropertyGUI\setRequired(), ilFileInputGUI\setSuffixes(), and ilLanguage\txt().

Referenced by addBadge(), editBadge(), executeCommand(), saveBadge(), and updateBadge().

361  $lng = $this->lng;
362  $ilCtrl = $this->ctrl;
363 
364  $form = new ilPropertyFormGUI();
365  $form->setFormAction($ilCtrl->getFormAction($this, 'saveBadge'));
366  $form->setTitle($lng->txt('badge_badge') . ' "' . $a_type->getCaption() . '"');
367 
368  $active = new ilCheckboxInputGUI($lng->txt('active'), 'act');
369  $form->addItem($active);
370 
371  $title = new ilTextInputGUI($lng->txt('title'), 'title');
372  $title->setMaxLength(255);
373  $title->setRequired(true);
374  $form->addItem($title);
375 
376  $desc = new ilTextAreaInputGUI($lng->txt('description'), 'desc');
377  $desc->setMaxNumOfChars(4000);
378  $desc->setRequired(true);
379  $form->addItem($desc);
380 
381  $crit = new ilTextAreaInputGUI($lng->txt('badge_criteria'), 'crit');
382  $crit->setMaxNumOfChars(4000);
383  $crit->setRequired(true);
384  $form->addItem($crit);
385 
386  if ($a_mode === 'create') {
387  // upload
388 
389  $img_mode = new ilRadioGroupInputGUI($lng->txt('image'), 'img_mode');
390  $img_mode->setRequired(true);
391  $img_mode->setValue('tmpl');
392  $form->addItem($img_mode);
393 
394  $img_mode_tmpl = new ilRadioOption($lng->txt('badge_image_from_template'), 'tmpl');
395  $img_mode->addOption($img_mode_tmpl);
396 
397  $img_mode_up = new ilRadioOption($lng->txt('badge_image_from_upload'), 'up');
398  $img_mode->addOption($img_mode_up);
399 
400  $img_upload = new ilImageFileInputGUI($lng->txt('file'), 'img');
401  $img_upload->setRequired(true);
402  $img_upload->setSuffixes(['png', 'svg']);
403  $img_mode_up->addSubItem($img_upload);
404 
405  // templates
406 
407  $valid_templates = ilBadgeImageTemplate::getInstancesByType($a_type_unique_id);
408  if (count($valid_templates)) {
409  $options = [];
410  $options[''] = $lng->txt('please_select');
411  foreach ($valid_templates as $tmpl) {
412  $options[$tmpl->getId()] = $tmpl->getTitle();
413  }
414 
415  $tmpl = new ilSelectInputGUI($lng->txt('badge_image_template_form'), 'tmpl');
416  $tmpl->setRequired(true);
417  $tmpl->setOptions($options);
418  $img_mode_tmpl->addSubItem($tmpl);
419  } else {
420  // no templates, activate upload
421  $img_mode_tmpl->setDisabled(true);
422  $img_mode->setValue('up');
423  }
424  } else {
425  $img_upload = new ilImageFileInputGUI($lng->txt('image'), 'img');
426  $img_upload->setSuffixes(['png', 'svg']);
427  $img_upload->setAllowDeletion(false);
428  $img_upload->setUseCache(false);
429  $form->addItem($img_upload);
430  }
431 
432  $valid = new ilTextInputGUI($lng->txt('badge_valid'), 'valid');
433  $valid->setMaxLength(255);
434  $form->addItem($valid);
435 
436  $custom = $a_type->getConfigGUIInstance();
437  if ($custom instanceof ilBadgeTypeGUI) {
438  $custom->initConfigForm($form, $this->parent_ref_id);
439  }
440 
441  // :TODO: valid date/period
442 
443  if ($a_mode === 'create') {
444  $form->addCommandButton('saveBadge', $lng->txt('save'));
445  } else {
446  $form->addCommandButton('updateBadge', $lng->txt('save'));
447  }
448  $form->addCommandButton('listBadges', $lng->txt('cancel'));
449 
450  return $form;
451  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstancesByType(string $a_type_unique_id)
This class represents a selection list property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
$valid
getConfigGUIInstance()
Get GUI config instance.
setSuffixes(array $a_suffixes)
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRequired(bool $a_required)
This class represents an image file property in a property form.
This class represents a text area property in a property form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listBadges()

ilBadgeManagementGUI::listBadges ( )
protected

Definition at line 260 of file class.ilBadgeManagementGUI.php.

References $ctrl, $handler, $id, $lng, $toolbar, ILIAS\Repository\ctrl(), ilBadge\getExtendedTypeCaption(), ilBadgeHandler\getInstance(), getValidBadgesFromClipboard(), hasWrite(), ilLanguage\loadLanguageModule(), setTabs(), and ilLanguage\txt().

260  : void
261  {
262  $ilToolbar = $this->toolbar;
263  $lng = $this->lng;
264  $ilCtrl = $this->ctrl;
265 
266  $this->setTabs('badges');
267 
268  if ($this->hasWrite()) {
270  $valid_types = $handler->getAvailableTypesForObjType($this->parent_obj_type);
271  if ($valid_types) {
272  $options = [];
273  foreach ($valid_types as $id => $type) {
274  $ilCtrl->setParameter($this, 'type', $id);
275  $options[$id] = $this->ui_factory->link()->standard(
276  $this->parent_obj_type !== 'bdga' ? ilBadge::getExtendedTypeCaption($type) : $type->getCaption(),
277  $ilCtrl->getLinkTarget($this, 'addBadge')
278  );
279  $ilCtrl->setParameter($this, 'type', null);
280  }
281  asort($options);
282  $options = array_values($options);
283 
284  $ilToolbar->addComponent(
285  $this->ui_factory->dropdown()->standard($options)->withLabel($lng->txt('badge_create'))
286  );
287  } else {
288  $this->tpl->setOnScreenMessage('info', $lng->txt('badge_no_valid_types_for_obj'));
289  }
290 
291  $clip_ids = $this->session_repo->getBadgeIds();
292  if (count($clip_ids) > 0) {
293  if ($valid_types) {
294  $ilToolbar->addSeparator();
295  }
296 
297  $tt = [];
298  foreach ($this->getValidBadgesFromClipboard() as $badge) {
299  $tt[] = $badge->getTitle();
300  }
301  $ttid = 'bdgpst';
302 
303  $lng->loadLanguageModule('content');
304  $ilToolbar->addButton(
305  $lng->txt('cont_paste_from_clipboard') .
306  ' (' . count($tt) . ')',
307  $ilCtrl->getLinkTarget($this, 'pasteBadges'),
308  '',
309  null,
310  '',
311  $ttid
312  );
313  $ilToolbar->addButton(
314  $lng->txt('clear_clipboard'),
315  $ilCtrl->getLinkTarget($this, 'clearClipboard')
316  );
317  }
318  }
319 
320  $table = new ilBadgeTableGUI($this->parent_obj_id, $this->parent_obj_type, $this->hasWrite());
321  $this->ctrl->setParameter($this, 'returnCmd', __FUNCTION__);
322  $table->renderTable(ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, 'action'));
323  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
loadLanguageModule(string $a_module)
Load language module.
static getExtendedTypeCaption(ilBadgeType $a_type)
$handler
Definition: oai.php:14
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
+ Here is the call graph for this function:

◆ listUsers()

ilBadgeManagementGUI::listUsers ( )
protected

Definition at line 808 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $toolbar, $tpl, ILIAS\Repository\ctrl(), ilBadgeHandler\getInstance(), hasWrite(), ilSelectInputGUI\setOptions(), setTabs(), and ilLanguage\txt().

808  : void
809  {
810  $lng = $this->lng;
811  $ilCtrl = $this->ctrl;
812  $ilToolbar = $this->toolbar;
813  $tpl = $this->tpl;
814 
815  $this->setTabs('users');
816 
817  if ($this->hasWrite()) {
818  $manual = ilBadgeHandler::getInstance()->getAvailableManualBadges(
819  $this->parent_obj_id,
820  $this->parent_obj_type
821  );
822  if (count($manual)) {
823  $drop = new ilSelectInputGUI($lng->txt('badge_badge'), 'bid');
824  $drop->setOptions($manual);
825  $ilToolbar->addInputItem($drop, true);
826 
827  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, 'selectBadgeForAwardingOrRevoking'));
828  $ilToolbar->addFormButton($lng->txt('badge_award_badge'), 'selectBadgeForAwardingOrRevoking');
829  }
830  }
831 
832  $tbl = new ilBadgeUserTableGUI($this->parent_ref_id);
833  $this->ctrl->setParameter($this, 'returnCmd', __FUNCTION__);
834  $tbl->renderTable(ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, 'action'));
835  }
This class represents a selection list property in a property form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setOptions(array $a_options)
ilGlobalTemplateInterface $tpl
+ Here is the call graph for this function:

◆ pasteBadges()

ilBadgeManagementGUI::pasteBadges ( )
protected

Definition at line 748 of file class.ilBadgeManagementGUI.php.

References $ctrl, getValidBadgesFromClipboard(), hasWrite(), ILIAS\Repository\lng(), and ilCtrl\redirect().

748  : void
749  {
750  $ilCtrl = $this->ctrl;
751 
752  $clip_ids = $this->session_repo->getBadgeIds();
753  if (!$this->hasWrite() || count($clip_ids) === 0) {
754  $ilCtrl->redirect($this, 'listBadges');
755  }
756 
757  $copy_suffix = $this->lng->txt("copy_of_suffix");
758  foreach ($this->getValidBadgesFromClipboard() as $badge) {
759  $badge->copy($this->parent_obj_id, $copy_suffix);
760  }
761 
762  $ilCtrl->redirect($this, 'listBadges');
763  }
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
+ Here is the call graph for this function:

◆ removeResourceStorageImage()

ilBadgeManagementGUI::removeResourceStorageImage ( ilBadge  $badge)
protected

Definition at line 1017 of file class.ilBadgeManagementGUI.php.

References ilBadge\getImageRid().

Referenced by updateBadge().

1017  : void
1018  {
1019  if ($badge->getImageRid() !== '') {
1020  $this->resource_storage->manage()->remove(
1021  new ResourceIdentification($badge->getImageRid()),
1023  );
1024  }
1025  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveBadge()

ilBadgeManagementGUI::saveBadge ( )
protected
Exceptions
ilCtrlException
IllegalStateException

Definition at line 457 of file class.ilBadgeManagementGUI.php.

References $ctrl, $handler, $lng, addBadge(), cloneBadgeTemplate(), ilBadgeHandler\getInstance(), hasWrite(), initBadgeForm(), and ilLanguage\txt().

457  : void
458  {
459  $ilCtrl = $this->ctrl;
460  $lng = $this->lng;
461 
462  $type_id = $this->request->getType();
463  if (!$type_id ||
464  !$this->hasWrite()) {
465  $ilCtrl->redirect($this, 'listBadges');
466  }
467 
468  $ilCtrl->setParameter($this, 'type', $type_id);
469 
471  $type = $handler->getTypeInstanceByUniqueId($type_id);
472  if (!$type) {
473  $ilCtrl->redirect($this, 'listBadges');
474  }
475 
476  $form = $this->initBadgeForm('create', $type, $type_id);
477  $custom = $type->getConfigGUIInstance();
478 
479  if ($form->checkInput() &&
480  (!$custom || $custom->validateForm($form))) {
481  $badge = new ilBadge();
482  $badge->setParentId($this->parent_obj_id); // :TODO: ref_id?
483  $badge->setTypeId($type_id);
484  $badge->setActive($form->getInput('act'));
485  $badge->setTitle($form->getInput('title'));
486  $badge->setDescription($form->getInput('desc'));
487  $badge->setCriteria($form->getInput('crit'));
488  $badge->setValid($form->getInput('valid'));
489 
490  if ($custom instanceof ilBadgeTypeGUI) {
491  $badge->setConfiguration($custom->getConfigFromForm($form));
492  }
493 
494  $badge->create();
495 
496  if ($form->getInput('img_mode') === 'up') {
497  $this->badge_image_service->processImageUpload($badge);
498  } else {
499  $tmpl = new ilBadgeImageTemplate($form->getInput('tmpl'));
500  $this->cloneBadgeTemplate($badge, new ResourceIdentification($tmpl->getImageRid()));
501  }
502 
503  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
504  $ilCtrl->redirect($this, 'listBadges');
505  }
506 
507  $form->setValuesByPost();
508  $this->addBadge($form);
509  }
initBadgeForm(string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
cloneBadgeTemplate(ilBadge $badge, ?ResourceIdentification $rid)
addBadge(ilPropertyFormGUI $a_form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$handler
Definition: oai.php:14
+ Here is the call graph for this function:

◆ selectBadgeForAwardingOrRevoking()

ilBadgeManagementGUI::selectBadgeForAwardingOrRevoking ( )
private

Definition at line 837 of file class.ilBadgeManagementGUI.php.

References ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

837  : never
838  {
839  $this->ctrl->setParameter(
840  $this,
841  'bid',
842  $this->http->wrapper()->post()->retrieve('bid', $this->refinery->kindlyTo()->int())
843  );
844  $this->ctrl->redirect($this, 'awardBadgeUserSelection');
845  }
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:

◆ setBadgeFormValues()

ilBadgeManagementGUI::setBadgeFormValues ( ilPropertyFormGUI  $a_form,
ilBadge  $a_badge,
ilBadgeType  $a_type 
)
protected

Definition at line 541 of file class.ilBadgeManagementGUI.php.

References ilBadgeType\getConfigGUIInstance(), ilBadge\getConfiguration(), ilBadge\getCriteria(), ilBadge\getDescription(), ilBadge\getImage(), ilBadge\getImagePath(), ilPropertyFormGUI\getItemByPostVar(), ilBadge\getTitle(), ilBadge\getValid(), and ilBadge\isActive().

Referenced by editBadge(), and executeCommand().

545  : void {
546  $a_form->getItemByPostVar('act')->setChecked($a_badge->isActive());
547  $a_form->getItemByPostVar('title')->setValue($a_badge->getTitle());
548  $a_form->getItemByPostVar('desc')->setValue($a_badge->getDescription());
549  $a_form->getItemByPostVar('crit')->setValue($a_badge->getCriteria());
550  $a_form->getItemByPostVar('img')->setValue($a_badge->getImage());
551  $a_form->getItemByPostVar('img')->setImage($a_badge->getImagePath());
552 
553  $image_src = $this->badge_image_service->getImageFromBadge($a_badge);
554  if ($image_src !== '') {
555  $a_form->getItemByPostVar('img')->setImage($image_src);
556  }
557 
558  $a_form->getItemByPostVar('valid')->setValue($a_badge->getValid());
559 
560  $custom = $a_type->getConfigGUIInstance();
561  if ($custom instanceof ilBadgeTypeGUI) {
562  $custom->importConfigToForm($a_form, $a_badge->getConfiguration());
563  }
564  }
getConfiguration()
getItemByPostVar(string $a_post_var)
getConfigGUIInstance()
Get GUI config instance.
getImagePath(bool $a_full_path=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTabs()

ilBadgeManagementGUI::setTabs ( string  $a_active)
protected

Definition at line 233 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, $tabs, and ilLanguage\txt().

Referenced by listBadges(), and listUsers().

233  : void
234  {
235  $ilTabs = $this->tabs;
236  $lng = $this->lng;
237  $ilCtrl = $this->ctrl;
238 
239  $ilTabs->addSubTab(
240  'badges',
241  $lng->txt('obj_bdga'),
242  $ilCtrl->getLinkTarget($this, 'listBadges')
243  );
244 
245  $ilTabs->addSubTab(
246  'users',
247  $lng->txt('users'),
248  $ilCtrl->getLinkTarget($this, 'listUsers')
249  );
250 
251  $ilTabs->activateSubTab($a_active);
252  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ splitBadgeAndUserIdsFromString()

ilBadgeManagementGUI::splitBadgeAndUserIdsFromString ( array  $splittable_user_ids)
private
Parameters
list<string>$splittable_user_ids
Returns
array{0: list<int>, 1: int}

Definition at line 105 of file class.ilBadgeManagementGUI.php.

References $parent_obj_id, ilObject\_lookupObjId(), ilBadgeHandler\getInstance(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), and ILIAS\Repository\refinery().

Referenced by assignBadge(), and confirmDeassignBadge().

105  : array
106  {
107  $user_ids = [];
108  $badge_id = null;
109 
110  if ($splittable_user_ids !== []) {
111  if ($splittable_user_ids === ['ALL_OBJECTS']) {
113  if (!$parent_obj_id && $this->parent_ref_id) {
114  $parent_obj_id = ilObject::_lookupObjId($this->parent_ref_id);
115  }
116 
117  if ($this->parent_ref_id) {
118  $user_ids = ilBadgeHandler::getInstance()->getUserIds($this->parent_ref_id, $parent_obj_id);
119  }
120 
121  $badge_id = $this->http->wrapper()->query()->retrieve('bid', $this->refinery->kindlyTo()->int());
122  return [$user_ids, $badge_id];
123  } else {
124  foreach ($splittable_user_ids as $row) {
125  if (str_contains($row, '_')) {
126  $split = explode('_', $row);
127 
128  if ($badge_id === null && $split[0] !== '') {
129  $badge_id = (int) $split[0];
130  }
131 
132  if ($split[1] !== '') {
133  $user_ids[] = (int) $split[1];
134  }
135  } else {
136  return [$user_ids, 0];
137  }
138  }
139  }
140  }
141 
142  return [$user_ids, $badge_id];
143  }
static _lookupObjId(int $ref_id)
static http()
Fetches the global http state from ILIAS.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toggleBadges()

ilBadgeManagementGUI::toggleBadges ( bool  $a_status)
protected

Definition at line 765 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, ilBadge\getInstancesByParentId(), and ilLanguage\txt().

Referenced by activateBadges(), and deactivateBadges().

765  : void
766  {
767  $ilCtrl = $this->ctrl;
768  $lng = $this->lng;
769 
770  $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
771  if (count($badge_ids) > 0) {
772  foreach ($badge_ids as $badge_id) {
773  if ($badge_id === self::TABLE_ALL_OBJECTS_ACTION) {
774  foreach (ilBadge::getInstancesByParentId($this->parent_obj_id) as $badge) {
775  $badge = new ilBadge($badge->getId());
776  $badge->setActive($a_status);
777  $badge->update();
778  }
779  } else {
780  $badge = new ilBadge((int) $badge_id);
781  $badge->setActive($a_status);
782  $badge->update();
783  }
784  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
785  }
786  } else {
787  $this->tpl->setOnScreenMessage('failure', $lng->txt('badge_select_one'), true);
788  }
789 
790  $ilCtrl->redirect($this, 'listBadges');
791  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateBadge()

ilBadgeManagementGUI::updateBadge ( )
protected
Exceptions
ilCtrlException
IllegalStateException

Definition at line 570 of file class.ilBadgeManagementGUI.php.

References $ctrl, $lng, cloneBadgeTemplate(), editBadge(), hasWrite(), initBadgeForm(), removeResourceStorageImage(), and ilLanguage\txt().

570  : void
571  {
572  $ilCtrl = $this->ctrl;
573  $lng = $this->lng;
574 
575  $badge_id = $this->request->getBadgeId();
576  if (!$badge_id ||
577  !$this->hasWrite()) {
578  $ilCtrl->redirect($this, 'listBadges');
579  }
580 
581  $ilCtrl->setParameter($this, 'bid', $badge_id);
582 
583  $badge = new ilBadge($badge_id);
584  $type = $badge->getTypeInstance();
585  $custom = $type->getConfigGUIInstance();
586  if ($custom &&
587  !($custom instanceof ilBadgeTypeGUI)) {
588  $custom = null;
589  }
590  $form = $this->initBadgeForm('update', $type, $badge->getTypeId());
591  if ($form->checkInput() &&
592  (!$custom || $custom->validateForm($form))) {
593  $badge->setActive($form->getInput('act'));
594  $badge->setTitle($form->getInput('title'));
595  $badge->setDescription($form->getInput('desc'));
596  $badge->setCriteria($form->getInput('crit'));
597  $badge->setValid($form->getInput('valid'));
598 
599  $image = $form->getInput('img');
600  if (isset($image['name']) && $image['name'] !== '') {
601  $this->removeResourceStorageImage($badge);
602  $this->badge_image_service->processImageUpload($badge);
603  }
604 
605  if ($custom) {
606  $badge->setConfiguration($custom->getConfigFromForm($form));
607  }
608  $tmpl_id = $form->getInput('tmpl');
609  if ($tmpl_id !== '') {
610  $this->removeResourceStorageImage($badge);
611  $tmpl = new ilBadgeImageTemplate($tmpl_id);
612  $this->cloneBadgeTemplate($badge, new ResourceIdentification($tmpl->getImageRid()));
613  }
614 
615  $badge->update();
616  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
617  $ilCtrl->redirect($this, 'listBadges');
618  }
619 
620  $this->tpl->setOnScreenMessage('failure', $lng->txt('form_input_not_valid'));
621  $form->setValuesByPost();
622  $this->editBadge($form);
623  }
initBadgeForm(string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
editBadge(ilPropertyFormGUI $a_form=null)
cloneBadgeTemplate(ilBadge $badge, ?ResourceIdentification $rid)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilBadgeManagementGUI::$access
private

Definition at line 41 of file class.ilBadgeManagementGUI.php.

Referenced by hasWrite().

◆ $badge_image_service

ilBadgeImage ilBadgeManagementGUI::$badge_image_service = null
private

Definition at line 49 of file class.ilBadgeManagementGUI.php.

◆ $ctrl

◆ $flavour_definition

ilBadgePictureDefinition ilBadgeManagementGUI::$flavour_definition = null
private

Definition at line 52 of file class.ilBadgeManagementGUI.php.

◆ $http

ILIAS HTTP Services ilBadgeManagementGUI::$http
private

Definition at line 53 of file class.ilBadgeManagementGUI.php.

◆ $lng

◆ $parent_obj_id

int ilBadgeManagementGUI::$parent_obj_id
private

Definition at line 46 of file class.ilBadgeManagementGUI.php.

Referenced by splitBadgeAndUserIdsFromString().

◆ $parent_obj_type

string ilBadgeManagementGUI::$parent_obj_type
private

Definition at line 47 of file class.ilBadgeManagementGUI.php.

◆ $refinery

Factory ilBadgeManagementGUI::$refinery
private

Definition at line 54 of file class.ilBadgeManagementGUI.php.

◆ $request

ilBadgeGUIRequest ilBadgeManagementGUI::$request
private

Definition at line 36 of file class.ilBadgeManagementGUI.php.

◆ $resource_storage

Services ilBadgeManagementGUI::$resource_storage
private

Definition at line 50 of file class.ilBadgeManagementGUI.php.

◆ $session_repo

ilBadgeManagementSessionRepository ilBadgeManagementGUI::$session_repo
private

Definition at line 37 of file class.ilBadgeManagementGUI.php.

◆ $tabs

ilTabsGUI ilBadgeManagementGUI::$tabs
private

◆ $toolbar

ilToolbarGUI ilBadgeManagementGUI::$toolbar
private

Definition at line 42 of file class.ilBadgeManagementGUI.php.

Referenced by listBadges(), and listUsers().

◆ $tpl

ilGlobalTemplateInterface ilBadgeManagementGUI::$tpl
private

◆ $ui_factory

ILIAS UI Factory ilBadgeManagementGUI::$ui_factory
private

Definition at line 45 of file class.ilBadgeManagementGUI.php.

◆ $upload_service

FileUpload ilBadgeManagementGUI::$upload_service
private

Definition at line 51 of file class.ilBadgeManagementGUI.php.

◆ $user

ilObjUser ilBadgeManagementGUI::$user
private

Definition at line 44 of file class.ilBadgeManagementGUI.php.

Referenced by assignBadge().

◆ TABLE_ALL_OBJECTS_ACTION

const ilBadgeManagementGUI::TABLE_ALL_OBJECTS_ACTION = 'ALL_OBJECTS'

Definition at line 34 of file class.ilBadgeManagementGUI.php.


The documentation for this class was generated from the following file: