Skip to content

Session: Show remaining days instead of dates - refs BT#22640 #6326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions assets/vue/components/course/CourseCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -109,6 +131,10 @@ const teachers = computed(() => {
})

const sessionDisplayDate = computed(() => {
if (daysRemainingText.value) {
return daysRemainingText.value
}

const dateString = []

if (props.session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/CoreBundle/Settings/SessionSettingsSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
)
;
Expand Down Expand Up @@ -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);
Expand Down
Loading