Browse files

MDL-26647 (8) Support showuseridentity on enrol screen

Includes support for the table display, plus the AJAX, including search. (The fallback version uses user selector so is already supported.)
  • Loading branch information...
1 parent 02dd3b9 commit b849c21255ddab171eca5ff25f9b0731829da2d1 @sammarshallou sammarshallou committed Nov 4, 2011
Showing with 35 additions and 16 deletions.
  1. +13 −7 enrol/locallib.php
  2. +7 −0 enrol/manual/ajax.php
  3. +2 −2 enrol/manual/yui/quickenrolment/quickenrolment.js
  4. +2 −1 enrol/renderer.php
  5. +11 −6 enrol/users.php
View
20 enrol/locallib.php
@@ -199,7 +199,9 @@ public function get_users($sort, $direction='ASC', $page=0, $perpage=25) {
$key = md5("$sort-$direction-$page-$perpage");
if (!array_key_exists($key, $this->users)) {
list($instancessql, $params, $filter) = $this->get_instance_sql();
- $ufields = user_picture::fields('u', array('lastaccess', 'email'));
+ $extrafields = get_extra_user_fields($this->get_context());
+ $extrafields[] = 'lastaccess';
+ $ufields = user_picture::fields('u', $extrafields);
$sql = "SELECT DISTINCT $ufields, ul.timeaccess AS lastseen
FROM {user} u
JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid $instancessql)
@@ -279,10 +281,8 @@ public function get_potential_users($enrolid, $search='', $searchanywhere=false,
$tests = array("id <> :guestid", 'u.deleted = 0', 'u.confirmed = 1');
$params = array('guestid' => $CFG->siteguest);
if (!empty($search)) {
- $conditions = array(
- $DB->sql_concat('u.firstname', "' '", 'u.lastname'),
- 'u.email'
- );
+ $conditions = get_extra_user_fields($this->get_context());
+ $conditions[] = $DB->sql_concat('u.firstname', "' '", 'u.lastname');
if ($searchanywhere) {
$searchparam = '%' . $search . '%';
} else {
@@ -298,7 +298,10 @@ public function get_potential_users($enrolid, $search='', $searchanywhere=false,
}
$wherecondition = implode(' AND ', $tests);
- $ufields = user_picture::fields('u', array('username', 'lastaccess'));
+ $extrafields = get_extra_user_fields($this->get_context(), array('username', 'lastaccess'));
+ $extrafields[] = 'username';
+ $extrafields[] = 'lastaccess';
+ $ufields = user_picture::fields('u', $extrafields);
$fields = 'SELECT '.$ufields;
$countfields = 'SELECT COUNT(1)';
@@ -835,6 +838,7 @@ public function get_users_for_display(course_enrolment_manager $manager, $sort,
$canmanagegroups = has_capability('moodle/course:managegroups', $context);
$url = new moodle_url($pageurl, $this->get_url_params());
+ $extrafields = get_extra_user_fields($context);
$userdetails = array();
foreach ($users as $user) {
@@ -843,12 +847,14 @@ public function get_users_for_display(course_enrolment_manager $manager, $sort,
'courseid' => $courseid,
'picture' => new user_picture($user),
'firstname' => fullname($user, true),
- 'email' => $user->email,
'lastseen' => $strnever,
'roles' => array(),
'groups' => array(),
'enrolments' => array()
);
+ foreach ($extrafields as $field) {
+ $details[$field] = $user->{$field};
+ }
if ($user->lastaccess) {
$details['lastseen'] = format_time($now - $user->lastaccess);
View
7 enrol/manual/ajax.php
@@ -68,9 +68,16 @@
$search = optional_param('search', '', PARAM_RAW);
$page = optional_param('page', 0, PARAM_INT);
$outcome->response = $manager->get_potential_users($enrolid, $search, true, $page);
+ $extrafields = get_extra_user_fields($context);
foreach ($outcome->response['users'] as &$user) {
$user->picture = $OUTPUT->user_picture($user);
$user->fullname = fullname($user);
+ $fieldvalues = array();
+ foreach ($extrafields as $field) {
+ $fieldvalues[] = s($user->{$field});
+ unset($user->{$field});
+ }
+ $user->extrafields = implode(', ', $fieldvalues);
}
$outcome->success = true;
break;
View
4 enrol/manual/yui/quickenrolment/quickenrolment.js
@@ -44,7 +44,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
PICTURE : 'picture',
DETAILS : 'details',
FULLNAME : 'fullname',
- EMAIL : 'email',
+ EXTRAFIELDS : 'extrafields',
OPTIONS : 'options',
ODD : 'odd',
EVEN : 'even',
@@ -344,7 +344,7 @@ YUI.add('moodle-enrol_manual-quickenrolment', function(Y) {
.append(create(user.picture)))
.append(create('<div class="'+CSS.DETAILS+'"></div>')
.append(create('<div class="'+CSS.FULLNAME+'">'+user.fullname+'</div>'))
- .append(create('<div class="'+CSS.EMAIL+'">'+user.email+'</div>')))
+ .append(create('<div class="'+CSS.EXTRAFIELDS+'">'+user.extrafields+'</div>')))
.append(create('<div class="'+CSS.OPTIONS+'"></div>')
.append(create('<input type="button" class="'+CSS.ENROL+'" value="'+M.str.enrol.enrol+'" />')))
);
View
3 enrol/renderer.php
@@ -417,7 +417,8 @@ class course_enrolment_table extends html_table implements renderable {
* @static
* @var array
*/
- protected static $sortablefields = array('firstname', 'lastname', 'email');
+ protected static $sortablefields = array('firstname', 'lastname', 'idnumber', 'email',
+ 'phone1', 'phone2', 'institution', 'department' );
/**
* Constructs the table
View
17 enrol/users.php
@@ -166,13 +166,18 @@
$renderer = $PAGE->get_renderer('core_enrol');
+$userdetails = array (
+ 'picture' => false,
+ 'firstname' => get_string('firstname'),
+ 'lastname' => get_string('lastname'),
+);
+$extrafields = get_extra_user_fields($context);
+foreach ($extrafields as $field) {
+ $userdetails[$field] = get_user_field_name($field);
+}
+
$fields = array(
- 'userdetails' => array (
- 'picture' => false,
- 'firstname' => get_string('firstname'),
- 'lastname' => get_string('lastname'),
- 'email' => get_string('email')
- ),
+ 'userdetails' => $userdetails,
'lastseen' => get_string('lastaccess'),
'role' => get_string('roles', 'role'),
'group' => get_string('groups', 'group'),

0 comments on commit b849c21

Please sign in to comment.