Skip to content

Commit ba540cd

Browse files
Merge pull request #6326 from christianbeeznest/ras-22640
Session: Show remaining days instead of dates - refs BT#22640
2 parents 459ddac + 8da591a commit ba540cd

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

assets/vue/components/course/CourseCard.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { computed } from "vue"
6363
import { isEmpty } from "lodash"
6464
import { useFormatDate } from "../../composables/formatDate"
6565
import { usePlatformConfig } from "../../store/platformConfig"
66+
import { useI18n } from "vue-i18n"
6667
6768
const { abbreviatedDatetime } = useFormatDate()
6869
@@ -91,6 +92,27 @@ const props = defineProps({
9192
const platformConfigStore = usePlatformConfig()
9293
const showCourseDuration = computed(() => "true" === platformConfigStore.getSetting("course.show_course_duration"))
9394
95+
const { t } = useI18n()
96+
97+
const showRemainingDays = computed(() => {
98+
return platformConfigStore.getSetting("session.session_list_view_remaining_days") === "true"
99+
})
100+
101+
const daysRemainingText = computed(() => {
102+
if (!showRemainingDays.value || !props.session?.displayEndDate) return null
103+
104+
const endDate = new Date(props.session.displayEndDate)
105+
if (isNaN(endDate)) return null
106+
107+
const today = new Date()
108+
const diff = Math.floor((endDate - today) / (1000 * 60 * 60 * 24))
109+
110+
if (diff > 1) return `${diff} days remaining`
111+
if (diff === 1) return t("Ends tomorrow")
112+
if (diff === 0) return t("Ends today")
113+
return t("Expired")
114+
})
115+
94116
const teachers = computed(() => {
95117
if (props.session?.courseCoachesSubscriptions) {
96118
return props.session.courseCoachesSubscriptions
@@ -109,6 +131,10 @@ const teachers = computed(() => {
109131
})
110132
111133
const sessionDisplayDate = computed(() => {
134+
if (daysRemainingText.value) {
135+
return daysRemainingText.value
136+
}
137+
112138
const dateString = []
113139
114140
if (props.session) {

src/CoreBundle/Controller/PlatformConfigurationController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function list(SettingsManager $settingsManager): Response
108108
'platform.course_catalog_hide_private',
109109
'course.show_courses_descriptions_in_catalog',
110110
'session.session_automatic_creation_user_id',
111+
'session.session_list_view_remaining_days',
111112
];
112113

113114
$user = $this->userHelper->getCurrent();

src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public static function getExistingSettings(): array
114114
],
115115
],
116116
'session' => [
117+
[
118+
'name' => 'session_list_view_remaining_days',
119+
'title' => 'Show remaining days in My Sessions',
120+
'comment' => 'If enabled, the session dates on the "My Sessions" page will be replaced by the number of remaining days.',
121+
],
117122
[
118123
'name' => 'add_users_by_coach',
119124
'title' => 'Register users by Coach',

src/CoreBundle/Settings/SessionSettingsSchema.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public function buildSettings(AbstractSettingsBuilder $builder): void
8282
'duplicate_specific_session_content_on_session_copy' => 'false',
8383
'enable_auto_reinscription' => 'false',
8484
'enable_session_replication' => 'false',
85+
'session_list_view_remaining_days' => 'false',
8586
]
8687
)
8788
;
@@ -207,6 +208,7 @@ public function buildForm(FormBuilderInterface $builder): void
207208
)
208209
->add('session_model_list_field_ordered_by_id', YesNoType::class)
209210
->add('duplicate_specific_session_content_on_session_copy', YesNoType::class)
211+
->add('session_list_view_remaining_days', YesNoType::class)
210212
;
211213

212214
$this->updateFormFieldsFromSettingsInfo($builder);

0 commit comments

Comments
 (0)