Merge branch 'MDL-37396_m24' of git://github.com/rwijaya/moodle into MOODLE_24_STABLE
This commit is contained in:
+6
-4
@@ -318,11 +318,12 @@ class course_enrolment_manager {
|
||||
* @param array $params query parameters.
|
||||
* @param int $page which page number of the results to show.
|
||||
* @param int $perpage number of users per page.
|
||||
* @param int $addedenrollment number of users added to enrollment.
|
||||
* @return array with two elememts:
|
||||
* int total number of users matching the search.
|
||||
* array of user objects returned by the query.
|
||||
*/
|
||||
protected function execute_search_queries($search, $fields, $countfields, $sql, array $params, $page, $perpage) {
|
||||
protected function execute_search_queries($search, $fields, $countfields, $sql, array $params, $page, $perpage, $addedenrollment=0) {
|
||||
global $DB, $CFG;
|
||||
|
||||
list($sort, $sortparams) = users_order_by_sql('u', $search, $this->get_context());
|
||||
@@ -330,7 +331,7 @@ class course_enrolment_manager {
|
||||
|
||||
$totalusers = $DB->count_records_sql($countfields . $sql, $params);
|
||||
$availableusers = $DB->get_records_sql($fields . $sql . $order,
|
||||
array_merge($params, $sortparams), $page*$perpage, $perpage);
|
||||
array_merge($params, $sortparams), ($page*$perpage) - $addedenrollment, $perpage);
|
||||
|
||||
return array('totalusers' => $totalusers, 'users' => $availableusers);
|
||||
}
|
||||
@@ -344,9 +345,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;
|
||||
|
||||
list($ufields, $params, $wherecondition) = $this->get_basic_search_conditions($search, $searchanywhere);
|
||||
@@ -359,7 +361,7 @@ class course_enrolment_manager {
|
||||
AND ue.id IS NULL";
|
||||
$params['enrolid'] = $enrolid;
|
||||
|
||||
return $this->execute_search_queries($search, $fields, $countfields, $sql, $params, $page, $perpage);
|
||||
return $this->execute_search_queries($search, $fields, $countfields, $sql, $params, $page, $perpage, $addedenrollment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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, $searchanywhere, $page);
|
||||
$addedenrollment = optional_param('enrolcount', 0, PARAM_INT);
|
||||
$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, $searchanywhere, $page, $perpage, $addedenrollment);
|
||||
$extrafields = get_extra_user_fields($context);
|
||||
foreach ($outcome->response['users'] as &$user) {
|
||||
$user->picture = $OUTPUT->user_picture($user);
|
||||
|
||||
+18
-3
@@ -23,7 +23,9 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
|
||||
DEFAULTDURATION : 'defaultDuration',
|
||||
ASSIGNABLEROLES : 'assignableRoles',
|
||||
DISABLEGRADEHISTORY : 'disableGradeHistory',
|
||||
RECOVERGRADESDEFAULT : 'recoverGradesDefault'
|
||||
RECOVERGRADESDEFAULT : 'recoverGradesDefault',
|
||||
ENROLCOUNT : 'enrolCount',
|
||||
PERPAGE : 'perPage'
|
||||
};
|
||||
/** CSS classes for nodes in structure **/
|
||||
var CSS = {
|
||||
@@ -309,6 +311,9 @@ 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);
|
||||
params['perpage'] = this.get(UEP.PERPAGE);
|
||||
|
||||
if (this.get(UEP.MULTIPLE)) {
|
||||
alert('oh no there are multiple');
|
||||
} else {
|
||||
@@ -376,7 +381,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
|
||||
var content = create('<div class="'+CSS.SEARCHRESULTS+'"></div>')
|
||||
.append(create('<div class="'+CSS.TOTALUSERS+'">'+usersstr+'</div>'))
|
||||
.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('<div class="'+CSS.MORERESULTS+'"><a href="#">'+M.str.enrol.ajaxnext25+'</a></div>');
|
||||
fetchmore.on('click', this.search, this, true);
|
||||
content.append(fetchmore)
|
||||
@@ -384,7 +389,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();
|
||||
}
|
||||
}
|
||||
@@ -420,6 +425,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);
|
||||
@@ -532,6 +539,14 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
|
||||
},
|
||||
recoverGradesDefault : {
|
||||
value : ''
|
||||
},
|
||||
enrolCount : {
|
||||
value : 0,
|
||||
validator : Y.Lang.isNumber
|
||||
},
|
||||
perPage : {
|
||||
value: 25,
|
||||
Validator: Y.Lang.isNumber
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user