53 private \ILIAS\HTTP\Services
$http;
57 private readonly
int $parent_ref_id,
58 int $a_parent_obj_id = null,
59 string $a_parent_obj_type = null
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();
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
78 $this->parent_obj_type = $a_parent_obj_type
94 $DIC->resourceStorage(),
96 $DIC->ui()->mainTemplate()
110 if ($splittable_user_ids !== []) {
111 if ($splittable_user_ids === [
'ALL_OBJECTS']) {
113 if (!$parent_obj_id && $this->parent_ref_id) {
117 if ($this->parent_ref_id) {
121 $badge_id = $this->
http->wrapper()->query()->retrieve(
'bid', $this->
refinery->kindlyTo()->int());
122 return [$user_ids, $badge_id];
124 foreach ($splittable_user_ids as $row) {
125 if (str_contains($row,
'_')) {
126 $split = explode(
'_', $row);
128 if ($badge_id === null && $split[0] !==
'') {
129 $badge_id = (
int) $split[0];
132 if ($split[1] !==
'') {
133 $user_ids[] = (
int) $split[1];
136 return [$user_ids, 0];
142 return [$user_ids, $badge_id];
150 $cmd = $ilCtrl->getCmd(
'listBadges');
152 switch ($next_class) {
153 case 'ilpropertyformgui':
155 if ($this->request->getBadgeId()) {
156 $badge =
new ilBadge($this->request->getBadgeId());
157 $type = $badge->getTypeInstance();
162 $type_id = $this->request->getType();
163 $ilCtrl->setParameter($this,
'type', $type_id);
165 $type =
$handler->getTypeInstanceByUniqueId($type_id);
168 $ilCtrl->forwardCommand($form);
172 $render_default =
true;
174 $action_parameter_token =
'tid_id';
175 $parameter =
'tid_table_action';
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())
187 $DIC->ctrl()->setParameter($this,
"tid",
$id);
191 $get = fn(
string $key) => $query->has($key) ?
192 $query->retrieve($key, $DIC->refinery()->kindlyTo()->string()) :
195 $action = $get($parameter);
196 $return_cmd = $get(
'returnCmd');
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',
208 $entry = $actions[$action] ?? null;
209 if ($cmd !==
'action' || !$entry) {
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();
233 protected function setTabs(
string $a_active): void
241 $lng->
txt(
'obj_bdga'),
242 $ilCtrl->getLinkTarget($this,
'listBadges')
248 $ilCtrl->getLinkTarget($this,
'listUsers')
251 $ilTabs->activateSubTab($a_active);
257 return $ilAccess->
checkAccess(
'write',
'', $this->parent_ref_id);
270 $valid_types =
$handler->getAvailableTypesForObjType($this->parent_obj_type);
273 foreach ($valid_types as
$id => $type) {
274 $ilCtrl->setParameter($this,
'type',
$id);
275 $options[
$id] = $this->ui_factory->link()->standard(
277 $ilCtrl->getLinkTarget($this,
'addBadge')
279 $ilCtrl->setParameter($this,
'type', null);
282 $options = array_values($options);
284 $ilToolbar->addComponent(
285 $this->ui_factory->dropdown()->standard($options)->withLabel($lng->
txt(
'badge_create'))
288 $this->tpl->setOnScreenMessage(
'info', $lng->
txt(
'badge_no_valid_types_for_obj'));
291 $clip_ids = $this->session_repo->getBadgeIds();
292 if (count($clip_ids) > 0) {
294 $ilToolbar->addSeparator();
299 $tt[] = $badge->getTitle();
304 $ilToolbar->addButton(
305 $lng->
txt(
'cont_paste_from_clipboard') .
306 ' (' . count($tt) .
')',
307 $ilCtrl->getLinkTarget($this,
'pasteBadges'),
313 $ilToolbar->addButton(
314 $lng->
txt(
'clear_clipboard'),
315 $ilCtrl->getLinkTarget($this,
'clearClipboard')
321 $this->
ctrl->setParameter($this,
'returnCmd', __FUNCTION__);
322 $table->renderTable(ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getLinkTarget($this,
'action'));
335 $type_id = $this->request->getType();
338 $ilCtrl->redirect($this,
'listBadges');
341 $ilCtrl->setParameter($this,
'type', $type_id);
344 $type =
$handler->getTypeInstanceByUniqueId($type_id);
346 $ilCtrl->redirect($this,
'listBadges');
359 string $a_type_unique_id
365 $form->setFormAction($ilCtrl->getFormAction($this,
'saveBadge'));
366 $form->setTitle($lng->
txt(
'badge_badge') .
' "' . $a_type->
getCaption() .
'"');
369 $form->addItem($active);
372 $title->setMaxLength(255);
373 $title->setRequired(
true);
374 $form->addItem($title);
378 $desc->setRequired(
true);
379 $form->addItem($desc);
383 $crit->setRequired(
true);
384 $form->addItem($crit);
386 if ($a_mode ===
'create') {
391 $img_mode->setValue(
'tmpl');
392 $form->addItem($img_mode);
394 $img_mode_tmpl =
new ilRadioOption($lng->
txt(
'badge_image_from_template'),
'tmpl');
395 $img_mode->addOption($img_mode_tmpl);
397 $img_mode_up =
new ilRadioOption($lng->
txt(
'badge_image_from_upload'),
'up');
398 $img_mode->addOption($img_mode_up);
402 $img_upload->setSuffixes([
'png',
'svg']);
403 $img_mode_up->addSubItem($img_upload);
408 if (count($valid_templates)) {
410 $options[
''] = $lng->
txt(
'please_select');
411 foreach ($valid_templates as $tmpl) {
412 $options[$tmpl->getId()] = $tmpl->getTitle();
417 $tmpl->setOptions($options);
418 $img_mode_tmpl->addSubItem($tmpl);
421 $img_mode_tmpl->setDisabled(
true);
422 $img_mode->setValue(
'up');
427 $img_upload->setAllowDeletion(
false);
428 $img_upload->setUseCache(
false);
429 $form->addItem($img_upload);
433 $valid->setMaxLength(255);
438 $custom->initConfigForm($form, $this->parent_ref_id);
443 if ($a_mode ===
'create') {
444 $form->addCommandButton(
'saveBadge', $lng->
txt(
'save'));
446 $form->addCommandButton(
'updateBadge', $lng->
txt(
'save'));
448 $form->addCommandButton(
'listBadges', $lng->
txt(
'cancel'));
462 $type_id = $this->request->getType();
465 $ilCtrl->redirect($this,
'listBadges');
468 $ilCtrl->setParameter($this,
'type', $type_id);
471 $type =
$handler->getTypeInstanceByUniqueId($type_id);
473 $ilCtrl->redirect($this,
'listBadges');
477 $custom = $type->getConfigGUIInstance();
479 if ($form->checkInput() &&
480 (!$custom || $custom->validateForm($form))) {
482 $badge->setParentId($this->parent_obj_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'));
491 $badge->setConfiguration($custom->getConfigFromForm($form));
496 if ($form->getInput(
'img_mode') ===
'up') {
497 $this->badge_image_service->processImageUpload($badge);
503 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
504 $ilCtrl->redirect($this,
'listBadges');
507 $form->setValuesByPost();
517 $badge_id = $this->request->getBadgeIdFromUrl();
520 $ilCtrl->redirect($this,
'listBadges');
523 $ilCtrl->setParameter($this,
'bid', $badge_id);
525 $badge =
new ilBadge($badge_id);
529 $this->tpl->setOnScreenMessage(
'info', sprintf($lng->
txt(
'badge_edit_with_published'), $static_cnt));
533 $type = $badge->getTypeInstance();
534 $a_form = $this->
initBadgeForm(
'edit', $type, $badge->getTypeId());
553 $image_src = $this->badge_image_service->getImageFromBadge($a_badge);
554 if ($image_src !==
'') {
575 $badge_id = $this->request->getBadgeId();
578 $ilCtrl->redirect($this,
'listBadges');
581 $ilCtrl->setParameter($this,
'bid', $badge_id);
583 $badge =
new ilBadge($badge_id);
584 $type = $badge->getTypeInstance();
585 $custom = $type->getConfigGUIInstance();
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'));
599 $image = $form->getInput(
'img');
600 if (isset($image[
'name']) && $image[
'name'] !==
'') {
602 $this->badge_image_service->processImageUpload($badge);
606 $badge->setConfiguration($custom->getConfigFromForm($form));
608 $tmpl_id = $form->getInput(
'tmpl');
609 if ($tmpl_id !==
'') {
616 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
617 $ilCtrl->redirect($this,
'listBadges');
620 $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
'form_input_not_valid'));
621 $form->setValuesByPost();
632 $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
633 if ($badge_ids === [
'ALL_OBJECTS']) {
636 $badge_ids[] = $badge->getId();
641 $ilTabs->setBackTarget(
643 $ilCtrl->getLinkTarget($this,
'listBadges')
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');
652 foreach ($badge_ids as $badge_id) {
653 $badge =
new ilBadge((
int) $badge_id);
654 $confirmation_gui->addItem(
662 $tpl->
setContent($confirmation_gui->getHTML());
670 $badge_ids = $this->request->getIds();
672 if (count($badge_ids) > 0) {
673 foreach ($badge_ids as $badge_id) {
674 $badge =
new ilBadge((
int) $badge_id);
677 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
679 $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
'badge_select_one'),
true);
682 $ilCtrl->redirect($this,
'listBadges');
697 $badge_ids = $this->request->getIds();
700 $ilCtrl->
redirect($this,
'listBadges');
712 $clip_ids = $this->session_repo->getBadgeIds();
713 $clip_ids = array_unique(
714 array_merge($clip_ids, $badge_ids)
716 $this->session_repo->setBadgeIds(
array_map(intval(...), $clip_ids));
718 $ilCtrl->redirect($this,
'listBadges');
725 $this->session_repo->clear();
726 $ilCtrl->
redirect($this,
'listBadges');
738 foreach ($this->session_repo->getBadgeIds() as $badge_id) {
739 $badge =
new ilBadge($badge_id);
740 if (in_array($badge->getTypeId(), $valid_types,
true)) {
752 $clip_ids = $this->session_repo->getBadgeIds();
753 if (!$this->
hasWrite() || count($clip_ids) === 0) {
754 $ilCtrl->
redirect($this,
'listBadges');
757 $copy_suffix = $this->
lng->txt(
"copy_of_suffix");
759 $badge->copy($this->parent_obj_id, $copy_suffix);
762 $ilCtrl->redirect($this,
'listBadges');
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) {
775 $badge =
new ilBadge($badge->getId());
776 $badge->setActive($a_status);
780 $badge =
new ilBadge((
int) $badge_id);
781 $badge->setActive($a_status);
784 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
787 $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
'badge_select_one'),
true);
790 $ilCtrl->redirect($this,
'listBadges');
819 $this->parent_obj_id,
820 $this->parent_obj_type
822 if (count($manual)) {
825 $ilToolbar->addInputItem($drop,
true);
827 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
'selectBadgeForAwardingOrRevoking'));
828 $ilToolbar->addFormButton($lng->
txt(
'badge_award_badge'),
'selectBadgeForAwardingOrRevoking');
833 $this->
ctrl->setParameter($this,
'returnCmd', __FUNCTION__);
834 $tbl->renderTable(ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getLinkTarget($this,
'action'));
839 $this->
ctrl->setParameter(
842 $this->
http->wrapper()->post()->retrieve(
'bid', $this->
refinery->kindlyTo()->int())
844 $this->
ctrl->redirect($this,
'awardBadgeUserSelection');
849 $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
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());
858 } elseif (count($badge_ids) === 1) {
859 $bid = (
int) $badge_ids[0];
864 $this->
ctrl->redirect($this,
'listUsers');
867 $manual = array_keys(
871 if (!in_array($bid, $manual,
true)) {
872 $this->
ctrl->redirect($this,
'listUsers');
875 $back_target =
'listUsers';
876 if ($this->request->getTgt() ===
'bdgl') {
877 $this->
ctrl->saveParameter($this,
'tgt');
878 $back_target =
'listBadges';
881 $this->
tabs->clearTargets();
882 $this->
tabs->setBackTarget(
883 $this->
lng->txt(
'back'),
884 $this->
ctrl->getLinkTarget($this, $back_target)
887 $this->
ctrl->setParameter($this,
'bid', $bid);
892 $this->
ctrl->setParameter($this,
'returnCmd', __FUNCTION__);
893 $tbl->renderTable(ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getLinkTarget($this,
'action'));
902 $splittable_user_ids = $this->request->getBadgeAssignableUsers();
908 $ilCtrl->redirect($this,
'listUsers');
915 $ass->setAwardedBy($ilUser->getId());
918 $new_badges[
$user_id][] = $badge_id;
924 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
925 $ilCtrl->redirect($this,
'listUsers');
935 $splittable_user_ids = $this->request->getMultiActionBadgeIdsFromUrl();
941 $ilCtrl->redirect($this,
'listUsers');
944 $ilTabs->clearTargets();
945 $ilTabs->setBackTarget(
947 $ilCtrl->getLinkTarget($this,
'listUsers')
950 $badge =
new ilBadge($badge_id);
952 $ilCtrl->setParameter($this,
'bid', $badge->getId());
955 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
956 $confirmation_gui->setHeaderText(
957 sprintf($lng->
txt(
'badge_assignment_deletion_confirmation'), $badge->getTitle())
959 $confirmation_gui->setCancel($lng->
txt(
'cancel'),
'listUsers');
960 $confirmation_gui->setConfirm($lng->
txt(
'badge_remove_badge'),
'deassignBadge');
965 if (in_array($user_id, $assigned_users,
true)) {
966 $confirmation_gui->addItem(
974 $tpl->
setContent($confirmation_gui->getHTML());
982 $post_values = $this->request->getIds();
985 foreach ($post_values as $usr_id => $found_badge_id) {
986 $badge_id = $found_badge_id;
987 $user_ids[] = $usr_id;
993 $ilCtrl->redirect($this,
'listUsers');
1001 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
1002 $ilCtrl->redirect($this,
'listUsers');
1010 if ($rid !== null) {
1011 $new_rid = $this->badge_image_service->cloneBadgeImageByRid($rid);
1020 $this->resource_storage->manage()->remove(
__construct(private readonly int $parent_ref_id, int $a_parent_obj_id=null, string $a_parent_obj_type=null)
initBadgeForm(string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilBadgeManagementGUI: ilPropertyFormGUI
static getInstancesByType(string $a_type_unique_id)
ILIAS HTTP Services $http
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
ilBadgeGUIRequest $request
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
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) ...
ilBadgePictureDefinition $flavour_definition
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
toggleBadges(bool $a_status)
getConfigGUIInstance()
Get GUI config instance.
Stores repository clipboard data.
editBadge(ilPropertyFormGUI $a_form=null)
ilBadgeManagementSessionRepository $session_repo
Services $resource_storage
static getAssignedUsers(int $a_badge_id)
loadLanguageModule(string $a_module)
Load language module.
setBadgeFormValues(ilPropertyFormGUI $a_form, ilBadge $a_badge, ilBadgeType $a_type)
getSafePostCommands()
This method must return a list of safe POST commands.
FileUpload $upload_service
cloneBadgeTemplate(ilBadge $badge, ?ResourceIdentification $rid)
removeResourceStorageImage(ilBadge $badge)
ilBadgeImage $badge_image_service
static _lookupObjId(int $ref_id)
getNextClass($a_gui_class=null)
static http()
Fetches the global http state from ILIAS.
addBadge(ilPropertyFormGUI $a_form=null)
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:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
static getExtendedTypeCaption(ilBadgeType $a_type)
static getInstancesByBadgeId(int $a_badge_id)
Class ResourceIdentification.
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
getImagePath(bool $a_full_path=true)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const TABLE_ALL_OBJECTS_ACTION
splitBadgeAndUserIdsFromString(array $splittable_user_ids)
clearTargets()
clear all targets
static exists(int $a_badge_id, int $a_user_id)
setMaxNumOfChars(int $a_number)
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This class represents a text area property in a property form.
ILIAS UI Factory $ui_factory
getBadgesFromMultiAction()
getValidBadgesFromClipboard()
awardBadgeUserSelection()
static _lookupType(int $id, bool $reference=false)
setTabs(string $a_active)
selectBadgeForAwardingOrRevoking()
Interface ilCtrlSecurityInterface provides ilCtrl security information.
setImageRid(?string $image_rid)