Browse Source

Merge remote-tracking branch 'john/main-fix-490-report-fields-admin-setting' into main

nwp90-nwp90-allsessionsreport
Dan Marsden 4 years ago
parent
commit
31855f7573
  1. 2
      classes/structure.php
  2. 60
      export.php
  3. 34
      export_form.php
  4. 5
      lang/en/attendance.php
  5. 18
      settings.php
  6. 52
      tests/behat/attendance_mod.feature

2
classes/structure.php

@ -801,7 +801,7 @@ class mod_attendance_structure {
public function get_users($groupid = 0, $page = 1) : array { public function get_users($groupid = 0, $page = 1) : array {
global $DB; global $DB;
$fields = array('username' , 'idnumber' , 'institution' , 'department'); $fields = array('username' , 'idnumber' , 'institution' , 'department', 'city', 'country');
// Get user identity fields if required - doesn't return original $fields array. // Get user identity fields if required - doesn't return original $fields array.
$extrafields = get_extra_user_fields($this->context, $fields); $extrafields = get_extra_user_fields($this->context, $fields);
$fields = array_merge($fields, $extrafields); $fields = array_merge($fields, $extrafields);

60
export.php

@ -89,25 +89,29 @@ if ($formdata = $mform->get_data()) {
$data->course = $att->course->fullname; $data->course = $att->course->fullname;
$data->group = $group ? $group->name : get_string('allparticipants'); $data->group = $group ? $group->name : get_string('allparticipants');
if (isset($formdata->ident['id'])) { $data->tabhead[] = get_string('lastname');
$data->tabhead[] = get_string('firstname');
$groupmode = groups_get_activity_groupmode($cm, $course);
if (!empty($groupmode)) {
$data->tabhead[] = get_string('groups');
}
require_once($CFG->dirroot . '/user/profile/lib.php');
$customfields = profile_get_custom_fields(false);
if (isset($formdata->ident)) {
foreach (array_keys($formdata->ident) as $opt) {
if ($opt == 'id') {
$data->tabhead[] = get_string('studentid', 'attendance'); $data->tabhead[] = get_string('studentid', 'attendance');
} else if (in_array($opt, array_column($customfields, 'shortname'))) {
foreach ($customfields as $customfield) {
if ($opt == $customfield->shortname) {
$data->tabhead[] = $customfield->name;
} }
if (isset($formdata->ident['uname'])) {
$data->tabhead[] = get_string('username');
} }
} else {
$optional = array('idnumber', 'institution', 'department');
foreach ($optional as $opt) {
if (isset($formdata->ident[$opt])) {
$data->tabhead[] = get_string($opt); $data->tabhead[] = get_string($opt);
} }
} }
$data->tabhead[] = get_string('lastname');
$data->tabhead[] = get_string('firstname');
$groupmode = groups_get_activity_groupmode($cm, $course);
if (!empty($groupmode)) {
$data->tabhead[] = get_string('groups');
} }
if (count($reportdata->sessions) > 0) { if (count($reportdata->sessions) > 0) {
@ -144,19 +148,7 @@ if ($formdata = $mform->get_data()) {
$i = 0; $i = 0;
$data->table = array(); $data->table = array();
foreach ($reportdata->users as $user) { foreach ($reportdata->users as $user) {
if (isset($formdata->ident['id'])) { profile_load_custom_fields($user);
$data->table[$i][] = $user->id;
}
if (isset($formdata->ident['uname'])) {
$data->table[$i][] = $user->username;
}
$optionalrow = array('idnumber', 'institution', 'department');
foreach ($optionalrow as $opt) {
if (isset($formdata->ident[$opt])) {
$data->table[$i][] = $user->$opt;
}
}
$data->table[$i][] = $user->lastname; $data->table[$i][] = $user->lastname;
$data->table[$i][] = $user->firstname; $data->table[$i][] = $user->firstname;
@ -169,6 +161,22 @@ if ($formdata = $mform->get_data()) {
} }
$data->table[$i][] = implode(', ', $groups); $data->table[$i][] = implode(', ', $groups);
} }
if (isset($formdata->ident)) {
foreach (array_keys($formdata->ident) as $opt) {
if (in_array($opt, array_column($customfields, 'shortname'))) {
if (isset($user->profile[$opt])) {
$data->table[$i][] = $user->profile[$opt];
} else {
$data->table[$i][] = '';
}
continue;
}
$data->table[$i][] = $user->$opt;
}
}
$cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user); $cellsgenerator = new user_sessions_cells_text_generator($reportdata, $user);
$data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells(isset($formdata->includeremarks))); $data->table[$i] = array_merge($data->table[$i], $cellsgenerator->get_cells(isset($formdata->includeremarks)));

34
export_form.php

@ -39,7 +39,7 @@ class mod_attendance_export_form extends moodleform {
* @return void * @return void
*/ */
public function definition() { public function definition() {
global $USER, $DB, $PAGE; global $USER, $DB, $PAGE, $CFG;
$mform =& $this->_form; $mform =& $this->_form;
$course = $this->_customdata['course']; $course = $this->_customdata['course'];
$cm = $this->_customdata['cm']; $cm = $this->_customdata['cm'];
@ -102,19 +102,37 @@ class mod_attendance_export_form extends moodleform {
$PAGE->requires->yui_module('moodle-mod_attendance-groupfilter', 'M.mod_attendance.groupfilter.init', array($opts)); $PAGE->requires->yui_module('moodle-mod_attendance-groupfilter', 'M.mod_attendance.groupfilter.init', array($opts));
$ident = array(); $ident = array();
$checkedfields = array();
$adminsetfields = get_config('attendance', 'defaultexportfields');
if (in_array('id', explode(',', $adminsetfields))) {
$ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance')); $ident[] =& $mform->createElement('checkbox', 'id', '', get_string('studentid', 'attendance'));
$ident[] =& $mform->createElement('checkbox', 'uname', '', get_string('username')); $checkedfields['ident[id]'] = true;
}
$extrafields = get_extra_user_fields($modcontext);
foreach ($extrafields as $field) {
$ident[] =& $mform->createElement('checkbox', $field, '', get_string( $field));
$mform->setType($field, PARAM_NOTAGS);
$checkedfields['ident['. $field .']'] = true;
}
$optional = array('idnumber', 'institution', 'department'); require_once($CFG->dirroot . '/user/profile/lib.php');
foreach ($optional as $opt) { $customfields = profile_get_custom_fields();
$ident[] =& $mform->createElement('checkbox', $opt, '', get_string($opt));
$mform->setType($opt, PARAM_NOTAGS); foreach ($customfields as $field) {
if ((is_siteadmin($USER) || $field->visible == PROFILE_VISIBLE_ALL)
&& in_array($field->shortname, explode(',', $adminsetfields))) {
$ident[] =& $mform->createElement('checkbox', $field->shortname, '', $field->name);
$mform->setType($field->shortname, PARAM_NOTAGS);
$checkedfields['ident['. $field->shortname .']'] = true;
}
} }
if (count($ident) > 0) {
$mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('<br />'), true); $mform->addGroup($ident, 'ident', get_string('identifyby', 'attendance'), array('<br />'), true);
$mform->setDefaults(array('ident[id]' => true, 'ident[uname]' => true)); $mform->setDefaults($checkedfields);
}
$mform->setType('id', PARAM_INT); $mform->setType('id', PARAM_INT);
$mform->setType('uname', PARAM_INT);
$mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes')); $mform->addElement('checkbox', 'includeallsessions', get_string('includeall', 'attendance'), get_string('yes'));
$mform->setDefault('includeallsessions', true); $mform->setDefault('includeallsessions', true);

5
lang/en/attendance.php

@ -615,3 +615,8 @@ $string['warningupdated'] = 'Updated warnings';
$string['week'] = 'week(s)'; $string['week'] = 'week(s)';
$string['weeks'] = 'Weeks'; $string['weeks'] = 'Weeks';
$string['youcantdo'] = 'You can\'t do anything'; $string['youcantdo'] = 'You can\'t do anything';
$string['defaultexportsettings'] = 'Default export settings';
$string['defaultexportsettings_help'] = 'These settings define the defaults for sessions export';
$string['defaultexportfields'] = 'Default export fields';
$string['defaultexportfields_help'] = 'Fields that can be used to identify student in export report (If you are seeing less options than expected, please check show user identity in User policies).';

18
settings.php

@ -192,4 +192,22 @@ if ($ADMIN->fulltree) {
get_string('emailcontent', 'attendance'), get_string('emailcontent_help', 'attendance'), get_string('emailcontent', 'attendance'), get_string('emailcontent_help', 'attendance'),
get_string('emailcontent_default', 'attendance'), PARAM_RAW)); get_string('emailcontent_default', 'attendance'), PARAM_RAW));
$name = new lang_string('defaultexportsettings', 'mod_attendance');
$description = new lang_string('defaultexportsettings_help', 'mod_attendance');
$settings->add(new admin_setting_heading('defaultexportsettings', $name, $description));
$fields = array('id' => get_string('studentid', 'attendance'));
require_once($CFG->dirroot . '/user/profile/lib.php');
$customfields = profile_get_custom_fields();
foreach ($customfields as $field) {
$fields[$field->shortname] = $field->name;
}
$settings->add(new admin_setting_configmultiselect('attendance/defaultexportfields',
new lang_string('defaultexportfields', 'attendance'),
new lang_string('defaultexportfields_help', 'attendance'),
array('id'), $fields)
);
} }

52
tests/behat/attendance_mod.feature

@ -100,7 +100,53 @@ Feature: Teachers and Students can record session attendance
Then "Attendance report viewed" "link" should exist Then "Attendance report viewed" "link" should exist
Scenario: Export report includes id number, department and institution Scenario: Export report includes id number, department and institution
Given I log in as "teacher1" Given I log in as "admin"
And I navigate to "Users > Permissions > User policies" in site administration
And the following config values are set as admin:
| showuseridentity | idnumber,email,phone1,phone2,department,institution |
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Attendance"
And I follow "Add"
And I set the following fields to these values:
| id_sestime_starthour | 01 |
| id_sestime_endhour | 02 |
And I click on "id_submitbutton" "button"
And I follow "Export"
Then the field "id_ident_idnumber" matches value "1"
And the field "id_ident_institution" matches value "1"
And the field "id_ident_department" matches value "1"
Scenario: Test enabling custom user profile field
# Add custom field.
Given I log in as "admin"
And I navigate to "Users > Accounts > User profile fields" in site administration
And I set the field "datatype" to "Text input"
And I set the following fields to these values:
| Short name | superfield |
| Name | Super field |
And I click on "Save changes" "button"
And I navigate to "Plugins > Activity modules > Attendance" in site administration
And the "Default export fields" select box should contain "Super field"
Scenario: Test adding custom user profile
# Add custom field.
Given I log in as "admin"
And I navigate to "Users > Accounts > User profile fields" in site administration
And I set the field "datatype" to "Text input"
And I set the following fields to these values:
| Short name | superfield |
| Name | Super field |
And I click on "Save changes" "button"
And the following config values are set as admin:
| defaultexportfields | superfield | attendance |
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage And I am on "Course 1" course homepage
And I follow "Attendance" And I follow "Attendance"
And I follow "Add" And I follow "Add"
@ -109,9 +155,7 @@ Feature: Teachers and Students can record session attendance
| id_sestime_endhour | 02 | | id_sestime_endhour | 02 |
And I click on "id_submitbutton" "button" And I click on "id_submitbutton" "button"
And I follow "Export" And I follow "Export"
Then the field "id_ident_idnumber" matches value "" Then the field "id_ident_superfield" matches value "1"
And the field "id_ident_institution" matches value ""
And the field "id_ident_department" matches value ""
# Removed dependency on behat_download to allow automated Travis CI tests to pass. # Removed dependency on behat_download to allow automated Travis CI tests to pass.
# It would be good to add these back at some point. # It would be good to add these back at some point.

Loading…
Cancel
Save