From 1989bb2ed8e09a0816eb3a8c981dbe106a061c30 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Tue, 12 Feb 2013 17:12:03 +0800 Subject: [PATCH 1/2] MDL-37396 User Enrollment: fixed missing user from enrolment sub-menu --- enrol/locallib.php | 5 +++-- enrol/manual/ajax.php | 4 +++- enrol/manual/yui/quickenrolment/quickenrolment.js | 13 +++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/enrol/locallib.php b/enrol/locallib.php index 1577265e54b..095fe9545a5 100644 --- a/enrol/locallib.php +++ b/enrol/locallib.php @@ -272,9 +272,10 @@ class course_enrolment_manager { * @param bool $searchanywhere * @param int $page Defaults to 0 * @param int $perpage Defaults to 25 + * @param int $addedenrollment Defaults to 0 * @return array Array(totalusers => int, users => array) */ - public function get_potential_users($enrolid, $search='', $searchanywhere=false, $page=0, $perpage=25) { + public function get_potential_users($enrolid, $search='', $searchanywhere=false, $page=0, $perpage=25, $addedenrollment=0) { global $DB, $CFG; // Add some additional sensible conditions @@ -312,7 +313,7 @@ class course_enrolment_manager { $order = ' ORDER BY u.lastname ASC, u.firstname ASC'; $params['enrolid'] = $enrolid; $totalusers = $DB->count_records_sql($countfields . $sql, $params); - $availableusers = $DB->get_records_sql($fields . $sql . $order, $params, $page*$perpage, $perpage); + $availableusers = $DB->get_records_sql($fields . $sql . $order, $params, ($page*$perpage) - $addedenrollment, $perpage); return array('totalusers'=>$totalusers, 'users'=>$availableusers); } diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index b599b95a552..9b353d49bf8 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -67,7 +67,9 @@ switch ($action) { $enrolid = required_param('enrolid', PARAM_INT); $search = optional_param('search', '', PARAM_RAW); $page = optional_param('page', 0, PARAM_INT); - $outcome->response = $manager->get_potential_users($enrolid, $search, true, $page); + $addedenrollment = optional_param('enrolcount', 0, PARAM_INT); + $perpage = 25; // This value is hard-coded to 25 in quickenrolment.js + $outcome->response = $manager->get_potential_users($enrolid, $search, true, $page, $perpage, $addedenrollment); $extrafields = get_extra_user_fields($context); foreach ($outcome->response['users'] as &$user) { $user->picture = $OUTPUT->user_picture($user); diff --git a/enrol/manual/yui/quickenrolment/quickenrolment.js b/enrol/manual/yui/quickenrolment/quickenrolment.js index 3236a75c42b..59abfb644ba 100644 --- a/enrol/manual/yui/quickenrolment/quickenrolment.js +++ b/enrol/manual/yui/quickenrolment/quickenrolment.js @@ -22,7 +22,8 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { DEFAULTDURATION : 'defaultDuration', ASSIGNABLEROLES : 'assignableRoles', DISABLEGRADEHISTORY : 'disableGradeHistory', - RECOVERGRADESDEFAULT : 'recoverGradesDefault' + RECOVERGRADESDEFAULT : 'recoverGradesDefault', + ENROLCOUNT : 'enrolCount' }; /** CSS classes for nodes in structure **/ var CSS = { @@ -304,6 +305,8 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { params['action'] = 'searchusers'; params['search'] = this.get(UEP.SEARCH).get('value'); params['page'] = this.get(UEP.PAGE); + params['enrolcount'] = this.get(UEP.ENROLCOUNT); + if (this.get(UEP.MULTIPLE)) { alert('oh no there are multiple'); } else { @@ -415,6 +418,8 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { args.userNode.addClass(CSS.ENROLLED); args.userNode.one('.'+CSS.ENROL).remove(); this.set(UEP.REQUIREREFRESH, true); + var countenrol = this.get(UEP.ENROLCOUNT)+1; + this.set(UEP.ENROLCOUNT, countenrol); } } catch (e) { new M.core.exception(e); @@ -527,7 +532,11 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { }, recoverGradesDefault : { value : '' - } + }, + enrolCount : { + value : 0, + validator : Y.Lang.isNumber + } } }); Y.augment(USERENROLLER, Y.EventTarget); From 7e89587526725b77c7d285c8bc42971f8414ddeb Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Mon, 18 Feb 2013 13:41:13 +0800 Subject: [PATCH 2/2] MDL-37396 Enrollmen: pass $perpage as optional_param and set default perpage variable in quickenrolment.js --- enrol/manual/ajax.php | 2 +- enrol/manual/yui/quickenrolment/quickenrolment.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/enrol/manual/ajax.php b/enrol/manual/ajax.php index 9b353d49bf8..d938d123465 100644 --- a/enrol/manual/ajax.php +++ b/enrol/manual/ajax.php @@ -68,7 +68,7 @@ switch ($action) { $search = optional_param('search', '', PARAM_RAW); $page = optional_param('page', 0, PARAM_INT); $addedenrollment = optional_param('enrolcount', 0, PARAM_INT); - $perpage = 25; // This value is hard-coded to 25 in quickenrolment.js + $perpage = optional_param('perpage', 25, PARAM_INT); // This value is hard-coded to 25 in quickenrolment.js $outcome->response = $manager->get_potential_users($enrolid, $search, true, $page, $perpage, $addedenrollment); $extrafields = get_extra_user_fields($context); foreach ($outcome->response['users'] as &$user) { diff --git a/enrol/manual/yui/quickenrolment/quickenrolment.js b/enrol/manual/yui/quickenrolment/quickenrolment.js index 59abfb644ba..bcc5f5b5eed 100644 --- a/enrol/manual/yui/quickenrolment/quickenrolment.js +++ b/enrol/manual/yui/quickenrolment/quickenrolment.js @@ -23,7 +23,8 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { ASSIGNABLEROLES : 'assignableRoles', DISABLEGRADEHISTORY : 'disableGradeHistory', RECOVERGRADESDEFAULT : 'recoverGradesDefault', - ENROLCOUNT : 'enrolCount' + ENROLCOUNT : 'enrolCount', + PERPAGE : 'perPage' }; /** CSS classes for nodes in structure **/ var CSS = { @@ -306,6 +307,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { params['search'] = this.get(UEP.SEARCH).get('value'); params['page'] = this.get(UEP.PAGE); params['enrolcount'] = this.get(UEP.ENROLCOUNT); + params['perpage'] = this.get(UEP.PERPAGE); if (this.get(UEP.MULTIPLE)) { alert('oh no there are multiple'); @@ -374,7 +376,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { var content = create('
') .append(create('
'+usersstr+'
')) .append(users); - if (result.response.totalusers > (this.get(UEP.PAGE)+1)*25) { + if (result.response.totalusers > (this.get(UEP.PAGE)+1)*this.get(UEP.PERPAGE)) { var fetchmore = create(''); fetchmore.on('click', this.search, this, true); content.append(fetchmore) @@ -382,7 +384,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { this.setContent(content); Y.delegate("click", this.enrolUser, users, '.'+CSS.USER+' .'+CSS.ENROL, this, args); } else { - if (result.response.totalusers <= (this.get(UEP.PAGE)+1)*25) { + if (result.response.totalusers <= (this.get(UEP.PAGE)+1)*this.get(UEP.PERPAGE)) { this.get(UEP.BASE).one('.'+CSS.MORERESULTS).remove(); } } @@ -536,7 +538,11 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) { enrolCount : { value : 0, validator : Y.Lang.isNumber - } + }, + perPage : { + value: 25, + Validator: Y.Lang.isNumber + } } }); Y.augment(USERENROLLER, Y.EventTarget);