mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Merge branch 'w37_MDL-27856_m24_cohortrestore' of git://github.com/skodak/moodle
This commit is contained in:
commit
b01c955fef
12 changed files with 148 additions and 82 deletions
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
// This file is part of Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
@ -18,8 +17,7 @@
|
||||||
/**
|
/**
|
||||||
* Adds new instance of enrol_cohort to specified course.
|
* Adds new instance of enrol_cohort to specified course.
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -28,7 +26,7 @@ require('../../config.php');
|
||||||
require_once("$CFG->dirroot/enrol/cohort/addinstance_form.php");
|
require_once("$CFG->dirroot/enrol/cohort/addinstance_form.php");
|
||||||
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
|
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
|
||||||
|
|
||||||
$id = required_param('id', PARAM_INT); // course id
|
$id = required_param('id', PARAM_INT); // Course id.
|
||||||
|
|
||||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||||
$context = context_course::instance($course->id, MUST_EXIST);
|
$context = context_course::instance($course->id, MUST_EXIST);
|
||||||
|
@ -42,7 +40,7 @@ $PAGE->set_pagelayout('admin');
|
||||||
|
|
||||||
navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
|
navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
|
||||||
|
|
||||||
// Try and make the manage instances node on the navigation active
|
// Try and make the manage instances node on the navigation active.
|
||||||
$courseadmin = $PAGE->settingsnav->get('courseadmin');
|
$courseadmin = $PAGE->settingsnav->get('courseadmin');
|
||||||
if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) {
|
if ($courseadmin && $courseadmin->get('users') && $courseadmin->get('users')->get('manageinstances')) {
|
||||||
$courseadmin->get('users')->get('manageinstances')->make_active();
|
$courseadmin->get('users')->get('manageinstances')->make_active();
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
// This file is part of Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
@ -18,8 +17,7 @@
|
||||||
/**
|
/**
|
||||||
* Adds instance form
|
* Adds instance form
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -29,17 +27,20 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
require_once("$CFG->libdir/formslib.php");
|
require_once("$CFG->libdir/formslib.php");
|
||||||
|
|
||||||
class enrol_cohort_addinstance_form extends moodleform {
|
class enrol_cohort_addinstance_form extends moodleform {
|
||||||
|
|
||||||
|
protected $course;
|
||||||
|
|
||||||
function definition() {
|
function definition() {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
$mform = $this->_form;
|
$mform = $this->_form;
|
||||||
$course = $this->_customdata;
|
$this->course = $this->_customdata;
|
||||||
$coursecontext = context_course::instance($course->id);
|
$coursecontext = context_course::instance($this->course->id);
|
||||||
|
|
||||||
$enrol = enrol_get_plugin('cohort');
|
$enrol = enrol_get_plugin('cohort');
|
||||||
|
|
||||||
$cohorts = array('' => get_string('choosedots'));
|
$cohorts = array('' => get_string('choosedots'));
|
||||||
list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext));
|
list($sqlparents, $params) = $DB->get_in_or_equal($coursecontext->get_parent_context_ids());
|
||||||
$sql = "SELECT id, name, contextid
|
$sql = "SELECT id, name, contextid
|
||||||
FROM {cohort}
|
FROM {cohort}
|
||||||
WHERE contextid $sqlparents
|
WHERE contextid $sqlparents
|
||||||
|
@ -56,7 +57,7 @@ class enrol_cohort_addinstance_form extends moodleform {
|
||||||
|
|
||||||
$roles = get_assignable_roles($coursecontext);
|
$roles = get_assignable_roles($coursecontext);
|
||||||
$roles[0] = get_string('none');
|
$roles[0] = get_string('none');
|
||||||
$roles = array_reverse($roles, true); // descending default sortorder
|
$roles = array_reverse($roles, true); // Descending default sortorder.
|
||||||
|
|
||||||
$mform->addElement('header','general', get_string('pluginname', 'enrol_cohort'));
|
$mform->addElement('header','general', get_string('pluginname', 'enrol_cohort'));
|
||||||
|
|
||||||
|
@ -72,8 +73,18 @@ class enrol_cohort_addinstance_form extends moodleform {
|
||||||
|
|
||||||
$this->add_action_buttons(true, get_string('addinstance', 'enrol'));
|
$this->add_action_buttons(true, get_string('addinstance', 'enrol'));
|
||||||
|
|
||||||
$this->set_data(array('id'=>$course->id));
|
$this->set_data(array('id'=>$this->course->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: validate duplicate role-cohort does not exist
|
function validation($data, $files) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
$errors = parent::validation($data, $files);
|
||||||
|
|
||||||
|
if ($DB->record_exists('enrol', array('roleid'=>$data['roleid'], 'customint1'=>$data['cohortid'], 'courseid'=>$this->course->id, 'enrol'=>'cohort'))) {
|
||||||
|
$errors['cohortid'] = get_string('instanceexists', 'enrol_cohort');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
* The general idea behind this file is that any errors should throw exceptions
|
* The general idea behind this file is that any errors should throw exceptions
|
||||||
* which will be returned and acted upon by the calling AJAX script.
|
* which will be returned and acted upon by the calling AJAX script.
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2011 Sam Hemelryk
|
* @copyright 2011 Sam Hemelryk
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -33,7 +32,7 @@ require_once($CFG->dirroot.'/enrol/locallib.php');
|
||||||
require_once($CFG->dirroot.'/enrol/cohort/locallib.php');
|
require_once($CFG->dirroot.'/enrol/cohort/locallib.php');
|
||||||
require_once($CFG->dirroot.'/group/lib.php');
|
require_once($CFG->dirroot.'/group/lib.php');
|
||||||
|
|
||||||
// Must have the sesskey
|
// Must have the sesskey.
|
||||||
$id = required_param('id', PARAM_INT); // course id
|
$id = required_param('id', PARAM_INT); // course id
|
||||||
$action = required_param('action', PARAM_ALPHANUMEXT);
|
$action = required_param('action', PARAM_ALPHANUMEXT);
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ require_login($course);
|
||||||
require_capability('moodle/course:enrolreview', $context);
|
require_capability('moodle/course:enrolreview', $context);
|
||||||
require_sesskey();
|
require_sesskey();
|
||||||
|
|
||||||
echo $OUTPUT->header(); // send headers
|
echo $OUTPUT->header(); // Send headers.
|
||||||
|
|
||||||
$manager = new course_enrolment_manager($PAGE, $course);
|
$manager = new course_enrolment_manager($PAGE, $course);
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,7 @@
|
||||||
* - you need to change the "www-data" to match the apache user account
|
* - you need to change the "www-data" to match the apache user account
|
||||||
* - use "su" if "sudo" not available
|
* - use "su" if "sudo" not available
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2011 Petr Skoda {@link http://skodak.org}
|
* @copyright 2011 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +34,7 @@ require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
|
||||||
require_once($CFG->libdir.'/clilib.php');
|
require_once($CFG->libdir.'/clilib.php');
|
||||||
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
|
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
|
||||||
|
|
||||||
// now get cli options
|
// Now get cli options.
|
||||||
list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help'));
|
list($options, $unrecognized) = cli_get_params(array('verbose'=>false, 'help'=>false), array('v'=>'verbose', 'h'=>'help'));
|
||||||
|
|
||||||
if ($unrecognized) {
|
if ($unrecognized) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ $capabilities = array(
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
/* This is used only when sync suspends users instead of full unenrolment */
|
/* This is used only when sync suspends users instead of full unenrolment. */
|
||||||
'enrol/cohort:unenrol' => array(
|
'enrol/cohort:unenrol' => array(
|
||||||
|
|
||||||
'captype' => 'write',
|
'captype' => 'write',
|
||||||
|
@ -47,8 +47,3 @@ $capabilities = array(
|
||||||
),
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
/* List of handlers */
|
/* List of handlers. */
|
||||||
$handlers = array (
|
$handlers = array (
|
||||||
'cohort_member_added' => array (
|
'cohort_member_added' => array (
|
||||||
'handlerfile' => '/enrol/cohort/locallib.php',
|
'handlerfile' => '/enrol/cohort/locallib.php',
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
/**
|
/**
|
||||||
* Meta link enrolment plugin uninstallation.
|
* Meta link enrolment plugin uninstallation.
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2011 Petr Skoda {@link http://skodak.org}
|
* @copyright 2011 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// This file is part of Moodle - http://moodle.org/
|
// This file is part of Moodle - http://moodle.org/
|
||||||
//
|
//
|
||||||
// Moodle is free software: you can redistribute it and/or modify
|
// Moodle is free software: you can redistribute it and/or modify
|
||||||
|
@ -16,10 +15,9 @@
|
||||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strings for component 'enrol_cohort', language 'en', branch 'MOODLE_20_STABLE'
|
* Strings for component 'enrol_cohort', language 'en'
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -28,5 +26,6 @@ $string['ajaxmore'] = 'More...';
|
||||||
$string['cohortsearch'] = 'Search';
|
$string['cohortsearch'] = 'Search';
|
||||||
$string['cohort:config'] = 'Configure cohort instances';
|
$string['cohort:config'] = 'Configure cohort instances';
|
||||||
$string['cohort:unenrol'] = 'Unenrol suspended users';
|
$string['cohort:unenrol'] = 'Unenrol suspended users';
|
||||||
|
$string['instanceexists'] = 'Cohort is already synchronised with selected role';
|
||||||
$string['pluginname'] = 'Cohort sync';
|
$string['pluginname'] = 'Cohort sync';
|
||||||
$string['pluginname_desc'] = 'Cohort enrolment plugin synchronises cohort members with course participants.';
|
$string['pluginname_desc'] = 'Cohort enrolment plugin synchronises cohort members with course participants.';
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
/**
|
/**
|
||||||
* Cohort enrolment plugin.
|
* Cohort enrolment plugin.
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -32,9 +31,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||||
*/
|
*/
|
||||||
class enrol_cohort_plugin extends enrol_plugin {
|
class enrol_cohort_plugin extends enrol_plugin {
|
||||||
/**
|
/**
|
||||||
* Returns localised name of enrol instance
|
* Returns localised name of enrol instance.
|
||||||
*
|
*
|
||||||
* @param object $instance (null is accepted too)
|
* @param stdClass $instance (null is accepted too)
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_instance_name($instance) {
|
public function get_instance_name($instance) {
|
||||||
|
@ -67,12 +66,12 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||||
if (!$this->can_add_new_instances($courseid)) {
|
if (!$this->can_add_new_instances($courseid)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// multiple instances supported - multiple parent courses linked
|
// Multiple instances supported - multiple parent courses linked.
|
||||||
return new moodle_url('/enrol/cohort/addinstance.php', array('id'=>$courseid));
|
return new moodle_url('/enrol/cohort/addinstance.php', array('id'=>$courseid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a courseid this function returns true if the user is able to enrol or configure cohorts
|
* Given a courseid this function returns true if the user is able to enrol or configure cohorts.
|
||||||
* AND there are cohorts that the user can view.
|
* AND there are cohorts that the user can view.
|
||||||
*
|
*
|
||||||
* @param int $courseid
|
* @param int $courseid
|
||||||
|
@ -100,7 +99,6 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called for all enabled enrol plugins that returned true from is_cron_required().
|
* Called for all enabled enrol plugins that returned true from is_cron_required().
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -116,8 +114,8 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||||
* Called after updating/inserting course.
|
* Called after updating/inserting course.
|
||||||
*
|
*
|
||||||
* @param bool $inserted true if course just inserted
|
* @param bool $inserted true if course just inserted
|
||||||
* @param object $course
|
* @param stdClass $course
|
||||||
* @param object $data form data
|
* @param stdClass $data form data
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function course_updated($inserted, $course, $data) {
|
public function course_updated($inserted, $course, $data) {
|
||||||
|
@ -158,7 +156,7 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an array of the user enrolment actions
|
* Gets an array of the user enrolment actions.
|
||||||
*
|
*
|
||||||
* @param course_enrolment_manager $manager
|
* @param course_enrolment_manager $manager
|
||||||
* @param stdClass $ue A user enrolment object
|
* @param stdClass $ue A user enrolment object
|
||||||
|
@ -210,7 +208,7 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||||
$button->strings_for_js('cohort', 'cohort');
|
$button->strings_for_js('cohort', 'cohort');
|
||||||
$button->strings_for_js('users', 'moodle');
|
$button->strings_for_js('users', 'moodle');
|
||||||
|
|
||||||
// No point showing this at all if the user cant manually enrol users
|
// No point showing this at all if the user cant manually enrol users.
|
||||||
$hasmanualinstance = has_capability('enrol/manual:enrol', $manager->get_context()) && $manager->has_instance('manual');
|
$hasmanualinstance = has_capability('enrol/manual:enrol', $manager->get_context()) && $manager->has_instance('manual');
|
||||||
|
|
||||||
$modules = array('moodle-enrol_cohort-quickenrolment', 'moodle-enrol_cohort-quickenrolment-skin');
|
$modules = array('moodle-enrol_cohort-quickenrolment', 'moodle-enrol_cohort-quickenrolment-skin');
|
||||||
|
@ -224,6 +222,78 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||||
|
|
||||||
return $button;
|
return $button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore instance and map settings.
|
||||||
|
*
|
||||||
|
* @param restore_enrolments_structure_step $step
|
||||||
|
* @param stdClass $data
|
||||||
|
* @param stdClass $course
|
||||||
|
* @param int $oldid
|
||||||
|
*/
|
||||||
|
public function restore_instance(restore_enrolments_structure_step $step, stdClass $data, $course, $oldid) {
|
||||||
|
global $DB, $CFG;
|
||||||
|
|
||||||
|
if (!$step->get_task()->is_samesite()) {
|
||||||
|
// No cohort restore from other sites.
|
||||||
|
$step->set_mapping('enrol', $oldid, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data->roleid and $DB->record_exists('cohort', array('id'=>$data->customint1))) {
|
||||||
|
$instance = $DB->get_record('enrol', array('roleid'=>$data->roleid, 'customint1'=>$data->customint1, 'courseid'=>$course->id, 'enrol'=>$this->get_name()));
|
||||||
|
if ($instance) {
|
||||||
|
$instanceid = $instance;
|
||||||
|
} else {
|
||||||
|
$instanceid = $this->add_instance($course, (array)$data);
|
||||||
|
}
|
||||||
|
$step->set_mapping('enrol', $oldid, $instanceid);
|
||||||
|
|
||||||
|
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
|
||||||
|
enrol_cohort_sync($course->id, false);
|
||||||
|
|
||||||
|
} else if ($this->get_config('unenrolaction') == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||||
|
$data->customint1 = 0;
|
||||||
|
$instance = $DB->get_record('enrol', array('roleid'=>$data->roleid, 'customint1'=>$data->customint1, 'courseid'=>$course->id, 'enrol'=>$this->get_name()));
|
||||||
|
|
||||||
|
if ($instance) {
|
||||||
|
$instanceid = $instance;
|
||||||
|
} else {
|
||||||
|
$data->status = ENROL_INSTANCE_DISABLED;
|
||||||
|
$instanceid = $this->add_instance($course, (array)$data);
|
||||||
|
}
|
||||||
|
$step->set_mapping('enrol', $oldid, $instanceid);
|
||||||
|
|
||||||
|
require_once("$CFG->dirroot/enrol/cohort/locallib.php");
|
||||||
|
enrol_cohort_sync($course->id, false);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$step->set_mapping('enrol', $oldid, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore user enrolment.
|
||||||
|
*
|
||||||
|
* @param restore_enrolments_structure_step $step
|
||||||
|
* @param stdClass $data
|
||||||
|
* @param stdClass $instance
|
||||||
|
* @param int $oldinstancestatus
|
||||||
|
* @param int $userid
|
||||||
|
*/
|
||||||
|
public function restore_user_enrolment(restore_enrolments_structure_step $step, $data, $instance, $userid, $oldinstancestatus) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
if ($this->get_config('unenrolaction') != ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||||
|
// Enrolments were already synchronised in restore_instance(), we do not want any suspended leftovers.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ENROL_EXT_REMOVED_SUSPENDNOROLES means all previous enrolments are restored
|
||||||
|
// but without roles and suspended.
|
||||||
|
|
||||||
|
if (!$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
|
||||||
|
$this->enrol_user($instance, $userid, null, $data->timestart, $data->timeend, ENROL_USER_SUSPENDED);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
/**
|
/**
|
||||||
* Local stuff for cohort enrolment plugin.
|
* Local stuff for cohort enrolment plugin.
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -36,7 +35,7 @@ require_once($CFG->dirroot . '/enrol/locallib.php');
|
||||||
*/
|
*/
|
||||||
class enrol_cohort_handler {
|
class enrol_cohort_handler {
|
||||||
/**
|
/**
|
||||||
* Event processor - cohort member added
|
* Event processor - cohort member added.
|
||||||
* @param stdClass $ca
|
* @param stdClass $ca
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
@ -47,7 +46,7 @@ class enrol_cohort_handler {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// does any enabled cohort instance want to sync with this cohort?
|
// Does any enabled cohort instance want to sync with this cohort?
|
||||||
$sql = "SELECT e.*, r.id as roleexists
|
$sql = "SELECT e.*, r.id as roleexists
|
||||||
FROM {enrol} e
|
FROM {enrol} e
|
||||||
LEFT JOIN {role} r ON (r.id = e.roleid)
|
LEFT JOIN {role} r ON (r.id = e.roleid)
|
||||||
|
@ -60,14 +59,14 @@ class enrol_cohort_handler {
|
||||||
$plugin = enrol_get_plugin('cohort');
|
$plugin = enrol_get_plugin('cohort');
|
||||||
foreach ($instances as $instance) {
|
foreach ($instances as $instance) {
|
||||||
if ($instance->status != ENROL_INSTANCE_ENABLED ) {
|
if ($instance->status != ENROL_INSTANCE_ENABLED ) {
|
||||||
// no roles for disabled instances
|
// No roles for disabled instances.
|
||||||
$instance->roleid = 0;
|
$instance->roleid = 0;
|
||||||
} else if ($instance->roleid and !$instance->roleexists) {
|
} else if ($instance->roleid and !$instance->roleexists) {
|
||||||
// invalid role - let's just enrol, they will have to create new sync and delete this one
|
// Invalid role - let's just enrol, they will have to create new sync and delete this one.
|
||||||
$instance->roleid = 0;
|
$instance->roleid = 0;
|
||||||
}
|
}
|
||||||
unset($instance->roleexists);
|
unset($instance->roleexists);
|
||||||
// no problem if already enrolled
|
// No problem if already enrolled.
|
||||||
$plugin->enrol_user($instance, $ca->userid, $instance->roleid, 0, 0, ENROL_USER_ACTIVE);
|
$plugin->enrol_user($instance, $ca->userid, $instance->roleid, 0, 0, ENROL_USER_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,14 +74,14 @@ class enrol_cohort_handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event processor - cohort member removed
|
* Event processor - cohort member removed.
|
||||||
* @param stdClass $ca
|
* @param stdClass $ca
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function member_removed($ca) {
|
public static function member_removed($ca) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// does anything want to sync with this cohort?
|
// Does anything want to sync with this cohort?
|
||||||
if (!$instances = $DB->get_records('enrol', array('customint1'=>$ca->cohortid, 'enrol'=>'cohort'), 'id ASC')) {
|
if (!$instances = $DB->get_records('enrol', array('customint1'=>$ca->cohortid, 'enrol'=>'cohort'), 'id ASC')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -110,14 +109,14 @@ class enrol_cohort_handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event processor - cohort deleted
|
* Event processor - cohort deleted.
|
||||||
* @param stdClass $cohort
|
* @param stdClass $cohort
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function deleted($cohort) {
|
public static function deleted($cohort) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
// does anything want to sync with this cohort?
|
// Does anything want to sync with this cohort?
|
||||||
if (!$instances = $DB->get_records('enrol', array('customint1'=>$cohort->id, 'enrol'=>'cohort'), 'id ASC')) {
|
if (!$instances = $DB->get_records('enrol', array('customint1'=>$cohort->id, 'enrol'=>'cohort'), 'id ASC')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +148,7 @@ class enrol_cohort_handler {
|
||||||
function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
||||||
global $CFG, $DB;
|
global $CFG, $DB;
|
||||||
|
|
||||||
// purge all roles if cohort sync disabled, those can be recreated later here by cron or CLI
|
// Purge all roles if cohort sync disabled, those can be recreated later here by cron or CLI.
|
||||||
if (!enrol_is_enabled('cohort')) {
|
if (!enrol_is_enabled('cohort')) {
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
mtrace('Cohort sync plugin is disabled, unassigning all plugin roles and stopping.');
|
mtrace('Cohort sync plugin is disabled, unassigning all plugin roles and stopping.');
|
||||||
|
@ -158,7 +157,7 @@ function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unfortunately this may take a long time, this script can be interrupted without problems
|
// Unfortunately this may take a long time, this script can be interrupted without problems.
|
||||||
@set_time_limit(0);
|
@set_time_limit(0);
|
||||||
raise_memory_limit(MEMORY_HUGE);
|
raise_memory_limit(MEMORY_HUGE);
|
||||||
|
|
||||||
|
@ -173,7 +172,7 @@ function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
||||||
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
|
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
|
||||||
|
|
||||||
|
|
||||||
// iterate through all not enrolled yet users
|
// Iterate through all not enrolled yet users.
|
||||||
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
||||||
$sql = "SELECT cm.userid, e.id AS enrolid, ue.status
|
$sql = "SELECT cm.userid, e.id AS enrolid, ue.status
|
||||||
FROM {cohort_members} cm
|
FROM {cohort_members} cm
|
||||||
|
@ -204,7 +203,7 @@ function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
||||||
$rs->close();
|
$rs->close();
|
||||||
|
|
||||||
|
|
||||||
// unenrol as necessary
|
// Unenrol as necessary.
|
||||||
$sql = "SELECT ue.*, e.courseid
|
$sql = "SELECT ue.*, e.courseid
|
||||||
FROM {user_enrolments} ue
|
FROM {user_enrolments} ue
|
||||||
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'cohort' $onecourse)
|
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'cohort' $onecourse)
|
||||||
|
@ -217,14 +216,14 @@ function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
||||||
}
|
}
|
||||||
$instance = $instances[$ue->enrolid];
|
$instance = $instances[$ue->enrolid];
|
||||||
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
|
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
|
||||||
// remove enrolment together with group membership, grades, preferences, etc.
|
// Temove enrolment together with group membership, grades, preferences, etc.
|
||||||
$plugin->unenrol_user($instance, $ue->userid);
|
$plugin->unenrol_user($instance, $ue->userid);
|
||||||
if ($verbose) {
|
if ($verbose) {
|
||||||
mtrace(" unenrolling: $ue->userid ==> $instance->courseid via cohort $instance->customint1");
|
mtrace(" unenrolling: $ue->userid ==> $instance->courseid via cohort $instance->customint1");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // ENROL_EXT_REMOVED_SUSPENDNOROLES
|
} else { // ENROL_EXT_REMOVED_SUSPENDNOROLES
|
||||||
// just disable and ignore any changes
|
// Just disable and ignore any changes.
|
||||||
if ($ue->status != ENROL_USER_SUSPENDED) {
|
if ($ue->status != ENROL_USER_SUSPENDED) {
|
||||||
$plugin->update_user_enrol($instance, $ue->userid, ENROL_USER_SUSPENDED);
|
$plugin->update_user_enrol($instance, $ue->userid, ENROL_USER_SUSPENDED);
|
||||||
$context = context_course::instance($instance->courseid);
|
$context = context_course::instance($instance->courseid);
|
||||||
|
@ -239,7 +238,7 @@ function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
||||||
unset($instances);
|
unset($instances);
|
||||||
|
|
||||||
|
|
||||||
// now assign all necessary roles to enrolled users - skip suspended instances and users
|
// Now assign all necessary roles to enrolled users - skip suspended instances and users.
|
||||||
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
||||||
$sql = "SELECT e.roleid, ue.userid, c.id AS contextid, e.id AS itemid, e.courseid
|
$sql = "SELECT e.roleid, ue.userid, c.id AS contextid, e.id AS itemid, e.courseid
|
||||||
FROM {user_enrolments} ue
|
FROM {user_enrolments} ue
|
||||||
|
@ -264,7 +263,7 @@ function enrol_cohort_sync($courseid = NULL, $verbose = false) {
|
||||||
$rs->close();
|
$rs->close();
|
||||||
|
|
||||||
|
|
||||||
// remove unwanted roles - sync role can not be changed, we only remove role when unenrolled
|
// Remove unwanted roles - sync role can not be changed, we only remove role when unenrolled.
|
||||||
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
||||||
$sql = "SELECT ra.roleid, ra.userid, ra.contextid, ra.itemid, e.courseid
|
$sql = "SELECT ra.roleid, ra.userid, ra.contextid, ra.itemid, e.courseid
|
||||||
FROM {role_assignments} ra
|
FROM {role_assignments} ra
|
||||||
|
@ -384,7 +383,7 @@ function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if cohort exists and user is allowed to enrol it
|
* Check if cohort exists and user is allowed to enrol it.
|
||||||
*
|
*
|
||||||
* @global moodle_database $DB
|
* @global moodle_database $DB
|
||||||
* @param int $cohortid Cohort ID
|
* @param int $cohortid Cohort ID
|
||||||
|
@ -426,10 +425,10 @@ function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset
|
||||||
|
|
||||||
list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($context));
|
list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($context));
|
||||||
|
|
||||||
// Add some additional sensible conditions
|
// Add some additional sensible conditions.
|
||||||
$tests = array('contextid ' . $sqlparents);
|
$tests = array('contextid ' . $sqlparents);
|
||||||
|
|
||||||
// Modify the query to perform the search if required
|
// Modify the query to perform the search if required.
|
||||||
if (!empty($search)) {
|
if (!empty($search)) {
|
||||||
$conditions = array(
|
$conditions = array(
|
||||||
'name',
|
'name',
|
||||||
|
@ -452,17 +451,17 @@ function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset
|
||||||
$order = ' ORDER BY name ASC';
|
$order = ' ORDER BY name ASC';
|
||||||
$rs = $DB->get_recordset_sql($fields . $sql . $order, $params, $offset);
|
$rs = $DB->get_recordset_sql($fields . $sql . $order, $params, $offset);
|
||||||
|
|
||||||
// Produce the output respecting parameters
|
// Produce the output respecting parameters.
|
||||||
foreach ($rs as $c) {
|
foreach ($rs as $c) {
|
||||||
// Track offset
|
// Track offset.
|
||||||
$offset++;
|
$offset++;
|
||||||
// Check capabilities
|
// Check capabilities.
|
||||||
$context = context::instance_by_id($c->contextid);
|
$context = context::instance_by_id($c->contextid);
|
||||||
if (!has_capability('moodle/cohort:view', $context)) {
|
if (!has_capability('moodle/cohort:view', $context)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($limit === 0) {
|
if ($limit === 0) {
|
||||||
// we have reached the required number of items and know that there are more, exit now
|
// we have reached the required number of items and know that there are more, exit now.
|
||||||
$offset--;
|
$offset--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -472,7 +471,7 @@ function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset
|
||||||
'users'=>$DB->count_records('cohort_members', array('cohortid'=>$c->id)),
|
'users'=>$DB->count_records('cohort_members', array('cohortid'=>$c->id)),
|
||||||
'enrolled'=>in_array($c->id, $enrolled)
|
'enrolled'=>in_array($c->id, $enrolled)
|
||||||
);
|
);
|
||||||
// Count items
|
// Count items.
|
||||||
$limit--;
|
$limit--;
|
||||||
}
|
}
|
||||||
$rs->close();
|
$rs->close();
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
/**
|
/**
|
||||||
* Cohort enrolment plugin settings and presets.
|
* Cohort enrolment plugin settings and presets.
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
@ -45,4 +44,3 @@ if ($ADMIN->fulltree) {
|
||||||
$settings->add(new admin_setting_configselect('enrol_cohort/unenrolaction', get_string('extremovedaction', 'enrol'), get_string('extremovedaction_help', 'enrol'), ENROL_EXT_REMOVED_UNENROL, $options));
|
$settings->add(new admin_setting_configselect('enrol_cohort/unenrolaction', get_string('extremovedaction', 'enrol'), get_string('extremovedaction_help', 'enrol'), ENROL_EXT_REMOVED_UNENROL, $options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,7 @@
|
||||||
/**
|
/**
|
||||||
* Cohort enrolment plugin version specification.
|
* Cohort enrolment plugin version specification.
|
||||||
*
|
*
|
||||||
* @package enrol
|
* @package enrol_cohort
|
||||||
* @subpackage cohort
|
|
||||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue