ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 57 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().

61  {
62  global $DIC;
63 
64  $this->lng = $DIC->language();
65  $this->ctrl = $DIC->ctrl();
66  $this->tabs = $DIC->tabs();
67  $this->access = $DIC->access();
68  $this->http = $DIC->http();
69  $this->refinery = $DIC->refinery();
70  $this->toolbar = $DIC->toolbar();
71  $this->ui_factory = $DIC->ui()->factory();
72  $this->resource_storage = $DIC->resourceStorage();
73  $this->upload_service = $DIC->upload();
74  $this->tpl = $DIC->ui()->mainTemplate();
75  $this->user = $DIC->user();
76  $lng = $DIC->language();
77  $this->parent_obj_id = $a_parent_obj_id
78  ?: ilObject::_lookupObjId($parent_ref_id);
79  $this->parent_obj_type = $a_parent_obj_type
80  ?: ilObject::_lookupType($this->parent_obj_id);
81 
82  if (!ilBadgeHandler::getInstance()->isObjectActive($this->parent_obj_id)) {
83  throw new ilException('inactive object');
84  }
85 
86  $lng->loadLanguageModule('badge');
87 
88  $this->request = new ilBadgeGUIRequest(
89  $DIC->http(),
90  $DIC->refinery()
91  );
92 
93  $this->session_repo = new ilBadgeManagementSessionRepository();
94  $this->badge_image_service = new ilBadgeImage(
95  $DIC->resourceStorage(),
96  $DIC->upload(),
97  $DIC->ui()->mainTemplate()
98  );
99  $this->flavour_definition = new ilBadgePictureDefinition();
100  }
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:26
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 794 of file class.ilBadgeManagementGUI.php.

References toggleBadges().

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

◆ addBadge()

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

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

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

Referenced by saveBadge().

331  : void
332  {
333  $ilCtrl = $this->ctrl;
334  $tpl = $this->tpl;
335 
336  $type_id = $this->request->getType();
337  if (!$type_id ||
338  !$this->hasWrite()) {
339  $ilCtrl->redirect($this, 'listBadges');
340  }
341 
342  $ilCtrl->setParameter($this, 'type', $type_id);
343 
345  $type = $handler->getTypeInstanceByUniqueId($type_id);
346  if (!$type) {
347  $ilCtrl->redirect($this, 'listBadges');
348  }
349 
350  if (!$a_form) {
351  $a_form = $this->initBadgeForm('create', $type, $type_id);
352  }
353 
354  $tpl->setContent($a_form->getHTML());
355  }
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:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assignBadge()

ilBadgeManagementGUI::assignBadge ( )
protected

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

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

897  : void
898  {
899  $ilCtrl = $this->ctrl;
900  $ilUser = $this->user;
901  $lng = $this->lng;
902 
903  $splittable_user_ids = $this->request->getBadgeAssignableUsers();
904  [$user_ids, $badge_id] = $this->splitBadgeAndUserIdsFromString($splittable_user_ids);
905 
906  if (!$user_ids ||
907  !$badge_id ||
908  !$this->hasWrite()) {
909  $ilCtrl->redirect($this, 'listUsers');
910  }
911 
912  $new_badges = [];
913  foreach ($user_ids as $user_id) {
914  if (!ilBadgeAssignment::exists($badge_id, $user_id)) {
915  $ass = new ilBadgeAssignment($badge_id, $user_id);
916  $ass->setAwardedBy($ilUser->getId());
917  $ass->store();
918 
919  $new_badges[$user_id][] = $badge_id;
920  }
921  }
922 
923  ilBadgeHandler::getInstance()->sendNotification($new_badges, $this->parent_ref_id);
924 
925  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
926  $ilCtrl->redirect($this, 'listUsers');
927  }
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 848 of file class.ilBadgeManagementGUI.php.

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

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

◆ clearClipboard()

ilBadgeManagementGUI::clearClipboard ( )
protected

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

References $ctrl, and ilCtrl\redirect().

722  : void
723  {
724  $ilCtrl = $this->ctrl;
725 
726  $this->session_repo->clear();
727  $ilCtrl->redirect($this, 'listBadges');
728  }
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 1009 of file class.ilBadgeManagementGUI.php.

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

Referenced by saveBadge(), and updateBadge().

1009  : void
1010  {
1011  if ($rid !== null) {
1012  $new_rid = $this->badge_image_service->cloneBadgeImageByRid($rid);
1013  $badge->setImageRid($new_rid);
1014  $badge->update();
1015  }
1016  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 929 of file class.ilBadgeManagementGUI.php.

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

929  : void
930  {
931  $ilCtrl = $this->ctrl;
932  $lng = $this->lng;
933  $tpl = $this->tpl;
934  $ilTabs = $this->tabs;
935 
936  $splittable_user_ids = $this->request->getMultiActionBadgeIdsFromUrl();
937  [$user_ids, $badge_id] = $this->splitBadgeAndUserIdsFromString($splittable_user_ids);
938 
939  if (!$user_ids ||
940  !$badge_id ||
941  !$this->hasWrite()) {
942  $ilCtrl->redirect($this, 'listUsers');
943  }
944 
945  $ilTabs->clearTargets();
946  $ilTabs->setBackTarget(
947  $lng->txt('back'),
948  $ilCtrl->getLinkTarget($this, 'listUsers')
949  );
950 
951  $badge = new ilBadge($badge_id);
952 
953  $ilCtrl->setParameter($this, 'bid', $badge->getId());
954 
955  $confirmation_gui = new ilConfirmationGUI();
956  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
957  $confirmation_gui->setHeaderText(
958  sprintf($lng->txt('badge_assignment_deletion_confirmation'), $badge->getTitle())
959  );
960  $confirmation_gui->setCancel($lng->txt('cancel'), 'listUsers');
961  $confirmation_gui->setConfirm($lng->txt('badge_remove_badge'), 'deassignBadge');
962 
963  $assigned_users = ilBadgeAssignment::getAssignedUsers($badge->getId());
964 
965  foreach ($user_ids as $user_id) {
966  if (in_array($user_id, $assigned_users, true)) {
967  $confirmation_gui->addItem(
968  "id[$user_id]",
969  (string) $badge_id,
970  ilUserUtil::getNamePresentation($user_id, false, false, '', true)
971  );
972  }
973  }
974 
975  $tpl->setContent($confirmation_gui->getHTML());
976  }
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 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:
ilGlobalTemplateInterface $tpl
splitBadgeAndUserIdsFromString(array $splittable_user_ids)
+ Here is the call graph for this function:

◆ confirmDeleteBadges()

ilBadgeManagementGUI::confirmDeleteBadges ( )
protected

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

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

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

◆ copyBadges()

ilBadgeManagementGUI::copyBadges ( )
protected

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

References $ctrl, and getBadgesFromMultiAction().

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

◆ deactivateBadges()

ilBadgeManagementGUI::deactivateBadges ( )
protected

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

References toggleBadges().

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

◆ deassignBadge()

ilBadgeManagementGUI::deassignBadge ( )
protected

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

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

978  : void
979  {
980  $ilCtrl = $this->ctrl;
981  $lng = $this->lng;
982 
983  $post_values = $this->request->getIds();
984  $user_ids = [];
985  $badge_id = null;
986  foreach ($post_values as $usr_id => $found_badge_id) {
987  $badge_id = $found_badge_id;
988  $user_ids[] = $usr_id;
989  }
990 
991  if (!$user_ids ||
992  !$badge_id ||
993  !$this->hasWrite()) {
994  $ilCtrl->redirect($this, 'listUsers');
995  }
996 
997  foreach ($user_ids as $user_id) {
998  $ass = new ilBadgeAssignment((int) $badge_id, (int) $user_id);
999  $ass->delete();
1000  }
1001 
1002  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
1003  $ilCtrl->redirect($this, 'listUsers');
1004  }
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...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ deleteBadges()

ilBadgeManagementGUI::deleteBadges ( )
protected

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

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

666  : void
667  {
668  $ilCtrl = $this->ctrl;
669  $lng = $this->lng;
670 
671  $badge_ids = $this->request->getIds();
672 
673  if (count($badge_ids) > 0) {
674  foreach ($badge_ids as $badge_id) {
675  $badge = new ilBadge((int) $badge_id);
676  $badge->delete();
677  }
678  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
679  } else {
680  $this->tpl->setOnScreenMessage('failure', $lng->txt('badge_select_one'), true);
681  }
682 
683  $ilCtrl->redirect($this, 'listBadges');
684  }
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 512 of file class.ilBadgeManagementGUI.php.

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

Referenced by updateBadge().

512  : void
513  {
514  $ilCtrl = $this->ctrl;
515  $tpl = $this->tpl;
516  $lng = $this->lng;
517 
518  $badge_id = $this->request->getBadgeIdFromUrl();
519  if (!$badge_id ||
520  !$this->hasWrite()) {
521  $ilCtrl->redirect($this, 'listBadges');
522  }
523 
524  $ilCtrl->setParameter($this, 'bid', $badge_id);
525 
526  $badge = new ilBadge($badge_id);
527 
528  $static_cnt = ilBadgeHandler::getInstance()->countStaticBadgeInstances($badge);
529  if ($static_cnt) {
530  $this->tpl->setOnScreenMessage('info', sprintf($lng->txt('badge_edit_with_published'), $static_cnt));
531  }
532 
533  if (!$a_form) {
534  $type = $badge->getTypeInstance();
535  $a_form = $this->initBadgeForm('edit', $type, $badge->getTypeId());
536  $this->setBadgeFormValues($a_form, $badge, $type);
537  }
538 
539  $tpl->setContent($a_form->getHTML());
540  }
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...
setContent(string $a_html)
Sets content for standard template.
setBadgeFormValues(ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
ilGlobalTemplateInterface $tpl
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilBadgeManagementGUI::executeCommand ( )

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

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

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

◆ getBadgesFromMultiAction()

ilBadgeManagementGUI::getBadgesFromMultiAction ( )
protected
Returns
int[]

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

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

Referenced by copyBadges().

694  : array
695  {
696  $ilCtrl = $this->ctrl;
697 
698  $badge_ids = $this->request->getIds();
699  if (!$badge_ids ||
700  !$this->hasWrite()) {
701  $ilCtrl->redirect($this, 'listBadges');
702  }
703 
704  return $badge_ids;
705  }
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 224 of file class.ilBadgeManagementGUI.php.

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

◆ 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 229 of file class.ilBadgeManagementGUI.php.

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

◆ getValidBadgesFromClipboard()

ilBadgeManagementGUI::getValidBadgesFromClipboard ( )
protected
Returns
ilBadge[]

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

References $res, and ilBadgeHandler\getInstance().

Referenced by listBadges(), and pasteBadges().

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

◆ hasWrite()

ilBadgeManagementGUI::hasWrite ( )
protected

Definition at line 255 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().

255  : bool
256  {
257  $ilAccess = $this->access;
258  return $ilAccess->checkAccess('write', '', $this->parent_ref_id);
259  }
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 357 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().

362  $lng = $this->lng;
363  $ilCtrl = $this->ctrl;
364 
365  $form = new ilPropertyFormGUI();
366  $form->setFormAction($ilCtrl->getFormAction($this, 'saveBadge'));
367  $form->setTitle($lng->txt('badge_badge') . ' "' . $a_type->getCaption() . '"');
368 
369  $active = new ilCheckboxInputGUI($lng->txt('active'), 'act');
370  $form->addItem($active);
371 
372  $title = new ilTextInputGUI($lng->txt('title'), 'title');
373  $title->setMaxLength(255);
374  $title->setRequired(true);
375  $form->addItem($title);
376 
377  $desc = new ilTextAreaInputGUI($lng->txt('description'), 'desc');
378  $desc->setMaxNumOfChars(4000);
379  $desc->setRequired(true);
380  $form->addItem($desc);
381 
382  $crit = new ilTextAreaInputGUI($lng->txt('badge_criteria'), 'crit');
383  $crit->setMaxNumOfChars(4000);
384  $crit->setRequired(true);
385  $form->addItem($crit);
386 
387  if ($a_mode === 'create') {
388  // upload
389 
390  $img_mode = new ilRadioGroupInputGUI($lng->txt('image'), 'img_mode');
391  $img_mode->setRequired(true);
392  $img_mode->setValue('tmpl');
393  $form->addItem($img_mode);
394 
395  $img_mode_tmpl = new ilRadioOption($lng->txt('badge_image_from_template'), 'tmpl');
396  $img_mode->addOption($img_mode_tmpl);
397 
398  $img_mode_up = new ilRadioOption($lng->txt('badge_image_from_upload'), 'up');
399  $img_mode->addOption($img_mode_up);
400 
401  $img_upload = new ilImageFileInputGUI($lng->txt('file'), 'img');
402  $img_upload->setRequired(true);
403  $img_upload->setSuffixes(['png', 'svg']);
404  $img_mode_up->addSubItem($img_upload);
405 
406  // templates
407 
408  $valid_templates = ilBadgeImageTemplate::getInstancesByType($a_type_unique_id);
409  if (count($valid_templates)) {
410  $options = [];
411  $options[''] = $lng->txt('please_select');
412  foreach ($valid_templates as $tmpl) {
413  $options[$tmpl->getId()] = $tmpl->getTitle();
414  }
415 
416  $tmpl = new ilSelectInputGUI($lng->txt('badge_image_template_form'), 'tmpl');
417  $tmpl->setRequired(true);
418  $tmpl->setOptions($options);
419  $img_mode_tmpl->addSubItem($tmpl);
420  } else {
421  // no templates, activate upload
422  $img_mode_tmpl->setDisabled(true);
423  $img_mode->setValue('up');
424  }
425  } else {
426  $img_upload = new ilImageFileInputGUI($lng->txt('image'), 'img');
427  $img_upload->setSuffixes(['png', 'svg']);
428  $img_upload->setAllowDeletion(false);
429  $img_upload->setUseCache(false);
430  $form->addItem($img_upload);
431  }
432 
433  $valid = new ilTextInputGUI($lng->txt('badge_valid'), 'valid');
434  $valid->setMaxLength(255);
435  $form->addItem($valid);
436 
437  $custom = $a_type->getConfigGUIInstance();
438  if ($custom instanceof ilBadgeTypeGUI) {
439  $custom->initConfigForm($form, $this->parent_ref_id);
440  }
441 
442  // :TODO: valid date/period
443 
444  if ($a_mode === 'create') {
445  $form->addCommandButton('saveBadge', $lng->txt('save'));
446  } else {
447  $form->addCommandButton('updateBadge', $lng->txt('save'));
448  }
449  $form->addCommandButton('listBadges', $lng->txt('cancel'));
450 
451  return $form;
452  }
This class represents an option in a radio group.
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 261 of file class.ilBadgeManagementGUI.php.

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

261  : void
262  {
263  $ilToolbar = $this->toolbar;
264  $lng = $this->lng;
265  $ilCtrl = $this->ctrl;
266 
267  $this->setTabs('badges');
268 
269  if ($this->hasWrite()) {
271  $valid_types = $handler->getAvailableTypesForObjType($this->parent_obj_type);
272  if ($valid_types) {
273  $options = [];
274  foreach ($valid_types as $id => $type) {
275  $ilCtrl->setParameter($this, 'type', $id);
276  $options[$id] = $this->ui_factory->link()->standard(
277  $this->parent_obj_type !== 'bdga' ? ilBadge::getExtendedTypeCaption($type) : $type->getCaption(),
278  $ilCtrl->getLinkTarget($this, 'addBadge')
279  );
280  $ilCtrl->setParameter($this, 'type', null);
281  }
282  asort($options);
283  $options = array_values($options);
284 
285  $ilToolbar->addComponent(
286  $this->ui_factory->dropdown()->standard($options)->withLabel($lng->txt('badge_create'))
287  );
288  } else {
289  $this->tpl->setOnScreenMessage('info', $lng->txt('badge_no_valid_types_for_obj'));
290  }
291 
292  $clip_ids = $this->session_repo->getBadgeIds();
293  if (count($clip_ids) > 0) {
294  if ($valid_types) {
295  $ilToolbar->addSeparator();
296  }
297 
298  $tt = [];
299  foreach ($this->getValidBadgesFromClipboard() as $badge) {
300  $tt[] = $badge->getTitle();
301  }
302  $ttid = 'bdgpst';
303 
304  $lng->loadLanguageModule('content');
305  $ilToolbar->addButton(
306  $lng->txt('cont_paste_from_clipboard') .
307  ' (' . count($tt) . ')',
308  $ilCtrl->getLinkTarget($this, 'pasteBadges'),
309  '',
310  null,
311  '',
312  $ttid
313  );
314  $ilToolbar->addButton(
315  $lng->txt('clear_clipboard'),
316  $ilCtrl->getLinkTarget($this, 'clearClipboard')
317  );
318  }
319  }
320 
321  $table = new ilBadgeTableGUI($this->parent_obj_id, $this->parent_obj_type, $this->hasWrite());
322  $this->ctrl->setParameter($this, 'returnCmd', __FUNCTION__);
323  $table->renderTable(ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, 'action'));
324  }
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getExtendedTypeCaption(ilBadgeType $a_type)
$handler
Definition: oai.php:29
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ listUsers()

ilBadgeManagementGUI::listUsers ( )
protected

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

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

809  : void
810  {
811  $lng = $this->lng;
812  $ilCtrl = $this->ctrl;
813  $ilToolbar = $this->toolbar;
814  $tpl = $this->tpl;
815 
816  $this->setTabs('users');
817 
818  if ($this->hasWrite()) {
819  $manual = ilBadgeHandler::getInstance()->getAvailableManualBadges(
820  $this->parent_obj_id,
821  $this->parent_obj_type
822  );
823  if (count($manual)) {
824  $drop = new ilSelectInputGUI($lng->txt('badge_badge'), 'bid');
825  $drop->setOptions($manual);
826  $ilToolbar->addInputItem($drop, true);
827 
828  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, 'selectBadgeForAwardingOrRevoking'));
829  $ilToolbar->addFormButton($lng->txt('badge_award_badge'), 'selectBadgeForAwardingOrRevoking');
830  }
831  }
832 
833  $tbl = new ilBadgeUserTableGUI($this->parent_ref_id);
834  $this->ctrl->setParameter($this, 'returnCmd', __FUNCTION__);
835  $tbl->renderTable(ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this, 'action'));
836  }
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 749 of file class.ilBadgeManagementGUI.php.

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

749  : void
750  {
751  $ilCtrl = $this->ctrl;
752 
753  $clip_ids = $this->session_repo->getBadgeIds();
754  if (!$this->hasWrite() || count($clip_ids) === 0) {
755  $ilCtrl->redirect($this, 'listBadges');
756  }
757 
758  $copy_suffix = $this->lng->txt("copy_of_suffix");
759  foreach ($this->getValidBadgesFromClipboard() as $badge) {
760  $badge->copy($this->parent_obj_id, $copy_suffix);
761  }
762 
763  $ilCtrl->redirect($this, 'listBadges');
764  }
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 1018 of file class.ilBadgeManagementGUI.php.

References ilBadge\getImageRid().

Referenced by updateBadge().

1018  : void
1019  {
1020  if ($badge->getImageRid() !== '') {
1021  $this->resource_storage->manage()->remove(
1022  new ResourceIdentification($badge->getImageRid()),
1024  );
1025  }
1026  }
+ 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 458 of file class.ilBadgeManagementGUI.php.

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

458  : void
459  {
460  $ilCtrl = $this->ctrl;
461  $lng = $this->lng;
462 
463  $type_id = $this->request->getType();
464  if (!$type_id ||
465  !$this->hasWrite()) {
466  $ilCtrl->redirect($this, 'listBadges');
467  }
468 
469  $ilCtrl->setParameter($this, 'type', $type_id);
470 
472  $type = $handler->getTypeInstanceByUniqueId($type_id);
473  if (!$type) {
474  $ilCtrl->redirect($this, 'listBadges');
475  }
476 
477  $form = $this->initBadgeForm('create', $type, $type_id);
478  $custom = $type->getConfigGUIInstance();
479 
480  if ($form->checkInput() &&
481  (!$custom || $custom->validateForm($form))) {
482  $badge = new ilBadge();
483  $badge->setParentId($this->parent_obj_id); // :TODO: ref_id?
484  $badge->setTypeId($type_id);
485  $badge->setActive($form->getInput('act'));
486  $badge->setTitle($form->getInput('title'));
487  $badge->setDescription($form->getInput('desc'));
488  $badge->setCriteria($form->getInput('crit'));
489  $badge->setValid($form->getInput('valid'));
490 
491  if ($custom instanceof ilBadgeTypeGUI) {
492  $badge->setConfiguration($custom->getConfigFromForm($form));
493  }
494 
495  $badge->create();
496 
497  if ($form->getInput('img_mode') === 'up') {
498  $this->badge_image_service->processImageUpload($badge);
499  } else {
500  $tmpl = new ilBadgeImageTemplate($form->getInput('tmpl'));
501  $this->cloneBadgeTemplate($badge, new ResourceIdentification($tmpl->getImageRid()));
502  }
503 
504  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
505  $ilCtrl->redirect($this, 'listBadges');
506  }
507 
508  $form->setValuesByPost();
509  $this->addBadge($form);
510  }
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:29
+ Here is the call graph for this function:

◆ selectBadgeForAwardingOrRevoking()

ilBadgeManagementGUI::selectBadgeForAwardingOrRevoking ( )
private

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

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

838  : never
839  {
840  $this->ctrl->setParameter(
841  $this,
842  'bid',
843  $this->http->wrapper()->post()->retrieve('bid', $this->refinery->kindlyTo()->int())
844  );
845  $this->ctrl->redirect($this, 'awardBadgeUserSelection');
846  }
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 542 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().

546  : void {
547  $a_form->getItemByPostVar('act')->setChecked($a_badge->isActive());
548  $a_form->getItemByPostVar('title')->setValue($a_badge->getTitle());
549  $a_form->getItemByPostVar('desc')->setValue($a_badge->getDescription());
550  $a_form->getItemByPostVar('crit')->setValue($a_badge->getCriteria());
551  $a_form->getItemByPostVar('img')->setValue($a_badge->getImage());
552  $a_form->getItemByPostVar('img')->setImage($a_badge->getImagePath());
553 
554  $image_src = $this->badge_image_service->getImageFromBadge($a_badge);
555  if ($image_src !== '') {
556  $a_form->getItemByPostVar('img')->setImage($image_src);
557  }
558 
559  $a_form->getItemByPostVar('valid')->setValue($a_badge->getValid());
560 
561  $custom = $a_type->getConfigGUIInstance();
562  if ($custom instanceof ilBadgeTypeGUI) {
563  $custom->importConfigToForm($a_form, $a_badge->getConfiguration());
564  }
565  }
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 234 of file class.ilBadgeManagementGUI.php.

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

Referenced by listBadges(), and listUsers().

234  : void
235  {
236  $ilTabs = $this->tabs;
237  $lng = $this->lng;
238  $ilCtrl = $this->ctrl;
239 
240  $ilTabs->addSubTab(
241  'badges',
242  $lng->txt('obj_bdga'),
243  $ilCtrl->getLinkTarget($this, 'listBadges')
244  );
245 
246  $ilTabs->addSubTab(
247  'users',
248  $lng->txt('users'),
249  $ilCtrl->getLinkTarget($this, 'listUsers')
250  );
251 
252  $ilTabs->activateSubTab($a_active);
253  }
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 106 of file class.ilBadgeManagementGUI.php.

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

Referenced by assignBadge(), and confirmDeassignBadge().

106  : array
107  {
108  $user_ids = [];
109  $badge_id = null;
110 
111  if ($splittable_user_ids !== []) {
112  if ($splittable_user_ids === ['ALL_OBJECTS']) {
114  if (!$parent_obj_id && $this->parent_ref_id) {
115  $parent_obj_id = ilObject::_lookupObjId($this->parent_ref_id);
116  }
117 
118  if ($this->parent_ref_id) {
119  $user_ids = ilBadgeHandler::getInstance()->getUserIds($this->parent_ref_id, $parent_obj_id);
120  }
121 
122  $badge_id = $this->http->wrapper()->query()->retrieve('bid', $this->refinery->kindlyTo()->int());
123  return [$user_ids, $badge_id];
124  } else {
125  foreach ($splittable_user_ids as $row) {
126  if (str_contains($row, '_')) {
127  $split = explode('_', $row);
128 
129  if ($badge_id === null && $split[0] !== '') {
130  $badge_id = (int) $split[0];
131  }
132 
133  if ($split[1] !== '') {
134  $user_ids[] = (int) $split[1];
135  }
136  } else {
137  return [$user_ids, 0];
138  }
139  }
140  }
141  }
142 
143  return [$user_ids, $badge_id];
144  }
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 766 of file class.ilBadgeManagementGUI.php.

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

Referenced by activateBadges(), and deactivateBadges().

766  : void
767  {
768  $ilCtrl = $this->ctrl;
769  $lng = $this->lng;
770 
771  $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
772  if (count($badge_ids) > 0) {
773  foreach ($badge_ids as $badge_id) {
774  if ($badge_id === self::TABLE_ALL_OBJECTS_ACTION) {
775  foreach (ilBadge::getInstancesByParentId($this->parent_obj_id) as $badge) {
776  $badge = new ilBadge($badge->getId());
777  $badge->setActive($a_status);
778  $badge->update();
779  }
780  } else {
781  $badge = new ilBadge((int) $badge_id);
782  $badge->setActive($a_status);
783  $badge->update();
784  }
785  $this->tpl->setOnScreenMessage('success', $lng->txt('settings_saved'), true);
786  }
787  } else {
788  $this->tpl->setOnScreenMessage('failure', $lng->txt('badge_select_one'), true);
789  }
790 
791  $ilCtrl->redirect($this, 'listBadges');
792  }
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 571 of file class.ilBadgeManagementGUI.php.

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

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

Field Documentation

◆ $access

ilAccessHandler ilBadgeManagementGUI::$access
private

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

Referenced by hasWrite().

◆ $badge_image_service

ilBadgeImage ilBadgeManagementGUI::$badge_image_service = null
private

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

◆ $ctrl

◆ $flavour_definition

ilBadgePictureDefinition ilBadgeManagementGUI::$flavour_definition = null
private

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

◆ $http

ILIAS HTTP Services ilBadgeManagementGUI::$http
private

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

◆ $lng

◆ $parent_obj_id

int ilBadgeManagementGUI::$parent_obj_id
private

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

Referenced by splitBadgeAndUserIdsFromString().

◆ $parent_obj_type

string ilBadgeManagementGUI::$parent_obj_type
private

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

◆ $refinery

Factory ilBadgeManagementGUI::$refinery
private

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

◆ $request

ilBadgeGUIRequest ilBadgeManagementGUI::$request
private

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

◆ $resource_storage

Services ilBadgeManagementGUI::$resource_storage
private

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

◆ $session_repo

ilBadgeManagementSessionRepository ilBadgeManagementGUI::$session_repo
private

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

◆ $tabs

ilTabsGUI ilBadgeManagementGUI::$tabs
private

◆ $toolbar

ilToolbarGUI ilBadgeManagementGUI::$toolbar
private

Definition at line 43 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 46 of file class.ilBadgeManagementGUI.php.

◆ $upload_service

FileUpload ilBadgeManagementGUI::$upload_service
private

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

◆ $user

ilObjUser ilBadgeManagementGUI::$user
private

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

Referenced by assignBadge().

◆ TABLE_ALL_OBJECTS_ACTION

const ilBadgeManagementGUI::TABLE_ALL_OBJECTS_ACTION = 'ALL_OBJECTS'

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


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