From 58b5b04d4be686da6f132830ff7975494dd3a434 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 15 Sep 2014 10:50:53 +0800 Subject: [PATCH] MDL-35618 enrol_cohort: remove enrolment button --- enrol/cohort/ajax.php | 127 ------ enrol/cohort/lang/en/enrol_cohort.php | 2 - enrol/cohort/lib.php | 48 --- enrol/cohort/locallib.php | 83 ---- .../assets/skins/sam/quickenrolment.css | 40 -- .../assets/skins/sam/sprite.png | Bin 1940 -> 0 bytes .../yui/quickenrolment/quickenrolment.js | 396 ------------------ lib/deprecatedlib.php | 96 ++++- lib/upgrade.txt | 5 +- 9 files changed, 97 insertions(+), 700 deletions(-) delete mode 100644 enrol/cohort/ajax.php delete mode 100644 enrol/cohort/yui/quickenrolment/assets/skins/sam/quickenrolment.css delete mode 100644 enrol/cohort/yui/quickenrolment/assets/skins/sam/sprite.png delete mode 100644 enrol/cohort/yui/quickenrolment/quickenrolment.js diff --git a/enrol/cohort/ajax.php b/enrol/cohort/ajax.php deleted file mode 100644 index 49db76d9771..00000000000 --- a/enrol/cohort/ajax.php +++ /dev/null @@ -1,127 +0,0 @@ -. - -/** - * 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(); diff --git a/enrol/cohort/lang/en/enrol_cohort.php b/enrol/cohort/lang/en/enrol_cohort.php index 97c3fa4fccd..48550f28b16 100644 --- a/enrol/cohort/lang/en/enrol_cohort.php +++ b/enrol/cohort/lang/en/enrol_cohort.php @@ -23,9 +23,7 @@ */ $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'; diff --git a/enrol/cohort/lib.php b/enrol/cohort/lib.php index 889504b8c71..0f338fbeafe 100644 --- a/enrol/cohort/lib.php +++ b/enrol/cohort/lib.php @@ -208,54 +208,6 @@ class enrol_cohort_plugin extends enrol_plugin { 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. * diff --git a/enrol/cohort/locallib.php b/enrol/cohort/locallib.php index 7087ccb7c5a..35f1e03dfe1 100644 --- a/enrol/cohort/locallib.php +++ b/enrol/cohort/locallib.php @@ -328,86 +328,3 @@ function enrol_cohort_sync(progress_trace $trace, $courseid = NULL) { 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); -} diff --git a/enrol/cohort/yui/quickenrolment/assets/skins/sam/quickenrolment.css b/enrol/cohort/yui/quickenrolment/assets/skins/sam/quickenrolment.css deleted file mode 100644 index ae247a091e9..00000000000 --- a/enrol/cohort/yui/quickenrolment/assets/skins/sam/quickenrolment.css +++ /dev/null @@ -1,40 +0,0 @@ -.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;} diff --git a/enrol/cohort/yui/quickenrolment/assets/skins/sam/sprite.png b/enrol/cohort/yui/quickenrolment/assets/skins/sam/sprite.png deleted file mode 100644 index 067c225db53c2c161b930df99222baf66b87d0f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1940 zcmW-hc|4SP9LFC=4Iv%MRUzc6A(;`Pcu^yfm>g@jL#>1k$Ce^dkz-lqr4+LoQprY> zEu9l3N2Ca;);MRzjF~axnsM*<_k7>a=l%P9=5H@)-d?-Zmgp?OFig#z;_3shHpE#; z0lbpG&;*ZMw9hUVth{9n55we{-g~HS@Z*USC!(XHlarHaG#Z1!sHv&xM#o}7aG=6K zV)gVuaG=6K>gnx;;6R0e)Z5nw!GQ_`sjt5uf&&!>QvbjJ1P3a9gM$MA9Iin&dvK7A z0~H2@gFYM(IxZK20~H1mcW4NL0~H3+5RV7JfeHhO$LB+Epu#}n4-Z3dpu#{J76>3X zP+>rX=tBsEaJYmbkx(eYfeHgjG%^A~z~LGZi=jfqaJa-0iC8SbfeHgjGCGQcUT8?8 zV`C5;s4$Sm#>XKzP+=gAPfS2?pu#|!n4E;*K!pL3q7N}Cg~KJ4$)r*l4pbOOvZ*Nu z4pbOOQ`6H^2zXILH#38TUT8=&v$GH!s4$Rb=jI?dP+=g=&Cf${pu#|!Us!QdXODS6RO4<_d-Gj^>aL%$ax9o`BZM>{T%Dq^=oH*&2yZzZ|<(I zGb_x~D$LHzZ0u#YnqQ;LXFItJGpN%PbLaHz>h}v{uj=}$`VLOgY75__amkCouC^%Y z0gonH2>tQXiId?fO8F;AtQ9uo?$u#OO{XaR!E3*Le>{>W9yD0S_HSj5 zIwtwqMLsPsHB>U)WMSdBA=amg?IJZ)Oez#-8z;oGMte&BDS~^Yf=hg>4F-o0}VC zWLkdK{bL31C3}c}UrQ_WAQ1a?Md5Aa6?gC5EpT^th}Ma`5l2=F3^QNlqi@hR?5nKY zXtLLs=4!WjvzeWlBqlg2%DUF5*2ufIcO=($9HT2Yh+WM&A zBS*Y;P+eo&C8^>D${A|AM0}d;&>x^^vfg@B>&gY~x~0EgO<^pj8&KZ4d^eyH0{*E8 z(2Y+b`la5(Hdx5S2A!>j8$0RxorgR3g;-^1Ys47kDJLW~WB0ZjClTguCCSb2;neKd zkltIB^|oiR+-+5YmWC5SD?wGS?wC`db-XsSaAsO2ORPFSnr3pDaq;ba&G$KdLbj02 z{vekBOvCJH^Nd$qr=v0Iw(5UfIJxemNEBmhYyZ5BNA&W_(zAQH^_Be#`&M3gOBRvX zlGW0CNZL2ERLS9Ap&30aj^N->ZPnbly0WtJLv}f#xpQ72NHrp~Gmash>Ju`2u+r50xz>&W#Yxh|kkxyA>W=tVpEI@%7aW rU0=Ey+N-;&zjS@6tyLnaE-0MdYu7|yvb6^O!C>xgUasXXhc5jO%e=iQ diff --git a/enrol/cohort/yui/quickenrolment/quickenrolment.js b/enrol/cohort/yui/quickenrolment/quickenrolment.js deleted file mode 100644 index 661af045c56..00000000000 --- a/enrol/cohort/yui/quickenrolment/quickenrolment.js +++ /dev/null @@ -1,396 +0,0 @@ -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('
') - .append(Y.Node.create('')); - var base = Y.Node.create('
') - .append(Y.Node.create('
')) - .append(Y.Node.create('
')) - .append(Y.Node.create('
') - .append(Y.Node.create('
') - .append(Y.Node.create('')) - ) - .append(finishbutton) - ) - .append(Y.Node.create('
') - .append(Y.Node.create('loading') - .setAttribute('src', M.util.image_url('i/loading', 'moodle'))) - .setStyle('opacity', 0.5) - ); - - var close = Y.Node.create('
'); - var panel = new Y.Overlay({ - headerContent : Y.Node.create('
').append(Y.Node.create('

'+M.str.enrol.enrolcohort+'

')).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('
'); - 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(''); - 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(''); - for (i in roles) { - content.append(Y.Node.create('')); - } - panel.get('contentBox').one('.'+CSS.PANELROLES).setContent(Y.Node.create('
').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('
'+M.str.enrol.synced+'
'); - 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('
'); - if (this.get(ENROLLED)) { - button = Y.Node.create('
'+M.str.enrol.synced+'
'); - } else { - button = Y.Node.create('
'); - - syncbutton = Y.Node.create(''+M.str.enrol.enrolcohort+''); - syncbutton.on('click', function(){this.fire('enrolchort');}, this); - button.append(syncbutton); - - if (supportmanualenrolment) { - usersbutton = Y.Node.create(''+M.str.enrol.enrolcohortusers+''); - usersbutton.on('click', function(){this.fire('enrolusers');}, this); - button.append(usersbutton); - } - } - name = Y.Node.create('
'+this.get(NAME)+'
'); - users = Y.Node.create('
'+this.get(USERS)+'
'); - 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']}); diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index d5c592b0e69..899cb1c8237 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -4452,14 +4452,13 @@ function coursemodule_visible_for_user($cm, $userid=0) { /** * 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, ''); @@ -4538,3 +4537,96 @@ function cohort_get_visible_list($course, $onlyenrolled=true) { 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); +} diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 96ce278290c..35717d5e4e5 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -30,8 +30,9 @@ DEPRECATIONS: 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 ===