Skip to content

Commit 3dddf12

Browse files
Merge pull request #7427 from christianbeeznest/GH-7412
Course: Improve course settings form defaults and UI behavior - refs #7412
2 parents 33a7b73 + 6fd609f commit 3dddf12

1 file changed

Lines changed: 66 additions & 4 deletions

File tree

public/main/course_info/infocours.php

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
get_lang('Delete picture')
181181
);
182182

183-
184183
if ('true' === api_get_setting('pdf_export_watermark_by_course')) {
185184
$url = PDF::get_watermark($course_code);
186185
$form->addText('pdf_export_watermark_text', get_lang('PDF watermark text'), false, ['size' => '60']);
@@ -256,7 +255,6 @@
256255
true
257256
);
258257

259-
260258
// --- End of legacy block, from here panels start as usual ---
261259

262260
$url = api_get_path(WEB_CODE_PATH)."auth/inscription.php?c=$course_code&e=1";
@@ -1066,6 +1064,58 @@
10661064
),
10671065
];
10681066

1067+
// ---------------------------------------------------------------------
1068+
// Default values
1069+
// When a course setting is not stored yet, api_get_course_setting() returns -1.
1070+
// We still want radios/selects to have a clear default selected in the UI.
1071+
// This does NOT write anything to the database; it only affects form defaults.
1072+
// ---------------------------------------------------------------------
1073+
$defaultCourseSettings = [
1074+
// Documents (only used if the corresponding platform setting enables these fields)
1075+
'documents_default_visibility' => 'visible',
1076+
'show_system_folders' => 1,
1077+
1078+
// E-mail notifications (default to disabled)
1079+
'email_alert_to_teacher_on_new_user_in_course' => 0,
1080+
'email_alert_student_on_manual_subscription' => 0,
1081+
'email_alert_students_on_new_homework' => 0,
1082+
'email_alert_manager_on_new_doc' => 0,
1083+
'email_alert_on_new_doc_dropbox' => 0,
1084+
'email_to_teachers_on_new_work_feedback' => 2, // Yes=1, No=2
1085+
1086+
// User rights (default to disabled)
1087+
'allow_user_edit_agenda' => 0,
1088+
'allow_user_edit_announcement' => 0,
1089+
'allow_user_image_forum' => 0,
1090+
'allow_user_view_user_list' => 0,
1091+
1092+
// Chat settings
1093+
'allow_open_chat_window' => 0,
1094+
1095+
// Learning path settings
1096+
'allow_learning_path_theme' => 0,
1097+
'lp_return_link' => 0, // Redirect to Course home
1098+
'exercise_invisible_in_session' => 0,
1099+
1100+
// Thematic
1101+
'display_info_advance_inside_homecourse' => 0,
1102+
1103+
// Certificates
1104+
'allow_public_certificates' => 0,
1105+
1106+
// Forum settings (Yes=1, No=2)
1107+
'hide_forum_notifications' => 2,
1108+
'subscribe_users_to_forum_notifications' => 2,
1109+
1110+
// Assignments / Student publications
1111+
'show_score' => 0,
1112+
'student_delete_own_publication' => 0,
1113+
1114+
// Auto-launch (UI helper radio)
1115+
'auto_launch_option' => 'disable_auto_launch',
1116+
'show_course_in_user_language' => 2,
1117+
];
1118+
10691119
// Set default values
10701120
$values = [];
10711121
$values['title'] = $courseEntity->getTitle();
@@ -1083,8 +1133,16 @@
10831133
$courseSettings = CourseManager::getCourseSettingVariables();
10841134
foreach ($courseSettings as $setting) {
10851135
$result = api_get_course_setting($setting);
1086-
if ('-1' != $result) {
1136+
1137+
// Stored setting: use it.
1138+
if ('-1' !== (string) $result) {
10871139
$values[$setting] = $result;
1140+
continue;
1141+
}
1142+
1143+
// Not stored yet: fallback to UI defaults when available.
1144+
if (!array_key_exists($setting, $values) && array_key_exists($setting, $defaultCourseSettings)) {
1145+
$values[$setting] = $defaultCourseSettings[$setting];
10881146
}
10891147
}
10901148

@@ -1097,6 +1155,7 @@
10971155
$values['email_alert_student_on_manual_subscription'] = 0;
10981156
}
10991157

1158+
// Auto-launch: compute the selected UI option from stored flags
11001159
$documentAutoLaunch = api_get_course_setting('enable_document_auto_launch');
11011160
$lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
11021161
$exerciseAutoLaunch = api_get_course_setting('enable_exercise_auto_launch');
@@ -1119,9 +1178,12 @@
11191178

11201179
$values['auto_launch_option'] = $defaultAutoLaunchOption;
11211180

1181+
// AI helpers: api_get_course_setting() can also return -1 for new courses.
1182+
// We want radios to default to "No" ("false") to avoid an empty state.
11221183
if ($enableAiHelpers) {
11231184
foreach ($aiOptions as $key => $label) {
1124-
$values[$key] = api_get_course_setting($key);
1185+
$v = api_get_course_setting($key);
1186+
$values[$key] = ('-1' === (string) $v || $v === null || $v === '') ? 'false' : (string) $v;
11251187
}
11261188
}
11271189

0 commit comments

Comments
 (0)