mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-59365 enrol: Switch the user selector
The user selector was calling the wrong API to get the potential list of users to enrol. Now it works.
This commit is contained in:
parent
786e014c5c
commit
0fa35b1abc
@ -415,7 +415,10 @@ class core_enrol_external extends external_api {
|
||||
* @return array An array of users
|
||||
*/
|
||||
public static function get_potential_users($courseid, $enrolid, $search, $searchanywhere, $page, $perpage) {
|
||||
global $PAGE;
|
||||
global $PAGE, $DB, $CFG;
|
||||
|
||||
require_once($CFG->dirroot.'/enrol/locallib.php');
|
||||
require_once($CFG->dirroot.'/user/lib.php');
|
||||
|
||||
$params = self::validate_parameters(
|
||||
self::get_potential_users_parameters(),
|
||||
@ -429,6 +432,14 @@ class core_enrol_external extends external_api {
|
||||
)
|
||||
);
|
||||
$context = context_course::instance($params['courseid']);
|
||||
try {
|
||||
self::validate_context($context);
|
||||
} catch (Exception $e) {
|
||||
$exceptionparam = new stdClass();
|
||||
$exceptionparam->message = $e->getMessage();
|
||||
$exceptionparam->courseid = $params['courseid'];
|
||||
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
|
||||
}
|
||||
require_capability('moodle/course:enrolreview', $context);
|
||||
|
||||
$course = $DB->get_record('course', array('id' => $params['courseid']));
|
||||
@ -441,7 +452,7 @@ class core_enrol_external extends external_api {
|
||||
$params['perpage']);
|
||||
|
||||
$results = array();
|
||||
foreach ($users as $id => $user) {
|
||||
foreach ($users['users'] as $id => $user) {
|
||||
if ($userdetails = user_get_user_details($user)) {
|
||||
$results[] = $userdetails;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
define(["jquery","core/ajax","core/templates"],function(a,b,c){return{processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b._label})}),d},transport:function(d,e,f,g){var h,i=a(d).data("courseid");"undefined"==typeof i&&(i="1");var j=a(d).data("enrolid");"undefined"==typeof j&&(j=""),h=b.call([{methodname:"core_enrol_get_potential_users",args:{courseid:i,enrolid:j,search:e,searchanywhere:!0,page:0,perpage:30}}]),h[0].then(function(b){var d=[],e=0;return a.each(b.users,function(b,e){var f=e,g=[];a.each(["idnumber","email","phone1","phone2","department","institution"],function(a,b){"undefined"!=typeof e[b]&&""!==e[b]&&(f.hasidentity=!0,g.push(e[b]))}),f.identity=g.join(", "),d.push(c.render("enrol_manual/form-user-selector-suggestion",f))}),a.when.apply(a.when,d).then(function(){var c=arguments;a.each(b.users,function(a,b){b._label=c[e],e++}),f(b.users)})},g)}}});
|
||||
define(["jquery","core/ajax","core/templates"],function(a,b,c){return{processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.id,label:b._label})}),d},transport:function(d,e,f,g){var h,i=a(d).attr("courseid");"undefined"==typeof i&&(i="1");var j=a(d).attr("enrolid");"undefined"==typeof j&&(j=""),h=b.call([{methodname:"core_enrol_get_potential_users",args:{courseid:i,enrolid:j,search:e,searchanywhere:!0,page:0,perpage:30}}]),h[0].then(function(b){var d=[],e=0;return a.each(b,function(b,e){var f=e,g=[];a.each(["idnumber","email","phone1","phone2","department","institution"],function(a,b){"undefined"!=typeof e[b]&&""!==e[b]&&(f.hasidentity=!0,g.push(e[b]))}),f.identity=g.join(", "),d.push(c.render("enrol_manual/form-user-selector-suggestion",f))}),a.when.apply(a.when,d).then(function(){var c=arguments;a.each(b,function(a,b){b._label=c[e],e++}),f(b)})},g)}}});
|
@ -40,11 +40,11 @@ define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) {
|
||||
|
||||
transport: function(selector, query, success, failure) {
|
||||
var promise;
|
||||
var courseid = $(selector).data('courseid');
|
||||
var courseid = $(selector).attr('courseid');
|
||||
if (typeof courseid === "undefined") {
|
||||
courseid = '1';
|
||||
}
|
||||
var enrolid = $(selector).data('enrolid');
|
||||
var enrolid = $(selector).attr('enrolid');
|
||||
if (typeof enrolid === "undefined") {
|
||||
enrolid = '';
|
||||
}
|
||||
@ -66,7 +66,7 @@ define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) {
|
||||
i = 0;
|
||||
|
||||
// Render the label.
|
||||
$.each(results.users, function(index, user) {
|
||||
$.each(results, function(index, user) {
|
||||
var ctx = user,
|
||||
identity = [];
|
||||
$.each(['idnumber', 'email', 'phone1', 'phone2', 'department', 'institution'], function(i, k) {
|
||||
@ -82,11 +82,11 @@ define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) {
|
||||
// Apply the label to the results.
|
||||
return $.when.apply($.when, promises).then(function() {
|
||||
var args = arguments;
|
||||
$.each(results.users, function(index, user) {
|
||||
$.each(results, function(index, user) {
|
||||
user._label = args[i];
|
||||
i++;
|
||||
});
|
||||
success(results.users);
|
||||
success(results);
|
||||
});
|
||||
|
||||
}, failure);
|
||||
|
@ -101,7 +101,7 @@ class enrol_manual_enrol_users_form extends moodleform {
|
||||
$mform->setDefault('role', $defaultrole);
|
||||
|
||||
$options = array(
|
||||
'ajax' => 'tool_lp/form-user-selector',
|
||||
'ajax' => 'enrol_manual/form-potential-user-selector',
|
||||
'multiple' => true,
|
||||
'courseid' => $course->id,
|
||||
'enrolid' => $instance->id
|
||||
|
@ -468,6 +468,7 @@ $functions = array(
|
||||
'methodname' => 'get_potential_users',
|
||||
'classpath' => 'enrol/externallib.php',
|
||||
'description' => 'Get the list of potential users to enrol',
|
||||
'ajax' => true,
|
||||
'type' => 'read',
|
||||
'capabilities' => 'moodle/course:enrolreview'
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user