diff --git a/local/o365/lang/en/local_o365.php b/local/o365/lang/en/local_o365.php index 05bba15fa..9130ac6a4 100644 --- a/local/o365/lang/en/local_o365.php +++ b/local/o365/lang/en/local_o365.php @@ -559,6 +559,7 @@ $string['settings_sds_profilesync_desc'] = 'Select the SDS school from which Moodle synchronises SDS specific profile data.
Note synchronisation of SDS fields will only happen when running the "Sync with SDS" scheduled task, and will not happen when running the "Sync users with Azure AD" scheduled task, nor when user logs in.'; $string['settings_sds_noschools'] = '
You do not have any schools available in School data sync.
'; +$string['settings_sds_get_schools_error'] = '
Failed to get SDS schools. Check the Azure app has required permission.
'; // Settings in the "Teams Settings" tab. $string['settings_teams_banner_1'] = 'The Moodle app for Microsoft Teams allows you to easily access and collaborate around your Moodle courses in Teams. The Moodle app also consists of a Moodle Assistant bot, which will send Moodle notifications to students and teachers and answer questions about their courses, assignments, grades and students -- right within Teams!'; diff --git a/local/o365/settings.php b/local/o365/settings.php index 94d65b04e..dd9b59845 100644 --- a/local/o365/settings.php +++ b/local/o365/settings.php @@ -453,91 +453,100 @@ $schools = []; if ($apiclient) { - $schoolresults = $apiclient->get_schools(); - $schools = $schoolresults['value']; - while (!empty($schoolresults['@odata.nextLink'])) { - $nextlink = parse_url($schoolresults['@odata.nextLink']); - $schoolresults = []; - if (isset($nextlink['query'])) { - $query = []; - parse_str($nextlink['query'], $query); - if (isset($query['$skiptoken'])) { - $schoolresults = $apiclient->get_schools($query['$skiptoken']); - $schools = array_merge($schools, $schoolresults['value']); + try { + $schoolresults = $apiclient->get_schools(); + $schools = $schoolresults['value']; + while (!empty($schoolresults['@odata.nextLink'])) { + $nextlink = parse_url($schoolresults['@odata.nextLink']); + $schoolresults = []; + if (isset($nextlink['query'])) { + $query = []; + parse_str($nextlink['query'], $query); + if (isset($query['$skiptoken'])) { + $schoolresults = $apiclient->get_schools($query['$skiptoken']); + $schools = array_merge($schools, $schoolresults['value']); + } } } - } - } - - if (!empty($schools)) { - // SDS course sync school selector header. - $label = new lang_string('settings_sds_coursecreation', 'local_o365'); - $desc = new lang_string('settings_sds_coursecreation_desc', 'local_o365'); - $settings->add(new admin_setting_heading('local_o365_sds_coursecreation', $label, $desc)); - - // SDS course sync school selector. - $label = new lang_string('settings_sds_coursecreation_enabled', 'local_o365'); - $desc = new lang_string('settings_sds_coursecreation_enabled_desc', 'local_o365'); - $coursesyncdefault = []; - $coursesynchoices = []; - $profilesyncchoices = []; - foreach ($schools as $school) { - $coursesynchoices[$school['id']] = $school['displayName']; - $profilesyncchoices[$school['id']] = $school['displayName'] . ' (' . $school['id'] . ')'; - } - $settings->add(new admin_setting_configmulticheckbox('local_o365/sdsschools', $label, $desc, $coursesyncdefault, - $coursesynchoices)); - - // SDS course sync Teams settings. - $label = new lang_string('settings_sds_teams_enabled', 'local_o365'); - $desc = new lang_string('settings_sds_teams_enabled_desc', 'local_o365'); - $settings->add(new admin_setting_configcheckbox('local_o365/sdsteamsenabled', $label, $desc, '0')); - - // SDS course sync enrol settings. - $label = new lang_string('settings_sds_enrolment_enabled', 'local_o365'); - $desc = new lang_string('settings_sds_enrolment_enabled_desc', 'local_o365'); - $settings->add(new admin_setting_configcheckbox('local_o365/sdsenrolmentenabled', $label, $desc, '0')); - - // SDS course sync enrol from Moodle to SDS settings. - $label = new lang_string('settings_sds_sync_enrolment_to_sds', 'local_o365'); - $desc = new lang_string('settings_sds_sync_enrolment_to_sds_desc', 'local_o365'); - $settings->add(new admin_setting_configcheckbox('local_o365/sdssyncenrolmenttosds', $label, $desc, '0')); - - // SDS course sync role selector. - $roleoptions = []; - $courseroles = get_roles_for_contextlevels(CONTEXT_COURSE); - $allroles = get_all_roles(); - foreach ($courseroles as $courserole) { - $role = $allroles[$courserole]; - $roleoptions[$courserole] = role_get_name($role); - } - - // SDS course sync teacher role setting. - $label = new lang_string('settings_sds_enrolment_teacher_role', 'local_o365'); - $desc = new lang_string('settings_sds_enrolment_teacher_role_desc', 'local_o365'); - $settings->add(new admin_setting_configselect('local_o365/sdsenrolmentteacherrole', $label, $desc, 3, $roleoptions)); - - // SDS course sync student role setting. - $label = new lang_string('settings_sds_enrolment_student_role', 'local_o365'); - $desc = new lang_string('settings_sds_enrolment_student_role_desc', 'local_o365'); - $settings->add(new admin_setting_configselect('local_o365/sdsenrolmentstudentrole', $label, $desc, 5, $roleoptions)); - // SDS user profile mapping sync section. - $label = new lang_string('settings_sds_profilesync_header', 'local_o365'); - $desc = new lang_string('settings_sds_profilesync_header_desc', 'local_o365'); - $settings->add(new admin_setting_heading('local_o365_sds_profilesync_header', $label, $desc)); - - // SDS profile sync school selector. - asort($profilesyncchoices); - $profilesyncchoices = ['' => new lang_string('settings_sds_profilesync_disabled', 'local_o365')] + $profilesyncchoices; + if (!empty($schools)) { + // SDS course sync school selector header. + $label = new lang_string('settings_sds_coursecreation', 'local_o365'); + $desc = new lang_string('settings_sds_coursecreation_desc', 'local_o365'); + $settings->add(new admin_setting_heading('local_o365_sds_coursecreation', $label, $desc)); + + // SDS course sync school selector. + $label = new lang_string('settings_sds_coursecreation_enabled', 'local_o365'); + $desc = new lang_string('settings_sds_coursecreation_enabled_desc', 'local_o365'); + $coursesyncdefault = []; + $coursesynchoices = []; + $profilesyncchoices = []; + foreach ($schools as $school) { + $coursesynchoices[$school['id']] = $school['displayName']; + $profilesyncchoices[$school['id']] = $school['displayName'] . ' (' . $school['id'] . ')'; + } + $settings->add(new admin_setting_configmulticheckbox('local_o365/sdsschools', $label, $desc, $coursesyncdefault, + $coursesynchoices)); + + // SDS course sync Teams settings. + $label = new lang_string('settings_sds_teams_enabled', 'local_o365'); + $desc = new lang_string('settings_sds_teams_enabled_desc', 'local_o365'); + $settings->add(new admin_setting_configcheckbox('local_o365/sdsteamsenabled', $label, $desc, '0')); + + // SDS course sync enrol settings. + $label = new lang_string('settings_sds_enrolment_enabled', 'local_o365'); + $desc = new lang_string('settings_sds_enrolment_enabled_desc', 'local_o365'); + $settings->add(new admin_setting_configcheckbox('local_o365/sdsenrolmentenabled', $label, $desc, '0')); + + // SDS course sync enrol from Moodle to SDS settings. + $label = new lang_string('settings_sds_sync_enrolment_to_sds', 'local_o365'); + $desc = new lang_string('settings_sds_sync_enrolment_to_sds_desc', 'local_o365'); + $settings->add(new admin_setting_configcheckbox('local_o365/sdssyncenrolmenttosds', $label, $desc, '0')); + + // SDS course sync role selector. + $roleoptions = []; + $courseroles = get_roles_for_contextlevels(CONTEXT_COURSE); + $allroles = get_all_roles(); + foreach ($courseroles as $courserole) { + $role = $allroles[$courserole]; + $roleoptions[$courserole] = role_get_name($role); + } - $label = new lang_string('settings_sds_profilesync', 'local_o365'); - $desc = new lang_string('settings_sds_profilesync_desc', 'local_o365'); - $settings->add(new admin_setting_configselect('local_o365/sdsprofilesync', $label, $desc, '0', $profilesyncchoices)); - } else { - // SDS no school notification. - $desc = new lang_string('settings_sds_noschools', 'local_o365'); - $settings->add(new admin_setting_heading('local_o365_sds_noschools', '', $desc)); + // SDS course sync teacher role setting. + $label = new lang_string('settings_sds_enrolment_teacher_role', 'local_o365'); + $desc = new lang_string('settings_sds_enrolment_teacher_role_desc', 'local_o365'); + $settings->add(new admin_setting_configselect('local_o365/sdsenrolmentteacherrole', $label, $desc, 3, + $roleoptions)); + + // SDS course sync student role setting. + $label = new lang_string('settings_sds_enrolment_student_role', 'local_o365'); + $desc = new lang_string('settings_sds_enrolment_student_role_desc', 'local_o365'); + $settings->add(new admin_setting_configselect('local_o365/sdsenrolmentstudentrole', $label, $desc, 5, + $roleoptions)); + + // SDS user profile mapping sync section. + $label = new lang_string('settings_sds_profilesync_header', 'local_o365'); + $desc = new lang_string('settings_sds_profilesync_header_desc', 'local_o365'); + $settings->add(new admin_setting_heading('local_o365_sds_profilesync_header', $label, $desc)); + + // SDS profile sync school selector. + asort($profilesyncchoices); + $profilesyncchoices = ['' => new lang_string('settings_sds_profilesync_disabled', 'local_o365')] + + $profilesyncchoices; + + $label = new lang_string('settings_sds_profilesync', 'local_o365'); + $desc = new lang_string('settings_sds_profilesync_desc', 'local_o365'); + $settings->add(new admin_setting_configselect('local_o365/sdsprofilesync', $label, $desc, '0', + $profilesyncchoices)); + } else { + // SDS no school notification. + $desc = new lang_string('settings_sds_noschools', 'local_o365'); + $settings->add(new admin_setting_heading('local_o365_sds_noschools', '', $desc)); + } + } catch (Exception $e) { + $desc = new lang_string('settings_sds_get_schools_error', 'local_o365'); + $settings->add(new admin_setting_heading('local_o365_sds_get_schools_error', '', $desc)); + } } }