+++ /dev/null
-<?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 file processes AJAX enrolment actions and returns JSON for the cohort plugin
- *
- * 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.
- *
- * @package enrol_cohort
- * @copyright 2011 Sam Hemelryk
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-define('AJAX_SCRIPT', true);
-
-require('../../config.php');
-require_once($CFG->dirroot.'/enrol/locallib.php');
-require_once($CFG->dirroot.'/enrol/cohort/locallib.php');
-require_once($CFG->dirroot.'/group/lib.php');
-require_once($CFG->dirroot.'/cohort/lib.php');
-
-// Must have the sesskey.
-$id = required_param('id', PARAM_INT); // course id
-$action = required_param('action', PARAM_ALPHANUMEXT);
-
-$PAGE->set_url(new moodle_url('/enrol/cohort/ajax.php', array('id'=>$id, 'action'=>$action)));
-
-$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
-$context = context_course::instance($course->id, MUST_EXIST);
-
-if ($course->id == SITEID) {
- throw new moodle_exception('invalidcourse');
-}
-
-require_login($course);
-require_capability('moodle/course:enrolreview', $context);
-require_sesskey();
-
-if (!enrol_is_enabled('cohort')) {
- // This should never happen, no need to invent new error strings.
- throw new enrol_ajax_exception('errorenrolcohort');
-}
-
-echo $OUTPUT->header(); // Send headers.
-
-$manager = new course_enrolment_manager($PAGE, $course);
-
-$outcome = new stdClass();
-$outcome->success = true;
-$outcome->response = new stdClass();
-$outcome->error = '';
-
-switch ($action) {
- case 'getassignable':
- $otheruserroles = optional_param('otherusers', false, PARAM_BOOL);
- $outcome->response = array_reverse($manager->get_assignable_roles($otheruserroles), true);
- break;
- case 'getdefaultcohortrole': //TODO: use in ajax UI MDL-24280
- $cohortenrol = enrol_get_plugin('cohort');
- $outcome->response = $cohortenrol->get_config('roleid');
- break;
- case 'getcohorts':
- require_capability('moodle/course:enrolconfig', $context);
- $offset = optional_param('offset', 0, PARAM_INT);
- $search = optional_param('search', '', PARAM_RAW);
- $outcome->response = enrol_cohort_search_cohorts($manager, $offset, 25, $search);
- // Some browsers reorder collections by key.
- $outcome->response['cohorts'] = array_values($outcome->response['cohorts']);
- break;
- case 'enrolcohort':
- require_capability('moodle/course:enrolconfig', $context);
- require_capability('enrol/cohort:config', $context);
- $roleid = required_param('roleid', PARAM_INT);
- $cohortid = required_param('cohortid', PARAM_INT);
-
- $roles = $manager->get_assignable_roles();
- if (!cohort_can_view_cohort($cohortid, $context) || !array_key_exists($roleid, $roles)) {
- throw new enrol_ajax_exception('errorenrolcohort');
- }
- $enrol = enrol_get_plugin('cohort');
- $enrol->add_instance($manager->get_course(), array('customint1' => $cohortid, 'roleid' => $roleid));
- $trace = new null_progress_trace();
- enrol_cohort_sync($trace, $manager->get_course()->id);
- $trace->finished();
- break;
- case 'enrolcohortusers':
- //TODO: this should be moved to enrol_manual, see MDL-35618.
- require_capability('enrol/manual:enrol', $context);
- $roleid = required_param('roleid', PARAM_INT);
- $cohortid = required_param('cohortid', PARAM_INT);
-
- $roles = $manager->get_assignable_roles();
- if (!cohort_can_view_cohort($cohortid, $context) || !array_key_exists($roleid, $roles)) {
- throw new enrol_ajax_exception('errorenrolcohort');
- }
-
- $result = enrol_cohort_enrol_all_users($manager, $cohortid, $roleid);
- if ($result === false) {
- throw new enrol_ajax_exception('errorenrolcohortusers');
- }
-
- $outcome->success = true;
- $outcome->response->users = $result;
- $outcome->response->title = get_string('success');
- $outcome->response->message = get_string('enrollednewusers', 'enrol', $result);
- $outcome->response->yesLabel = get_string('ok');
- break;
- default:
- throw new enrol_ajax_exception('unknowajaxaction');
-}
-
-echo json_encode($outcome);
-die();
*/
$string['addgroup'] = 'Add to group';
-$string['ajaxmore'] = 'More...';
$string['assignrole'] = 'Assign role';
-$string['cohortsearch'] = 'Search';
$string['cohort:config'] = 'Configure cohort instances';
$string['cohort:unenrol'] = 'Unenrol suspended users';
$string['instanceexists'] = 'Cohort is already synchronised with selected role';
return $actions;
}
- /**
- * Returns a button to enrol a cohort or its users through the manual enrolment plugin.
- *
- * This function also adds a quickenrolment JS ui to the page so that users can be enrolled
- * via AJAX.
- *
- * @param course_enrolment_manager $manager
- * @return enrol_user_button
- */
- public function get_manual_enrol_button(course_enrolment_manager $manager) {
- $course = $manager->get_course();
- if (!$this->can_add_new_instances($course->id)) {
- return false;
- }
-
- $cohorturl = new moodle_url('/enrol/cohort/edit.php', array('courseid' => $course->id));
- $button = new enrol_user_button($cohorturl, get_string('enrolcohort', 'enrol'), 'get');
- $button->class .= ' enrol_cohort_plugin';
-
- $button->strings_for_js(array(
- 'enrol',
- 'synced',
- 'enrolcohort',
- 'enrolcohortusers',
- ), 'enrol');
- $button->strings_for_js(array(
- 'ajaxmore',
- 'cohortsearch',
- ), 'enrol_cohort');
- $button->strings_for_js('assignroles', 'role');
- $button->strings_for_js('cohort', 'cohort');
- $button->strings_for_js('users', 'moodle');
-
- // No point showing this at all if the user cant manually enrol users.
- $hasmanualinstance = false; // Manual enrolment was disabled as part of MDL-35618.
-
- $modules = array('moodle-enrol_cohort-quickenrolment', 'moodle-enrol_cohort-quickenrolment-skin');
- $function = 'M.enrol_cohort.quickenrolment.init';
- $arguments = array(
- 'courseid' => $course->id,
- 'ajaxurl' => '/enrol/cohort/ajax.php',
- 'url' => $manager->get_moodlepage()->url->out(false),
- 'manualEnrolment' => $hasmanualinstance);
- $button->require_yui_module($modules, $function, array($arguments));
-
- return $button;
- }
-
/**
* Restore instance and map settings.
*
return 0;
}
-
-/**
- * Enrols all of the users in a cohort through a manual plugin instance.
- *
- * In order for this to succeed the course must contain a valid manual
- * enrolment plugin instance that the user has permission to enrol users through.
- *
- * @global moodle_database $DB
- * @param course_enrolment_manager $manager
- * @param int $cohortid
- * @param int $roleid
- * @return int
- */
-function enrol_cohort_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) {
- global $DB;
- $context = $manager->get_context();
- require_capability('moodle/course:enrolconfig', $context);
-
- $instance = false;
- $instances = $manager->get_enrolment_instances();
- foreach ($instances as $i) {
- if ($i->enrol == 'manual') {
- $instance = $i;
- break;
- }
- }
- $plugin = enrol_get_plugin('manual');
- if (!$instance || !$plugin || !$plugin->allow_enrol($instance) || !has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
- return false;
- }
- $sql = "SELECT com.userid
- FROM {cohort_members} com
- LEFT JOIN (
- SELECT *
- FROM {user_enrolments} ue
- WHERE ue.enrolid = :enrolid
- ) ue ON ue.userid=com.userid
- WHERE com.cohortid = :cohortid AND ue.id IS NULL";
- $params = array('cohortid' => $cohortid, 'enrolid' => $instance->id);
- $rs = $DB->get_recordset_sql($sql, $params);
- $count = 0;
- foreach ($rs as $user) {
- $count++;
- $plugin->enrol_user($instance, $user->userid, $roleid);
- }
- $rs->close();
- return $count;
-}
-
-/**
- * Gets cohorts the user is able to view.
- *
- * @global moodle_database $DB
- * @param course_enrolment_manager $manager
- * @param int $offset limit output from
- * @param int $limit items to output per load
- * @param string $search search string
- * @return array Array(more => bool, offset => int, cohorts => array)
- */
-function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') {
- $context = $manager->get_context();
- $cohorts = array();
- $instances = $manager->get_enrolment_instances();
- $enrolled = array();
- foreach ($instances as $instance) {
- if ($instance->enrol === 'cohort') {
- $enrolled[] = $instance->customint1;
- }
- }
-
- $rawcohorts = cohort_get_available_cohorts($context, COHORT_COUNT_MEMBERS, $offset, $limit, $search);
-
- // Produce the output respecting parameters.
- foreach ($rawcohorts as $c) {
- $cohorts[$c->id] = array(
- 'cohortid' => $c->id,
- 'name' => shorten_text(format_string($c->name, true, array('context'=>context::instance_by_id($c->contextid))), 35),
- 'users' => $c->memberscnt,
- 'enrolled' => in_array($c->id, $enrolled)
- );
- }
- return array('more' => !(bool)$limit, 'offset' => $offset, 'cohorts' => $cohorts);
-}
+++ /dev/null
-.qce-panel {background-color:#666;border:2px solid #666;border-width:0 2px 2px 0;min-width:420px;}
-.qce-panel .yui3-widget-hd {background:url("sprite.png");background-repeat:repeat-x;background-color:#DDD;background-position: 0 -15px;border-bottom:1px solid #555;border-top:1px solid #fff;}
-.qce-panel .yui3-widget-hd h2 {margin:3px 5px 2px;padding:0;font-size:110%;}
-.qce-panel .yui3-widget-hd .close {width:25px;height:15px;position:absolute;top:3px;right:1em;cursor:pointer;background:url("sprite.png") no-repeat scroll 0 0 transparent;}
-.dir-rtl .qce-panel .yui3-widget-hd .close {right:auto;left:1em;}
-.qce-panel .yui3-overlay-content {background-color:#F6F6F6;border:1px solid #555;margin-top:-2px;margin-left:-2px;}
-.qce-panel .qce-enrollable-cohorts {margin:5px;}
-.qce-panel .qce-cohorts {border:1px solid #666;min-width:408px;background-color:#FFF;height:375px;overflow:auto;}
-.qce-panel .qce-cohorts .qce-more-results {background-color:#eee;padding:5px;border-top:1px solid #BBB;text-align:center;}
-
-.qce-panel .qce-panel-content {min-height:405px;}
-.qce-panel .qce-panel-content .qce-loading-lightbox {position:absolute;width:100%;height:100%;top:0;left:0;background-color:#FFF;min-height:264px;text-align:center;}
-.qce-panel .qce-panel-content .qce-loading-lightbox.hidden {display:none;}
-.qce-panel .qce-panel-content .qce-loading-lightbox .loading-icon {margin:auto;vertical-align:middle;margin-top:198px;}
-
-.qce-panel .qce-cohort {width:100%;position:relative;clear:both;height:24px;white-space:nowrap;}
-.qce-panel .qce-cohort div {display:inline-block;overflow:hidden;}
-.qce-panel .qce-cohort.odd {background-color:#f4f4f4;}
-.qce-panel .qce-cohort .qce-cohort-button {text-align:center;display:inline-block;font-size:80%;height:22px;line-height:22px;overflow:hidden;padding:0 4px;}
-.qce-panel .qce-cohort .qce-cohort-button.notenrolled {background-color:#ddd;border:1px outset #CCC;background:url("sprite.png");background-repeat:repeat-x;background-color:#DDD;background-position: 0 -25px;color:inherit;}
-.qce-panel .qce-cohort .qce-cohort-button.notenrolled:hover {background-position:0 -15px;cursor:pointer;}
-.qce-panel .qce-cohort .qce-cohort-button.notenrolled.enrolusers {margin-right: 4px;}
-.qce-panel .qce-cohort .qce-cohort-button.alreadyenrolled {font-weight:bold;}
-.qce-panel .qce-cohort .qce-cohort-name {line-height:24px;width:220px;}
-.qce-panel .canenrolusers .qce-cohort .qce-cohort-button.alreadyenrolled {width:125px;}
-.qce-panel .canenrolusers .qce-cohort .qce-cohort-name {line-height:24px;}
-.qce-panel .qce-cohort .qce-cohort-users {width:30px;text-align:right;height:24px;line-height:24px;margin-right:4px}
-
-.qce-panel .qce-assignable-roles {margin:5px 6px 0 6px;}
-.qce-panel .qce-assignable-roles label {padding-right:8px;}
-
-.qce-panel .qce-footer {margin:0 6px 5px 6px;}
-.qce-panel .qce-search label {padding-right:8px;}
-.qce-panel .qce-search input {width:70%;}
-
-.qce-panel .qce-cohort.headings {font-weight:bold;border-width:0;}
-.qe-panel .qce-cohort.headings .qce-cohort-button {display:none;}
-
-.ie7 .qce-panel .qce-cohort div,
-.ie7 .qce-panel .canenrolusers .qce-cohort .qce-cohort-name {float:left;}
+++ /dev/null
-YUI.add('moodle-enrol_cohort-quickenrolment', function(Y) {
-
- var CONTROLLERNAME = 'Quick cohort enrolment controller',
- COHORTNAME = 'Cohort',
- COHORTID = 'cohortid',
- ENROLLED = 'enrolled',
- NAME = 'name',
- USERS = 'users',
- COURSEID = 'courseid',
- ASSIGNABLEROLES = 'assignableRoles',
- DEFAULTCOHORTROLE = 'defaultCohortRole',
- COHORTS = 'cohorts',
- MORERESULTS = 'moreresults',
- FIRSTPAGE = 'firstpage',
- OFFSET = 'offset',
- PANELID = 'qce-panel-',
- REQUIREREFRESH = 'requiresRefresh',
- SEARCH = 'search',
- URL = 'url',
- AJAXURL = 'ajaxurl',
- MANUALENROLMENT = 'manualEnrolment',
- CSS = {
- CLOSEBTN : 'close-button',
- COHORT : 'qce-cohort',
- COHORTS : 'qce-cohorts',
- COHORTBUTTON : 'qce-cohort-button',
- COHORTENROLLED : 'qce-cohort-enrolled',
- COHORTNAME : 'qce-cohort-name',
- COHORTUSERS : 'qce-cohort-users',
- ENROLUSERS : 'canenrolusers',
- FOOTER : 'qce-footer',
- HIDDEN : 'hidden',
- LIGHTBOX : 'qce-loading-lightbox',
- LOADINGICON : 'loading-icon',
- MORERESULTS : 'qce-more-results',
- PANEL : 'qce-panel',
- PANELCONTENT : 'qce-panel-content',
- PANELCOHORTS : 'qce-enrollable-cohorts',
- PANELROLES : 'qce-assignable-roles',
- PANELCONTROLS : 'qce-panel-controls',
- SEARCH : 'qce-search'
- },
- COUNT = 0;
-
-
- var CONTROLLER = function(config) {
- CONTROLLER.superclass.constructor.apply(this, arguments);
- };
- CONTROLLER.prototype = {
- initializer : function(config) {
- COUNT ++;
- this.publish('assignablerolesloaded', {fireOnce:true});
- this.publish('cohortsloaded');
- this.publish('defaultcohortroleloaded', {fireOnce:true});
-
- var finishbutton = Y.Node.create('<div class="'+CSS.CLOSEBTN+'"></div>')
- .append(Y.Node.create('<input type="button" value="'+M.str.enrol.finishenrollingusers+'" />'));
- var base = Y.Node.create('<div class="'+CSS.PANELCONTENT+'"></div>')
- .append(Y.Node.create('<div class="'+CSS.PANELROLES+'"></div>'))
- .append(Y.Node.create('<div class="'+CSS.PANELCOHORTS+'"></div>'))
- .append(Y.Node.create('<div class="'+CSS.FOOTER+'"></div>')
- .append(Y.Node.create('<div class="'+CSS.SEARCH+'"><label for="enrolcohortsearch">'+M.str.enrol_cohort.cohortsearch+':</label></div>')
- .append(Y.Node.create('<input type="text" id="enrolcohortsearch" value="" />'))
- )
- .append(finishbutton)
- )
- .append(Y.Node.create('<div class="'+CSS.LIGHTBOX+' '+CSS.HIDDEN+'"></div>')
- .append(Y.Node.create('<img alt="loading" class="'+CSS.LOADINGICON+'" />')
- .setAttribute('src', M.util.image_url('i/loading', 'moodle')))
- .setStyle('opacity', 0.5)
- );
-
- var close = Y.Node.create('<div class="close"></div>');
- var panel = new Y.Overlay({
- headerContent : Y.Node.create('<div></div>').append(Y.Node.create('<h2>'+M.str.enrol.enrolcohort+'</h2>')).append(close),
- bodyContent : base,
- constrain : true,
- centered : true,
- id : PANELID+COUNT,
- visible : false
- });
-
- // display the wheel on ajax events
- Y.on('io:start', function() {
- base.one('.'+CSS.LIGHTBOX).removeClass(CSS.HIDDEN);
- }, this);
- Y.on('io:end', function() {
- base.one('.'+CSS.LIGHTBOX).addClass(CSS.HIDDEN);
- }, this);
-
- this.set(SEARCH, base.one('#enrolcohortsearch'));
- Y.on('key', this.getCohorts, this.get(SEARCH), 'down:13', this, false);
-
- panel.get('boundingBox').addClass(CSS.PANEL);
- panel.render(Y.one(document.body));
- this.on('show', function(){
- this.set('centered', true);
- this.show();
- }, panel);
- this.on('hide', panel.hide, panel);
- this.on('assignablerolesloaded', this.updateContent, this, panel);
- this.on('cohortsloaded', this.updateContent, this, panel);
- this.on('defaultcohortroleloaded', this.updateContent, this, panel);
- Y.on('key', this.hide, document.body, 'down:27', this);
- close.on('click', this.hide, this);
- finishbutton.on('click', this.hide, this);
-
- Y.all('.enrol_cohort_plugin input').each(function(node){
- if (node.getAttribute('type', 'submit')) {
- node.on('click', this.show, this);
- }
- }, this);
-
- base = panel.get('boundingBox');
- base.plug(Y.Plugin.Drag);
- base.dd.addHandle('.yui3-widget-hd h2');
- base.one('.yui3-widget-hd h2').setStyle('cursor', 'move');
- },
- show : function(e) {
- e.preventDefault();
- // prepare the data and display the window
- this.getCohorts(e, false);
- this.getAssignableRoles();
- this.fire('show');
-
- var rolesselect = Y.one('#id_enrol_cohort_assignable_roles');
- if (rolesselect) {
- rolesselect.focus();
- }
- },
- updateContent : function(e, panel) {
- var content, i, roles, cohorts, count=0, supportmanual = this.get(MANUALENROLMENT), defaultrole;
- switch (e.type.replace(/^[^:]+:/, '')) {
- case 'cohortsloaded' :
- if (this.get(FIRSTPAGE)) {
- // we are on the page 0, create new element for cohorts list
- content = Y.Node.create('<div class="'+CSS.COHORTS+'"></div>');
- if (supportmanual) {
- content.addClass(CSS.ENROLUSERS);
- }
- } else {
- // we are adding cohorts to existing list
- content = Y.Node.one('.'+CSS.PANELCOHORTS+' .'+CSS.COHORTS);
- content.one('.'+CSS.MORERESULTS).remove();
- }
- // add cohorts items to the content
- cohorts = this.get(COHORTS);
- for (i in cohorts) {
- count++;
- cohorts[i].on('enrolchort', this.enrolCohort, this, cohorts[i], panel.get('contentBox'), false);
- cohorts[i].on('enrolusers', this.enrolCohort, this, cohorts[i], panel.get('contentBox'), true);
- content.append(cohorts[i].toHTML(supportmanual).addClass((count%2)?'even':'odd'));
- }
- // add the next link if there are more items expected
- if (this.get(MORERESULTS)) {
- var fetchmore = Y.Node.create('<div class="'+CSS.MORERESULTS+'"><a href="#">'+M.str.enrol_cohort.ajaxmore+'</a></div>');
- fetchmore.on('click', this.getCohorts, this, true);
- content.append(fetchmore);
- }
- // finally assing the content to the block
- if (this.get(FIRSTPAGE)) {
- panel.get('contentBox').one('.'+CSS.PANELCOHORTS).setContent(content);
- }
- break;
- case 'assignablerolesloaded':
- roles = this.get(ASSIGNABLEROLES);
- content = Y.Node.create('<select id="id_enrol_cohort_assignable_roles"></select>');
- for (i in roles) {
- content.append(Y.Node.create('<option value="'+i+'">'+roles[i]+'</option>'));
- }
- panel.get('contentBox').one('.'+CSS.PANELROLES).setContent(Y.Node.create('<div><label for="id_enrol_cohort_assignable_roles">'+M.str.role.assignroles+':</label></div>').append(content));
-
- this.getDefaultCohortRole();
- Y.one('#id_enrol_cohort_assignable_roles').focus();
- break;
- case 'defaultcohortroleloaded':
- defaultrole = this.get(DEFAULTCOHORTROLE);
- panel.get('contentBox').one('.'+CSS.PANELROLES+' select').set('value', defaultrole);
- break;
- }
- },
- hide : function() {
- if (this.get(REQUIREREFRESH)) {
- window.location = this.get(URL);
- }
- this.fire('hide');
- },
- getCohorts : function(e, append) {
- if (e) {
- e.preventDefault();
- }
- if (append) {
- this.set(FIRSTPAGE, false);
- } else {
- this.set(FIRSTPAGE, true);
- this.set(OFFSET, 0);
- }
- var params = [];
- params['id'] = this.get(COURSEID);
- params['offset'] = this.get(OFFSET);
- params['search'] = this.get(SEARCH).get('value');
- params['action'] = 'getcohorts';
- params['sesskey'] = M.cfg.sesskey;
-
- Y.io(M.cfg.wwwroot+this.get(AJAXURL), {
- method:'POST',
- data:build_querystring(params),
- on: {
- complete: function(tid, outcome, args) {
- try {
- var cohorts = Y.JSON.parse(outcome.responseText);
- if (cohorts.error) {
- new M.core.ajaxException(cohorts);
- } else {
- this.setCohorts(cohorts.response);
- }
- } catch (e) {
- return new M.core.exception(e);
- }
- this.fire('cohortsloaded');
- }
- },
- context:this
- });
- },
- setCohorts : function(response) {
- this.set(MORERESULTS, response.more);
- this.set(OFFSET, response.offset);
- var rawcohorts = response.cohorts;
- var cohorts = [], i=0;
- for (i in rawcohorts) {
- cohorts[i] = new COHORT(rawcohorts[i]);
- }
- this.set(COHORTS, cohorts);
- },
- getAssignableRoles : function() {
- Y.io(M.cfg.wwwroot+this.get(AJAXURL), {
- method:'POST',
- data:'id='+this.get(COURSEID)+'&action=getassignable&sesskey='+M.cfg.sesskey,
- on: {
- complete: function(tid, outcome, args) {
- try {
- var roles = Y.JSON.parse(outcome.responseText);
- this.set(ASSIGNABLEROLES, roles.response);
- } catch (e) {
- return new M.core.exception(e);
- }
- this.getAssignableRoles = function() {
- this.fire('assignablerolesloaded');
- };
- this.getAssignableRoles();
- }
- },
- context:this
- });
- },
- getDefaultCohortRole : function() {
- Y.io(M.cfg.wwwroot+this.get(AJAXURL), {
- method:'POST',
- data:'id='+this.get(COURSEID)+'&action=getdefaultcohortrole&sesskey='+M.cfg.sesskey,
- on: {
- complete: function(tid, outcome, args) {
- try {
- var roles = Y.JSON.parse(outcome.responseText);
- this.set(DEFAULTCOHORTROLE, roles.response);
- } catch (e) {
- return new M.core.exception(e);
- }
- this.fire('defaultcohortroleloaded');
- }
- },
- context:this
- });
- },
- enrolCohort : function(e, cohort, node, usersonly) {
- var params = {
- id : this.get(COURSEID),
- roleid : node.one('.'+CSS.PANELROLES+' select').get('value'),
- cohortid : cohort.get(COHORTID),
- action : (usersonly)?'enrolcohortusers':'enrolcohort',
- sesskey : M.cfg.sesskey
- };
- Y.io(M.cfg.wwwroot+this.get(AJAXURL), {
- method:'POST',
- data:build_querystring(params),
- on: {
- complete: function(tid, outcome, args) {
- try {
- var result = Y.JSON.parse(outcome.responseText);
- if (result.error) {
- new M.core.ajaxException(result);
- } else {
- if (result.response && result.response.message) {
- var alertpanel = new M.core.alert(result.response);
- Y.Node.one('#id_yuialertconfirm-' + alertpanel.get('COUNT')).focus();
- }
- var enrolled = Y.Node.create('<div class="'+CSS.COHORTBUTTON+' alreadyenrolled">'+M.str.enrol.synced+'</div>');
- node.one('.'+CSS.COHORT+' #cohortid_'+cohort.get(COHORTID)).replace(enrolled);
- this.set(REQUIREREFRESH, true);
- }
- } catch (e) {
- new M.core.exception(e);
- }
- }
- },
- context:this
- });
- return true;
- }
- };
- Y.extend(CONTROLLER, Y.Base, CONTROLLER.prototype, {
- NAME : CONTROLLERNAME,
- ATTRS : {
- url : {
- validator : Y.Lang.isString
- },
- ajaxurl : {
- validator : Y.Lang.isString
- },
- courseid : {
- value : null
- },
- cohorts : {
- validator : Y.Lang.isArray,
- value : null
- },
- assignableRoles : {
- value : null
- },
- manualEnrolment : {
- value : false
- },
- defaultCohortRole : {
- value : null
- },
- requiresRefresh : {
- value : false,
- validator : Y.Lang.isBool
- }
- }
- });
- Y.augment(CONTROLLER, Y.EventTarget);
-
- var COHORT = function(config) {
- COHORT.superclass.constructor.apply(this, arguments);
- };
- Y.extend(COHORT, Y.Base, {
- toHTML : function(supportmanualenrolment){
- var button, result, name, users, syncbutton, usersbutton;
- result = Y.Node.create('<div class="'+CSS.COHORT+'"></div>');
- if (this.get(ENROLLED)) {
- button = Y.Node.create('<div class="'+CSS.COHORTBUTTON+' alreadyenrolled">'+M.str.enrol.synced+'</div>');
- } else {
- button = Y.Node.create('<div id="cohortid_'+this.get(COHORTID)+'"></div>');
-
- syncbutton = Y.Node.create('<a class="'+CSS.COHORTBUTTON+' notenrolled enrolcohort">'+M.str.enrol.enrolcohort+'</a>');
- syncbutton.on('click', function(){this.fire('enrolchort');}, this);
- button.append(syncbutton);
-
- if (supportmanualenrolment) {
- usersbutton = Y.Node.create('<a class="'+CSS.COHORTBUTTON+' notenrolled enrolusers">'+M.str.enrol.enrolcohortusers+'</a>');
- usersbutton.on('click', function(){this.fire('enrolusers');}, this);
- button.append(usersbutton);
- }
- }
- name = Y.Node.create('<div class="'+CSS.COHORTNAME+'">'+this.get(NAME)+'</div>');
- users = Y.Node.create('<div class="'+CSS.COHORTUSERS+'">'+this.get(USERS)+'</div>');
- return result.append(button).append(name).append(users);
- }
- }, {
- NAME : COHORTNAME,
- ATTRS : {
- cohortid : {
-
- },
- name : {
- validator : Y.Lang.isString
- },
- enrolled : {
- value : false
- },
- users : {
- value : 0
- }
- }
- });
- Y.augment(COHORT, Y.EventTarget);
-
- M.enrol_cohort = M.enrol || {};
- M.enrol_cohort.quickenrolment = {
- init : function(cfg) {
- new CONTROLLER(cfg);
- }
- }
-
-}, '@VERSION@', {requires:['base','node', 'overlay', 'io-base', 'test', 'json-parse', 'event-delegate', 'dd-plugin', 'event-key', 'moodle-core-notification']});
/**
* Gets all the cohorts the user is able to view.
*
- * @deprecated since Moodle 2.8 MDL-36014 please use enrol_cohort_search_cohorts()
+ * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
*
* @param course_enrolment_manager $manager
* @return array
*/
function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
global $CFG;
- require_once($CFG->dirroot . '/enrol/cohort/locallib.php');
debugging('Function enrol_cohort_get_cohorts() is deprecated, use enrol_cohort_search_cohorts() or '.
'cohort_get_available_cohorts() instead', DEBUG_DEVELOPER);
return enrol_cohort_search_cohorts($manager, 0, 0, '');
return $cohorts;
}
+
+/**
+ * Enrols all of the users in a cohort through a manual plugin instance.
+ *
+ * In order for this to succeed the course must contain a valid manual
+ * enrolment plugin instance that the user has permission to enrol users through.
+ *
+ * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
+ *
+ * @global moodle_database $DB
+ * @param course_enrolment_manager $manager
+ * @param int $cohortid
+ * @param int $roleid
+ * @return int
+ */
+function enrol_cohort_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) {
+ global $DB;
+ debugging('enrol_cohort_enrol_all_users() is deprecated. This functionality is moved to enrol_manual.', DEBUG_DEVELOPER);
+
+ $context = $manager->get_context();
+ require_capability('moodle/course:enrolconfig', $context);
+
+ $instance = false;
+ $instances = $manager->get_enrolment_instances();
+ foreach ($instances as $i) {
+ if ($i->enrol == 'manual') {
+ $instance = $i;
+ break;
+ }
+ }
+ $plugin = enrol_get_plugin('manual');
+ if (!$instance || !$plugin || !$plugin->allow_enrol($instance) || !has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
+ return false;
+ }
+ $sql = "SELECT com.userid
+ FROM {cohort_members} com
+ LEFT JOIN (
+ SELECT *
+ FROM {user_enrolments} ue
+ WHERE ue.enrolid = :enrolid
+ ) ue ON ue.userid=com.userid
+ WHERE com.cohortid = :cohortid AND ue.id IS NULL";
+ $params = array('cohortid' => $cohortid, 'enrolid' => $instance->id);
+ $rs = $DB->get_recordset_sql($sql, $params);
+ $count = 0;
+ foreach ($rs as $user) {
+ $count++;
+ $plugin->enrol_user($instance, $user->userid, $roleid);
+ }
+ $rs->close();
+ return $count;
+}
+
+/**
+ * Gets cohorts the user is able to view.
+ *
+ * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
+ *
+ * @global moodle_database $DB
+ * @param course_enrolment_manager $manager
+ * @param int $offset limit output from
+ * @param int $limit items to output per load
+ * @param string $search search string
+ * @return array Array(more => bool, offset => int, cohorts => array)
+ */
+function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') {
+ global $CFG;
+ debugging('enrol_cohort_search_cohorts() is deprecated. This functionality is moved to enrol_manual.', DEBUG_DEVELOPER);
+ require_once($CFG->dirroot . '/cohort/lib.php');
+
+ $context = $manager->get_context();
+ $cohorts = array();
+ $instances = $manager->get_enrolment_instances();
+ $enrolled = array();
+ foreach ($instances as $instance) {
+ if ($instance->enrol === 'cohort') {
+ $enrolled[] = $instance->customint1;
+ }
+ }
+
+ $rawcohorts = cohort_get_available_cohorts($context, COHORT_COUNT_MEMBERS, $offset, $limit, $search);
+
+ // Produce the output respecting parameters.
+ foreach ($rawcohorts as $c) {
+ $cohorts[$c->id] = array(
+ 'cohortid' => $c->id,
+ 'name' => shorten_text(format_string($c->name, true, array('context'=>context::instance_by_id($c->contextid))), 35),
+ 'users' => $c->memberscnt,
+ 'enrolled' => in_array($c->id, $enrolled)
+ );
+ }
+ return array('more' => !(bool)$limit, 'offset' => $offset, 'cohorts' => $cohorts);
+}
deprecated.
* cohort_get_visible_list() is deprecated. There is a better function cohort_get_available_cohorts()
that respects user capabilities to view cohorts.
-* enrol_cohort_get_cohorts() is deprecated; replace with enrol_cohort_search_cohorts() or
- cohort_get_available_cohorts()
+* enrol_cohort_get_cohorts() and enrol_cohort_search_cohorts() are deprecated since
+ functionality is removed. Please use cohort_get_available_cohorts()
+* enrol_cohort_enrol_all_users() is deprecated; enrol_manual is now responsible for this action
* enrol_cohort_can_view_cohort() is deprecated; replace with cohort_can_view_cohort()
=== 2.6.4 / 2.7.1 ===