54 private \ILIAS\HTTP\Services
$http;
58 private readonly
int $parent_ref_id,
59 ?
int $a_parent_obj_id =
null,
60 ?
string $a_parent_obj_type =
null 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();
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
79 $this->parent_obj_type = $a_parent_obj_type
95 $DIC->resourceStorage(),
97 $DIC->ui()->mainTemplate()
111 if ($splittable_user_ids !== []) {
112 if ($splittable_user_ids === [
'ALL_OBJECTS']) {
114 if (!$parent_obj_id && $this->parent_ref_id) {
118 if ($this->parent_ref_id) {
122 $badge_id = $this->
http->wrapper()->query()->retrieve(
'bid', $this->
refinery->kindlyTo()->int());
123 return [$user_ids, $badge_id];
125 foreach ($splittable_user_ids as $row) {
126 if (str_contains($row,
'_')) {
127 $split = explode(
'_', $row);
129 if ($badge_id ===
null && $split[0] !==
'') {
130 $badge_id = (
int) $split[0];
133 if ($split[1] !==
'') {
134 $user_ids[] = (
int) $split[1];
137 return [$user_ids, 0];
143 return [$user_ids, $badge_id];
151 $cmd = $ilCtrl->getCmd(
'listBadges');
153 switch ($next_class) {
154 case 'ilpropertyformgui':
156 if ($this->request->getBadgeId()) {
157 $badge =
new ilBadge($this->request->getBadgeId());
158 $type = $badge->getTypeInstance();
163 $type_id = $this->request->getType();
164 $ilCtrl->setParameter($this,
'type', $type_id);
166 $type =
$handler->getTypeInstanceByUniqueId($type_id);
169 $ilCtrl->forwardCommand($form);
173 $render_default =
true;
175 $action_parameter_token =
'tid_id';
176 $parameter =
'tid_table_action';
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())
188 $DIC->ctrl()->setParameter($this,
"tid",
$id);
192 $get = fn(
string $key) => $query->has($key) ?
193 $query->retrieve($key, $DIC->refinery()->kindlyTo()->string()) :
196 $action = $get($parameter);
197 $return_cmd = $get(
'returnCmd');
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',
209 $entry = $actions[$action] ??
null;
210 if ($cmd !==
'action' || !$entry) {
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();
234 protected function setTabs(
string $a_active): void
242 $lng->
txt(
'obj_bdga'),
243 $ilCtrl->getLinkTarget($this,
'listBadges')
249 $ilCtrl->getLinkTarget($this,
'listUsers')
252 $ilTabs->activateSubTab($a_active);
258 return $ilAccess->
checkAccess(
'write',
'', $this->parent_ref_id);
271 $valid_types =
$handler->getAvailableTypesForObjType($this->parent_obj_type);
274 foreach ($valid_types as
$id => $type) {
275 $ilCtrl->setParameter($this,
'type',
$id);
276 $options[
$id] = $this->ui_factory->link()->standard(
278 $ilCtrl->getLinkTarget($this,
'addBadge')
280 $ilCtrl->setParameter($this,
'type',
null);
283 $options = array_values($options);
285 $ilToolbar->addComponent(
286 $this->ui_factory->dropdown()->standard($options)->withLabel($lng->
txt(
'badge_create'))
289 $this->tpl->setOnScreenMessage(
'info', $lng->
txt(
'badge_no_valid_types_for_obj'));
292 $clip_ids = $this->session_repo->getBadgeIds();
293 if (count($clip_ids) > 0) {
295 $ilToolbar->addSeparator();
300 $tt[] = $badge->getTitle();
305 $ilToolbar->addButton(
306 $lng->
txt(
'cont_paste_from_clipboard') .
307 ' (' . count($tt) .
')',
308 $ilCtrl->getLinkTarget($this,
'pasteBadges'),
314 $ilToolbar->addButton(
315 $lng->
txt(
'clear_clipboard'),
316 $ilCtrl->getLinkTarget($this,
'clearClipboard')
322 $this->
ctrl->setParameter($this,
'returnCmd', __FUNCTION__);
323 $table->renderTable(ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getLinkTarget($this,
'action'));
336 $type_id = $this->request->getType();
339 $ilCtrl->redirect($this,
'listBadges');
342 $ilCtrl->setParameter($this,
'type', $type_id);
345 $type =
$handler->getTypeInstanceByUniqueId($type_id);
347 $ilCtrl->redirect($this,
'listBadges');
360 string $a_type_unique_id
366 $form->setFormAction($ilCtrl->getFormAction($this,
'saveBadge'));
367 $form->setTitle($lng->
txt(
'badge_badge') .
' "' . $a_type->
getCaption() .
'"');
370 $form->addItem($active);
373 $title->setMaxLength(255);
374 $title->setRequired(
true);
375 $form->addItem($title);
379 $desc->setRequired(
true);
380 $form->addItem($desc);
384 $crit->setRequired(
true);
385 $form->addItem($crit);
387 if ($a_mode ===
'create') {
392 $img_mode->setValue(
'tmpl');
393 $form->addItem($img_mode);
395 $img_mode_tmpl =
new ilRadioOption($lng->
txt(
'badge_image_from_template'),
'tmpl');
396 $img_mode->addOption($img_mode_tmpl);
398 $img_mode_up =
new ilRadioOption($lng->
txt(
'badge_image_from_upload'),
'up');
399 $img_mode->addOption($img_mode_up);
403 $img_upload->setSuffixes([
'png',
'svg']);
404 $img_mode_up->addSubItem($img_upload);
409 if (count($valid_templates)) {
411 $options[
''] = $lng->
txt(
'please_select');
412 foreach ($valid_templates as $tmpl) {
413 $options[$tmpl->getId()] = $tmpl->getTitle();
418 $tmpl->setOptions($options);
419 $img_mode_tmpl->addSubItem($tmpl);
422 $img_mode_tmpl->setDisabled(
true);
423 $img_mode->setValue(
'up');
428 $img_upload->setAllowDeletion(
false);
429 $img_upload->setUseCache(
false);
430 $form->addItem($img_upload);
434 $valid->setMaxLength(255);
439 $custom->initConfigForm($form, $this->parent_ref_id);
444 if ($a_mode ===
'create') {
445 $form->addCommandButton(
'saveBadge', $lng->
txt(
'save'));
447 $form->addCommandButton(
'updateBadge', $lng->
txt(
'save'));
449 $form->addCommandButton(
'listBadges', $lng->
txt(
'cancel'));
463 $type_id = $this->request->getType();
466 $ilCtrl->redirect($this,
'listBadges');
469 $ilCtrl->setParameter($this,
'type', $type_id);
472 $type =
$handler->getTypeInstanceByUniqueId($type_id);
474 $ilCtrl->redirect($this,
'listBadges');
478 $custom = $type->getConfigGUIInstance();
480 if ($form->checkInput() &&
481 (!$custom || $custom->validateForm($form))) {
483 $badge->setParentId($this->parent_obj_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'));
492 $badge->setConfiguration($custom->getConfigFromForm($form));
497 if ($form->getInput(
'img_mode') ===
'up') {
498 $this->badge_image_service->processImageUpload($badge);
504 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
505 $ilCtrl->redirect($this,
'listBadges');
508 $form->setValuesByPost();
518 $badge_id = $this->request->getBadgeIdFromUrl();
521 $ilCtrl->redirect($this,
'listBadges');
524 $ilCtrl->setParameter($this,
'bid', $badge_id);
526 $badge =
new ilBadge($badge_id);
530 $this->tpl->setOnScreenMessage(
'info', sprintf($lng->
txt(
'badge_edit_with_published'), $static_cnt));
534 $type = $badge->getTypeInstance();
535 $a_form = $this->
initBadgeForm(
'edit', $type, $badge->getTypeId());
554 $image_src = $this->badge_image_service->getImageFromBadge($a_badge);
555 if ($image_src !==
'') {
576 $badge_id = $this->request->getBadgeId();
579 $ilCtrl->redirect($this,
'listBadges');
582 $ilCtrl->setParameter($this,
'bid', $badge_id);
584 $badge =
new ilBadge($badge_id);
585 $type = $badge->getTypeInstance();
586 $custom = $type->getConfigGUIInstance();
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'));
600 $image = $form->getInput(
'img');
601 if (isset($image[
'name']) && $image[
'name'] !==
'') {
603 $this->badge_image_service->processImageUpload($badge);
607 $badge->setConfiguration($custom->getConfigFromForm($form));
609 $tmpl_id = $form->getInput(
'tmpl');
610 if ($tmpl_id !==
'') {
617 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
618 $ilCtrl->redirect($this,
'listBadges');
621 $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
'form_input_not_valid'));
622 $form->setValuesByPost();
633 $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
634 if ($badge_ids === [
'ALL_OBJECTS']) {
637 $badge_ids[] = $badge->getId();
642 $ilTabs->setBackTarget(
644 $ilCtrl->getLinkTarget($this,
'listBadges')
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');
653 foreach ($badge_ids as $badge_id) {
654 $badge =
new ilBadge((
int) $badge_id);
655 $confirmation_gui->addItem(
663 $tpl->
setContent($confirmation_gui->getHTML());
671 $badge_ids = $this->request->getIds();
673 if (count($badge_ids) > 0) {
674 foreach ($badge_ids as $badge_id) {
675 $badge =
new ilBadge((
int) $badge_id);
678 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
680 $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
'badge_select_one'),
true);
683 $ilCtrl->redirect($this,
'listBadges');
698 $badge_ids = $this->request->getIds();
701 $ilCtrl->
redirect($this,
'listBadges');
713 $clip_ids = $this->session_repo->getBadgeIds();
714 $clip_ids = array_unique(
715 array_merge($clip_ids, $badge_ids)
717 $this->session_repo->setBadgeIds(
array_map(intval(...), $clip_ids));
719 $ilCtrl->redirect($this,
'listBadges');
726 $this->session_repo->clear();
727 $ilCtrl->
redirect($this,
'listBadges');
739 foreach ($this->session_repo->getBadgeIds() as $badge_id) {
740 $badge =
new ilBadge($badge_id);
741 if (in_array($badge->getTypeId(), $valid_types,
true)) {
753 $clip_ids = $this->session_repo->getBadgeIds();
754 if (!$this->
hasWrite() || count($clip_ids) === 0) {
755 $ilCtrl->
redirect($this,
'listBadges');
758 $copy_suffix = $this->
lng->txt(
"copy_of_suffix");
760 $badge->copy($this->parent_obj_id, $copy_suffix);
763 $ilCtrl->redirect($this,
'listBadges');
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) {
776 $badge =
new ilBadge($badge->getId());
777 $badge->setActive($a_status);
781 $badge =
new ilBadge((
int) $badge_id);
782 $badge->setActive($a_status);
785 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
788 $this->tpl->setOnScreenMessage(
'failure', $lng->
txt(
'badge_select_one'),
true);
791 $ilCtrl->redirect($this,
'listBadges');
820 $this->parent_obj_id,
821 $this->parent_obj_type
823 if (count($manual)) {
826 $ilToolbar->addInputItem($drop,
true);
828 $ilToolbar->setFormAction($ilCtrl->getFormAction($this,
'selectBadgeForAwardingOrRevoking'));
829 $ilToolbar->addFormButton($lng->
txt(
'badge_award_badge'),
'selectBadgeForAwardingOrRevoking');
834 $this->
ctrl->setParameter($this,
'returnCmd', __FUNCTION__);
835 $tbl->renderTable(ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getLinkTarget($this,
'action'));
840 $this->
ctrl->setParameter(
843 $this->
http->wrapper()->post()->retrieve(
'bid', $this->
refinery->kindlyTo()->int())
845 $this->
ctrl->redirect($this,
'awardBadgeUserSelection');
850 $badge_ids = $this->request->getMultiActionBadgeIdsFromUrl();
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());
859 } elseif (count($badge_ids) === 1) {
860 $bid = (
int) $badge_ids[0];
865 $this->
ctrl->redirect($this,
'listUsers');
868 $manual = array_keys(
872 if (!in_array($bid, $manual,
true)) {
873 $this->
ctrl->redirect($this,
'listUsers');
876 $back_target =
'listUsers';
877 if ($this->request->getTgt() ===
'bdgl') {
878 $this->
ctrl->saveParameter($this,
'tgt');
879 $back_target =
'listBadges';
882 $this->
tabs->clearTargets();
883 $this->
tabs->setBackTarget(
884 $this->
lng->txt(
'back'),
885 $this->
ctrl->getLinkTarget($this, $back_target)
888 $this->
ctrl->setParameter($this,
'bid', $bid);
893 $this->
ctrl->setParameter($this,
'returnCmd', __FUNCTION__);
894 $tbl->renderTable(ILIAS_HTTP_PATH .
'/' . $this->
ctrl->getLinkTarget($this,
'action'));
903 $splittable_user_ids = $this->request->getBadgeAssignableUsers();
909 $ilCtrl->redirect($this,
'listUsers');
916 $ass->setAwardedBy($ilUser->getId());
919 $new_badges[
$user_id][] = $badge_id;
925 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
926 $ilCtrl->redirect($this,
'listUsers');
936 $splittable_user_ids = $this->request->getMultiActionBadgeIdsFromUrl();
942 $ilCtrl->redirect($this,
'listUsers');
945 $ilTabs->clearTargets();
946 $ilTabs->setBackTarget(
948 $ilCtrl->getLinkTarget($this,
'listUsers')
951 $badge =
new ilBadge($badge_id);
953 $ilCtrl->setParameter($this,
'bid', $badge->getId());
956 $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
957 $confirmation_gui->setHeaderText(
958 sprintf($lng->
txt(
'badge_assignment_deletion_confirmation'), $badge->getTitle())
960 $confirmation_gui->setCancel($lng->
txt(
'cancel'),
'listUsers');
961 $confirmation_gui->setConfirm($lng->
txt(
'badge_remove_badge'),
'deassignBadge');
966 if (in_array($user_id, $assigned_users,
true)) {
967 $confirmation_gui->addItem(
975 $tpl->
setContent($confirmation_gui->getHTML());
983 $post_values = $this->request->getIds();
986 foreach ($post_values as $usr_id => $found_badge_id) {
987 $badge_id = $found_badge_id;
988 $user_ids[] = $usr_id;
994 $ilCtrl->redirect($this,
'listUsers');
1002 $this->tpl->setOnScreenMessage(
'success', $lng->
txt(
'settings_saved'),
true);
1003 $ilCtrl->redirect($this,
'listUsers');
1011 if ($rid !==
null) {
1012 $new_rid = $this->badge_image_service->cloneBadgeImageByRid($rid);
1021 $this->resource_storage->manage()->remove(
initBadgeForm(string $a_mode, ilBadgeType $a_type, string $a_type_unique_id)
This class represents an option in a radio group.
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
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
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.
setContent(string $a_html)
Sets content for standard template.
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getNextClass($a_gui_class=null)
static http()
Fetches the global http state from ILIAS.
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...
static getExtendedTypeCaption(ilBadgeType $a_type)
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
addBadge(?ilPropertyFormGUI $a_form=null)
static getInstancesByBadgeId(int $a_badge_id)
Class ResourceIdentification.
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...
editBadge(?ilPropertyFormGUI $a_form=null)
const TABLE_ALL_OBJECTS_ACTION
splitBadgeAndUserIdsFromString(array $splittable_user_ids)
clearTargets()
clear all targets
__construct(private readonly int $parent_ref_id, ?int $a_parent_obj_id=null, ?string $a_parent_obj_type=null)
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()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setImageRid(?string $image_rid)