diff --git a/assets/vue/components/course/CatalogueCourseCard.vue b/assets/vue/components/course/CatalogueCourseCard.vue
index 8c637531bf9..acc36a9f208 100644
--- a/assets/vue/components/course/CatalogueCourseCard.vue
+++ b/assets/vue/components/course/CatalogueCourseCard.vue
@@ -119,6 +119,19 @@
{{ course.extra_fields?.[field.variable] ?? "-" }}
+
+ {{ $t("Students") }}:
+ {{ course.nb_students }} / {{ course.max_students }}
+ ({{ $t("Full") }})
+
+
{
const subscribing = ref(false)
const subscribeToCourse = async () => {
if (!props.currentUserId) {
- showErrorNotification("You must be logged in to subscribe to a course.")
+ showErrorNotification($t("You must be logged in to subscribe to a course."))
return
}
try {
subscribing.value = true
+ const maxUsers = props.course.max_students ?? 0
+ const nbUsers = props.course.nb_students ?? 0
+
+ // Global limit validation (includes teachers and students)
+ if (maxUsers > 0 && nbUsers >= maxUsers) {
+ showErrorNotification(
+ $t("This course has reached the maximum number of users ({nb}/{max}).", {
+ nb: nbUsers,
+ max: maxUsers,
+ })
+ )
+ return
+ }
+
const useAutoSession =
platformConfigStore.getSetting("catalog.course_subscription_in_user_s_session") === "true"
@@ -278,7 +305,7 @@ const subscribeToCourse = async () => {
})
}
- showSuccessNotification("You have successfully subscribed to this course.")
+ showSuccessNotification($t("You have successfully subscribed to this course."))
await router.push({
name: "CourseHome",
@@ -289,7 +316,7 @@ const subscribeToCourse = async () => {
})
} catch (e) {
console.error("Subscription error:", e)
- showErrorNotification("Failed to subscribe to the course.")
+ showErrorNotification($t("Failed to subscribe to the course."))
} finally {
subscribing.value = false
}
diff --git a/public/main/admin/subscribe_user2course.php b/public/main/admin/subscribe_user2course.php
index 8a9d10f158c..bdb79cdbed9 100644
--- a/public/main/admin/subscribe_user2course.php
+++ b/public/main/admin/subscribe_user2course.php
@@ -34,18 +34,29 @@
$htmlHeadXtra[] = '';
// displaying the header
-Display :: display_header($tool_name);
+Display::display_header($tool_name);
$link_add_group = ''.
Display::getMdiIcon(ObjectIcon::MULTI_ELEMENT, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Enrolment by classes')).get_lang('Enrolment by classes').'';
echo Display::toolbarAction('subscribe', [$link_add_group]);
+/**
+ * We show this once at the top so admins are aware before selecting anything.
+ */
+$__globalLimit = (int) api_get_setting('platform.hosting_limit_users_per_course'); // 0 => disabled
+if ($__globalLimit > 0) {
+ echo Display::return_message(
+ sprintf('A global limit of %d users applies to every course (teachers included).', $__globalLimit),
+ 'warning'
+ );
+}
+
$form = new FormValidator('subscribe_user2course');
$form->addElement('header', '', $tool_name);
$form->display();
@@ -56,7 +67,7 @@ function validate_filter() {
$new_field_list = [];
if (is_array($extra_field_list)) {
foreach ($extra_field_list as $extra_field) {
- // if is enabled to filter and is a "