diff --git a/assets/vue/components/course/CourseCard.vue b/assets/vue/components/course/CourseCard.vue index 66b37b1dc7a..e0778aa63e3 100644 --- a/assets/vue/components/course/CourseCard.vue +++ b/assets/vue/components/course/CourseCard.vue @@ -63,6 +63,7 @@ import { computed } from "vue" import { isEmpty } from "lodash" import { useFormatDate } from "../../composables/formatDate" import { usePlatformConfig } from "../../store/platformConfig" +import { useI18n } from "vue-i18n" const { abbreviatedDatetime } = useFormatDate() @@ -91,6 +92,27 @@ const props = defineProps({ const platformConfigStore = usePlatformConfig() const showCourseDuration = computed(() => "true" === platformConfigStore.getSetting("course.show_course_duration")) +const { t } = useI18n() + +const showRemainingDays = computed(() => { + return platformConfigStore.getSetting("session.session_list_view_remaining_days") === "true" +}) + +const daysRemainingText = computed(() => { + if (!showRemainingDays.value || !props.session?.displayEndDate) return null + + const endDate = new Date(props.session.displayEndDate) + if (isNaN(endDate)) return null + + const today = new Date() + const diff = Math.floor((endDate - today) / (1000 * 60 * 60 * 24)) + + if (diff > 1) return `${diff} days remaining` + if (diff === 1) return t("Ends tomorrow") + if (diff === 0) return t("Ends today") + return t("Expired") +}) + const teachers = computed(() => { if (props.session?.courseCoachesSubscriptions) { return props.session.courseCoachesSubscriptions @@ -109,6 +131,10 @@ const teachers = computed(() => { }) const sessionDisplayDate = computed(() => { + if (daysRemainingText.value) { + return daysRemainingText.value + } + const dateString = [] if (props.session) { diff --git a/src/CoreBundle/Controller/PlatformConfigurationController.php b/src/CoreBundle/Controller/PlatformConfigurationController.php index eca5ecaba43..6a86c0cf13c 100644 --- a/src/CoreBundle/Controller/PlatformConfigurationController.php +++ b/src/CoreBundle/Controller/PlatformConfigurationController.php @@ -108,6 +108,7 @@ public function list(SettingsManager $settingsManager): Response 'platform.course_catalog_hide_private', 'course.show_courses_descriptions_in_catalog', 'session.session_automatic_creation_user_id', + 'session.session_list_view_remaining_days', ]; $user = $this->userHelper->getCurrent(); diff --git a/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php b/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php index e064842c4c0..ac9d2df7475 100644 --- a/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php +++ b/src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php @@ -114,6 +114,11 @@ public static function getExistingSettings(): array ], ], 'session' => [ + [ + 'name' => 'session_list_view_remaining_days', + 'title' => 'Show remaining days in My Sessions', + 'comment' => 'If enabled, the session dates on the "My Sessions" page will be replaced by the number of remaining days.', + ], [ 'name' => 'add_users_by_coach', 'title' => 'Register users by Coach', diff --git a/src/CoreBundle/Settings/SessionSettingsSchema.php b/src/CoreBundle/Settings/SessionSettingsSchema.php index 5fae095c3db..6f8b9c39827 100644 --- a/src/CoreBundle/Settings/SessionSettingsSchema.php +++ b/src/CoreBundle/Settings/SessionSettingsSchema.php @@ -82,6 +82,7 @@ public function buildSettings(AbstractSettingsBuilder $builder): void 'duplicate_specific_session_content_on_session_copy' => 'false', 'enable_auto_reinscription' => 'false', 'enable_session_replication' => 'false', + 'session_list_view_remaining_days' => 'false', ] ) ; @@ -207,6 +208,7 @@ public function buildForm(FormBuilderInterface $builder): void ) ->add('session_model_list_field_ordered_by_id', YesNoType::class) ->add('duplicate_specific_session_content_on_session_copy', YesNoType::class) + ->add('session_list_view_remaining_days', YesNoType::class) ; $this->updateFormFieldsFromSettingsInfo($builder);