MDL-26647 (8) Support showuseridentity on enrol screen
authorsam marshall <s.marshall@open.ac.uk>
Fri, 4 Nov 2011 13:01:00 +0000 (13:01 +0000)
committersam marshall <s.marshall@open.ac.uk>
Fri, 4 Nov 2011 13:57:21 +0000 (13:57 +0000)
Includes support for the table display, plus the AJAX, including search. (The fallback version uses user selector so is already supported.)

enrol/locallib.php
enrol/manual/ajax.php
enrol/manual/yui/quickenrolment/quickenrolment.js
enrol/renderer.php
enrol/users.php

index f07975a..a2a6a20 100644 (file)
@@ -199,7 +199,9 @@ class course_enrolment_manager {
         $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 @@ class course_enrolment_manager {
         $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 @@ class course_enrolment_manager {
         }
         $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 @@ class course_enrolment_manager {
         $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 @@ class course_enrolment_manager {
                 '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);
index 6f58ee4..a9d5bb7 100644 (file)
@@ -68,9 +68,16 @@ switch ($action) {
         $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;
index 1f266d5..9ed9fbb 100644 (file)
@@ -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+'" />')))
                 );
index c387dab..fafbfd7 100644 (file)
@@ -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
index ae408ae..8ff9c26 100644 (file)
@@ -166,13 +166,18 @@ if ($action) {
 
 
 $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'),