Allow course sync to be configured per course
This commit is contained in:
Родитель
df786f1781
Коммит
21967e524e
|
@ -21,6 +21,8 @@
|
|||
* @copyright (C) 2014 onwards Microsoft, Inc. (http://microsoft.com/)
|
||||
*/
|
||||
|
||||
use local_o365\feature\usergroups\utils;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot.'/blocks/microsoft/lib.php');
|
||||
|
@ -77,7 +79,7 @@ class block_microsoft extends block_base {
|
|||
if (!empty($connection) && (auth_oidc_connectioncapability($USER->id, 'connect') ||
|
||||
local_o365_connectioncapability($USER->id, 'link'))) {
|
||||
$uselogin = (!empty($connection->uselogin)) ? true : false;
|
||||
$this->content->text .= $this->get_user_content_matche($connection->aadupn, $uselogin);
|
||||
$this->content->text .= $this->get_user_content_matched($connection->aadupn, $uselogin);
|
||||
} else {
|
||||
$this->content->text .= $this->get_user_content_not_connected();
|
||||
}
|
||||
|
@ -98,22 +100,22 @@ class block_microsoft extends block_base {
|
|||
* @param bool $uselogin Whether the match includes login change.
|
||||
* @return string Block content about user.
|
||||
*/
|
||||
protected function get_user_content_matche($o365account, $uselogin = false) {
|
||||
protected function get_user_content_matched($o365account, $uselogin = false) {
|
||||
$html = '';
|
||||
|
||||
$langmatched = get_string('o365matched_title', 'block_microsoft');
|
||||
$html .= '<h5>'.$langmatched.'</h5>';
|
||||
$html .= '<h5>' . $langmatched . '</h5>';
|
||||
|
||||
$langmatcheddesc = get_string('o365matched_desc', 'block_microsoft', $o365account);
|
||||
$html .= '<p>'.$langmatcheddesc.'</p>';
|
||||
$html .= '<p>' . $langmatcheddesc . '</p>';
|
||||
|
||||
$langlogin = get_string('logintoo365', 'block_microsoft');
|
||||
$html .= '<p>'.get_string('o365matched_complete_authreq', 'block_microsoft').'</p>';
|
||||
$html .= '<p>' . get_string('o365matched_complete_authreq', 'block_microsoft') . '</p>';
|
||||
|
||||
if ($uselogin === true) {
|
||||
$html .= '<p>'. html_writer::link(new moodle_url('/local/o365/ucp.php'), $langlogin).'</p>';
|
||||
$html .= '<p>' . html_writer::link(new moodle_url('/local/o365/ucp.php'), $langlogin) . '</p>';
|
||||
} else {
|
||||
$html .= '<p>'. html_writer::link(new moodle_url('/local/o365/ucp.php?action=connecttoken'), $langlogin).'</p>';
|
||||
$html .= '<p>' . html_writer::link(new moodle_url('/local/o365/ucp.php?action=connecttoken'), $langlogin) . '</p>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
|
@ -132,61 +134,76 @@ class block_microsoft extends block_base {
|
|||
}
|
||||
|
||||
$courseid = $COURSE->id;
|
||||
$groupsenabled = \local_o365\feature\usergroups\utils::is_enabled();
|
||||
$groupsenabled = utils::is_enabled();
|
||||
$iscoursecontext = $PAGE->context instanceof \context_course && $PAGE->context->instanceid !== SITEID;
|
||||
$courseisgroupenabled = \local_o365\feature\usergroups\utils::course_is_group_enabled($courseid);
|
||||
$courseisgroupenabled = utils::course_is_group_enabled($courseid);
|
||||
$config = (array)get_config('block_microsoft');
|
||||
|
||||
$html = '';
|
||||
$items = [];
|
||||
|
||||
$courseheaderdisplayed = false;
|
||||
$o365record = null;
|
||||
|
||||
if (has_capability('local/o365:teamowner', $PAGE->context)) {
|
||||
|
||||
$courseheaderdisplayed = true;
|
||||
}
|
||||
|
||||
if (!empty($config['settings_showcoursegroup'])) {
|
||||
list($courseheader, $o365record) = $this->get_course_header_and_o365object($courseid);
|
||||
$html .= $courseheader;
|
||||
|
||||
// Link to course sync options.
|
||||
if (has_capability('local/o365:teamowner', $PAGE->context)) {
|
||||
$createteams = get_config('local_o365', 'createteams');
|
||||
$allowedmanageteamsyncpercourse = get_config('local_o365', 'createteams_per_course');
|
||||
if ($createteams == 'oncustom' && $allowedmanageteamsyncpercourse) {
|
||||
$configuresyncurl = new moodle_url('/blocks/microsoft/configure_sync.php',
|
||||
['course' => $courseid]);
|
||||
$items[] = html_writer::link($configuresyncurl, get_string('configure_sync', 'block_microsoft'),
|
||||
['class' => 'servicelink block_microsoft_sync']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($iscoursecontext && $groupsenabled && $courseisgroupenabled) {
|
||||
$canmanage = (has_capability('local/o365:managegroups', $PAGE->context) === true) ? true : false;
|
||||
$canview = (is_enrolled($PAGE->context) && has_capability('local/o365:viewgroups', $PAGE->context)) ? true : false;
|
||||
|
||||
if ($canmanage === true || $canview === true) {
|
||||
if (!empty($config['settings_showcoursegroup'])) {
|
||||
if (\local_o365\feature\usergroups\utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
if ($o365record = $DB->get_record('local_o365_objects',
|
||||
['type' => 'group', 'subtype' => 'courseteam', 'moodleid' => $courseid])) {
|
||||
// The course is configured to be connected to a Team, and is connected.
|
||||
$html .= html_writer::tag('h5', get_string('course_connected_to_team', 'block_microsoft'));
|
||||
} else {
|
||||
// The course is configured to be connected to a Team, but the Team cannot be found.
|
||||
$html .= html_writer::tag('h5', get_stirng('course_connected_to_team_missing', 'block_microsoft'));
|
||||
}
|
||||
} else {
|
||||
if ($o365record = $DB->get_record('local_o365_objects',
|
||||
['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid])) {
|
||||
// The course is configured to be connected to a group, and is connected.
|
||||
$html .= html_writer::tag('h5', get_string('course_connected_to_group', 'block_microsoft'));
|
||||
} else {
|
||||
// The course is configured to be connected to a group, but the group cannot be found.
|
||||
$html .= html_writer::tag('h5', get_stirng('course_connected_to_group_missing', 'block_microsoft'));
|
||||
}
|
||||
if (!$courseheaderdisplayed) {
|
||||
list($courseheader, $o365record) = $this->get_course_header_and_o365object($courseid);
|
||||
$html .= $courseheader;
|
||||
}
|
||||
|
||||
if ($o365record) {
|
||||
// Links to course features.
|
||||
$cache = cache::make('local_o365', 'groups');
|
||||
$groupscache = \local_o365\feature\usergroups\utils::get_group_urls($cache, $courseid, 0);
|
||||
$groupurls = utils::get_group_urls($courseid, 0);
|
||||
foreach (['team', 'conversations', 'onedrive', 'calendar', 'notebook'] as $feature) {
|
||||
if (!isset($groupscache['urls'][$feature])) {
|
||||
if (!isset($groupurls[$feature])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = new moodle_url($groupscache['urls'][$feature]);
|
||||
if ($feature == 'team' && !utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$url = new moodle_url($groupurls[$feature]);
|
||||
$resourcename = get_string('course_feature_' . $feature, 'block_microsoft');
|
||||
$items[] = html_writer::link($url, $resourcename,
|
||||
['target' => '_blank', 'class' => 'servicelink block_microsoft_' . $feature]);
|
||||
}
|
||||
|
||||
// Link to configuration.
|
||||
// Link to course reset options.
|
||||
if (has_capability('moodle/course:reset', $PAGE->context)) {
|
||||
switch (get_config('local_o365', 'course_reset_teams')) {
|
||||
case TEAMS_GROUP_COURSE_RESET_SITE_SETTING_PER_COURSE:
|
||||
// Allow user to configure reset actions.
|
||||
$configurereseturl = new moodle_url('/blocks/microsoft/configure_reset.php',
|
||||
['course' => $courseid]);
|
||||
if (\local_o365\feature\usergroups\utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
if (utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
$items[] = html_writer::link($configurereseturl,
|
||||
get_string('configure_reset_team', 'block_microsoft'),
|
||||
['class' => 'servicelink block_microsoft_reset']);
|
||||
|
@ -199,7 +216,7 @@ class block_microsoft extends block_base {
|
|||
break;
|
||||
case TEAMS_GROUP_COURSE_RESET_SITE_SETTING_DISCONNECT:
|
||||
// Force archive, show notification.
|
||||
if (\local_o365\feature\usergroups\utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
if (utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
$items[] = html_writer::span(get_string('course_reset_disconnect_team', 'block_microsoft'),
|
||||
'servicelink block_microsoft_reset');
|
||||
} else {
|
||||
|
@ -210,7 +227,7 @@ class block_microsoft extends block_base {
|
|||
break;
|
||||
default:
|
||||
// Force do nothing, show notification.
|
||||
if (\local_o365\feature\usergroups\utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
if (utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
$items[] = html_writer::span(get_string('course_reset_do_nothing_team', 'block_microsoft'),
|
||||
'servicelink block_microsoft_reset');
|
||||
} else {
|
||||
|
@ -227,6 +244,43 @@ class block_microsoft extends block_base {
|
|||
return $html . html_writer::alist($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the course header text and o365_object record for the course with the given ID.
|
||||
*
|
||||
* @param int $courseid
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_course_header_and_o365object(int $courseid) {
|
||||
global $DB;
|
||||
|
||||
$o365record = null;
|
||||
|
||||
if (utils::course_is_group_feature_enabled($courseid, 'team')) {
|
||||
if ($o365record = $DB->get_record('local_o365_objects',
|
||||
['type' => 'group', 'subtype' => 'courseteam', 'moodleid' => $courseid])) {
|
||||
// The course is configured to be connected to a Team, and is connected.
|
||||
$html = html_writer::tag('h5', get_string('course_connected_to_team', 'block_microsoft'));
|
||||
} else {
|
||||
// The course is configured to be connected to a Team, but the Team cannot be found.
|
||||
$html = html_writer::tag('h5', get_string('course_connected_to_team_missing', 'block_microsoft'));
|
||||
}
|
||||
} else if (utils::course_is_group_enabled($courseid)) {
|
||||
if ($o365record = $DB->get_record('local_o365_objects',
|
||||
['type' => 'group', 'subtype' => 'course', 'moodleid' => $courseid])) {
|
||||
// The course is configured to be connected to a group, and is connected.
|
||||
$html = html_writer::tag('h5', get_string('course_connected_to_group', 'block_microsoft'));
|
||||
} else {
|
||||
// The course is configured to be connected to a group, but the group cannot be found.
|
||||
$html = html_writer::tag('h5', get_string('course_connected_to_group_missing', 'block_microsoft'));
|
||||
}
|
||||
} else {
|
||||
$html = html_writer::tag('h5', get_string('course_not_connected', 'block_microsoft'));
|
||||
}
|
||||
|
||||
return [$html, $o365record];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content for a connected user.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This page allow authorised users to configure course sync to Teams/group.
|
||||
*
|
||||
* @package block_microsoft
|
||||
* @author Lai Wei <lai.wei@enovation.ie>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @copyright (C) 2021 onwards Microsoft, Inc. (http://microsoft.com/)
|
||||
*/
|
||||
|
||||
require_once(__DIR__.'/../../config.php');
|
||||
require_once($CFG->dirroot . '/blocks/microsoft/forms.php');
|
||||
require_once($CFG->dirroot . '/blocks/microsoft/lib.php');
|
||||
require_once($CFG->dirroot . '/local/o365/lib.php');
|
||||
|
||||
$courseid = required_param('course', PARAM_INT);
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
|
||||
require_login($courseid);
|
||||
|
||||
require_capability('local/o365:teamowner', $coursecontext);
|
||||
|
||||
$PAGE->set_context($coursecontext);
|
||||
|
||||
$redirecturl = new moodle_url('/course/view.php', ['id' => $courseid]);
|
||||
|
||||
// Validations.
|
||||
$sitecoursesyncconfig = get_config('local_o365', 'createteams');
|
||||
if ($sitecoursesyncconfig != 'oncustom') {
|
||||
print_error('error_course_sync_not_configurable_per_course', 'block_microsoft', $redirecturl);
|
||||
}
|
||||
|
||||
if (!get_config('local_o365', 'createteams_per_course')) {
|
||||
print_error('error_course_sync_not_configurable_per_course', 'block_microsoft', $redirecturl);
|
||||
}
|
||||
|
||||
$formdata = [
|
||||
'course' => $courseid,
|
||||
'sync' => block_microsoft_get_course_sync_option($courseid),
|
||||
];
|
||||
|
||||
$mform = new block_microsoft_course_sync_form();
|
||||
$mform->set_data($formdata);
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($redirecturl);
|
||||
} else if ($fromform = $mform->get_data()) {
|
||||
block_microsoft_set_course_sync_option($fromform->course, $fromform->sync);
|
||||
|
||||
redirect($redirecturl, get_string('sync_setting_saved', 'block_microsoft'));
|
||||
}
|
||||
|
||||
$pagetitle = get_string('configure_course_sync', 'block_microsoft');
|
||||
$PAGE->set_url('/blocks/microsoft/configure_sync.php', ['course' => $courseid]);
|
||||
$PAGE->navbar->add($pagetitle);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_title($pagetitle);
|
||||
$PAGE->set_heading($pagetitle);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('sync_page_heading', 'block_microsoft', $COURSE->fullname));
|
||||
|
||||
$mform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
27
forms.php
27
forms.php
|
@ -28,6 +28,33 @@ defined('MOODLE_INTERNAL') || die();
|
|||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->dirroot . '/local/o365/lib.php');
|
||||
|
||||
/**
|
||||
* Class block_microsoft_course_sync_form.
|
||||
* Form to configure course sync options.
|
||||
*/
|
||||
class block_microsoft_course_sync_form extends moodleform {
|
||||
/**
|
||||
* Form definition.
|
||||
*/
|
||||
protected function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('hidden', 'course');
|
||||
$mform->setType('course', PARAM_INT);
|
||||
|
||||
// Sync options.
|
||||
$syncoptions = [
|
||||
MICROSOFT365_COURSE_SYNC_NONE => get_string('course_sync_option_not_synced', 'block_microsoft'),
|
||||
MICROSOFT365_COURSE_SYNC_GROUPS => get_string('course_sync_option_groups', 'block_microsoft'),
|
||||
MICROSOFT365_COURSE_SYNC_TEAMS => get_string('course_sync_option_teams', 'block_microsoft'),
|
||||
];
|
||||
$mform->addElement('select', 'sync', get_string('course_sync_option', 'block_microsoft'), $syncoptions);
|
||||
$mform->setDefault('sync', MICROSOFT365_COURSE_SYNC_NONE);
|
||||
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class block_microsoft_course_configure_team_form.
|
||||
* Form to configure course Team reset actions.
|
||||
|
|
|
@ -55,6 +55,7 @@ $string['course_connected_to_team'] = 'The course is <span class="notifysuccess"
|
|||
$string['course_connected_to_team_missing'] = 'The course is configured to be connected to a <b>Team</b>, but the Team is <span class="notifyproblem">not found</span>.';
|
||||
$string['course_connected_to_group'] = 'The course is <span class="notifysuccess">connected</span> to a <b>group</b>.';
|
||||
$string['course_connected_to_group_missing'] = 'The course is configured to be connected to a <b>group</b>, but the group is <span class="notifyproblem">not found</span>.';
|
||||
$string['course_not_connected'] = 'The course is <span class="notifyproblem">not connected</span> to any Microsoft services.';
|
||||
$string['cachedef_onenotenotebook'] = 'Stores OneNote notebook.';
|
||||
$string['cachedef_groups'] = 'Caches Microsoft 365 group information.';
|
||||
$string['msalogin'] = 'Log in with Microsoft Account';
|
||||
|
@ -110,6 +111,17 @@ $string['course_feature_onedrive'] = 'OneDrive files';
|
|||
$string['course_feature_calendar'] = 'Outlook calendar';
|
||||
$string['course_feature_notebook'] = 'Class notebook';
|
||||
|
||||
// Course sync settings.
|
||||
$string['configure_sync'] = 'Configure course sync';
|
||||
$string['error_course_sync_not_configurable_per_course'] = 'Teams/Groups sync cannot be configured per course.';
|
||||
$string['sync_page_heading'] = 'Sync course {$a} to Microsoft 365 Teams/Groups';
|
||||
$string['configure_course_sync'] = 'Configure course sync to Microsoft 365 Teams/Groups';
|
||||
$string['course_sync_option'] = 'Sync option';
|
||||
$string['course_sync_option_not_synced'] = 'Not synced';
|
||||
$string['course_sync_option_groups'] = 'Microsoft 365 Groups only';
|
||||
$string['course_sync_option_teams'] = 'Microsoft 365 Teams';
|
||||
$string['sync_setting_saved'] = 'Course sync option is saved';
|
||||
|
||||
// Course reset status.
|
||||
$string['course_reset_disconnect_team'] = 'When the course is reset, the Team connected to the course will be renamed as configured, and archived. A new Team will be created and connected to the course.';
|
||||
$string['course_reset_disconnect_group'] = 'When the course is reset, the group connected to the course will be renamed as configured. A new group will be created and connected to the course.';
|
||||
|
|
55
lib.php
55
lib.php
|
@ -23,8 +23,63 @@
|
|||
* @copyright (C) 2021 onwards Microsoft Open Technologies, Inc. (http://msopentech.com/)
|
||||
*/
|
||||
|
||||
use local_o365\feature\usergroups\utils;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/local/o365/lib.php');
|
||||
|
||||
/**
|
||||
* Return the course sync option of the course with the given ID.
|
||||
*
|
||||
* @param int $courseid
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function block_microsoft_get_course_sync_option(int $courseid) {
|
||||
$coursesyncoption = MICROSOFT365_COURSE_SYNC_NONE;
|
||||
|
||||
$groupsyncenabledcourseids = utils::get_enabled_courses();
|
||||
$teamsyncenabledcourseids = utils::get_enabled_courses_with_feature('team');
|
||||
|
||||
if ($teamsyncenabledcourseids === true || $groupsyncenabledcourseids === true) {
|
||||
// Sync is enabled on all courses.
|
||||
$coursesyncoption = MICROSOFT365_COURSE_SYNC_TEAMS;
|
||||
} else if (in_array($courseid, $groupsyncenabledcourseids)) {
|
||||
if (in_array($courseid, $teamsyncenabledcourseids)) {
|
||||
$coursesyncoption = MICROSOFT365_COURSE_SYNC_TEAMS;
|
||||
} else {
|
||||
$coursesyncoption = MICROSOFT365_COURSE_SYNC_GROUPS;
|
||||
}
|
||||
}
|
||||
|
||||
return $coursesyncoption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set course sync options.
|
||||
*
|
||||
* @param int $courseid
|
||||
* @param int $syncsetting
|
||||
*/
|
||||
function block_microsoft_set_course_sync_option(int $courseid, int $syncsetting) {
|
||||
switch ($syncsetting) {
|
||||
case MICROSOFT365_COURSE_SYNC_GROUPS:
|
||||
utils::set_course_group_enabled($courseid);
|
||||
utils::set_course_group_feature_enabled($courseid, ['team'], false);
|
||||
|
||||
break;
|
||||
case MICROSOFT365_COURSE_SYNC_TEAMS:
|
||||
utils::set_course_group_enabled($courseid);
|
||||
utils::set_course_group_feature_enabled($courseid, ['team']);
|
||||
|
||||
break;
|
||||
default:
|
||||
utils::set_course_group_feature_enabled($courseid, ['team'], false);
|
||||
utils::set_course_group_enabled($courseid, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the existing course reset setting of the course with the given ID.
|
||||
*
|
||||
|
|
|
@ -77,6 +77,9 @@
|
|||
.block_microsoft_notebook {
|
||||
background-image: url([[pix:block_microsoft|onenotecolor]]);
|
||||
}
|
||||
.block_microsoft_sync {
|
||||
background-image: url([[pix:moodle|i/settings]]);
|
||||
}
|
||||
.block_microsoft_reset {
|
||||
background-image: url([[pix:moodle|t/reset]]);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,8 @@
|
|||
background-image: url([[pix:block_microsoft|calendar]]); }
|
||||
.block_microsoft .block_microsoft_notebook {
|
||||
background-image: url([[pix:block_microsoft|onenotecolor]]); }
|
||||
.block_microsoft .block_microsoft_sync {
|
||||
background-image: url([[pix:moodle|i/settings]]); }
|
||||
.block_microsoft .block_microsoft_reset {
|
||||
background-image: url([[pix:moodle|t/reset]]); }
|
||||
.block_microsoft .block_microsoft_profile {
|
||||
|
|
Загрузка…
Ссылка в новой задаче