Skip to content

Commit

Permalink
Merge branch 'wip-80351-m311' into MOODLE_311_STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
weilai-irl committed Dec 9, 2021
2 parents 7480b20 + 62ea380 commit 8f24481
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 81 deletions.
1 change: 1 addition & 0 deletions local/o365/lang/en/local_o365.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@
$string['settings_sds_profilesync_desc'] = 'Select the SDS school from which Moodle synchronises SDS specific profile data.<br/>
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'] = '<div class="alert alert-info">You do not have any schools available in School data sync.</div>';
$string['settings_sds_get_schools_error'] = '<div class="alert alert-info error">Failed to get SDS schools. Check the Azure app has required permission.</div>';

// Settings in the "Teams Settings" tab.
$string['settings_teams_banner_1'] = 'The Moodle app for <a href="https://aka.ms/MoodleLearnTeams" target="_blank">Microsoft Teams</a> 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!';
Expand Down
171 changes: 90 additions & 81 deletions local/o365/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

Expand Down

0 comments on commit 8f24481

Please sign in to comment.