Skip to content
Browse files

Merge branch 'MDL-37396_m24' of git://github.com/rwijaya/moodle into …

…MOODLE_24_STABLE
  • Loading branch information...
2 parents 9d0c759 + 4086097 commit ff1d6556a7871ca2c49267fe5bfbadefa0786314 @danpoltawski danpoltawski committed Feb 18, 2013
Showing with 27 additions and 8 deletions.
  1. +6 −4 enrol/locallib.php
  2. +3 −1 enrol/manual/ajax.php
  3. +18 −3 enrol/manual/yui/quickenrolment/quickenrolment.js
View
10 enrol/locallib.php
@@ -318,19 +318,20 @@ protected function get_basic_search_conditions($search, $searchanywhere) {
* @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());
$order = ' ORDER BY ' . $sort;
$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 @@ protected function execute_search_queries($search, $fields, $countfields, $sql,
* @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 @@ public function get_potential_users($enrolid, $search='', $searchanywhere=false,
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);
}
/**
View
4 enrol/manual/ajax.php
@@ -67,7 +67,9 @@
$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);
View
21 enrol/manual/yui/quickenrolment/quickenrolment.js
@@ -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,15 +381,15 @@ 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)
}
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
}
}
});

0 comments on commit ff1d655

Please sign in to comment.
Something went wrong with that request. Please try again.