Skip to content

Commit

Permalink
Merge pull request #54 from ngandrass/feature/idnumber-integration
Browse files Browse the repository at this point in the history
Feature: Student ID number integration
  • Loading branch information
ngandrass authored Oct 29, 2024
2 parents 04f8d4d + ff67e9f commit 5835c60
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## Version x.x.x (yyyymmddnn)

- Add student ID number to quiz attempt header
- Add student ID number to exported `attempts_metadata.csv` file inside quiz archives
- Allow student ID number to be used in attempt filename pattern as `${idnumber}`
- Improve display of user firstname, lastname, and avatar in quiz attempt header
- Improve display of empty values in quiz attempt header (e.g., feedback, idnumber, ...)
- Fix name of `QUIZ_ARCHIVER_PREVENT_REDIRECT_TO_LOGIN` environment variable in archive worker documentation
- Fix single unit test suit execution command in developer documentation
- Improve content spacing in docs


Expand Down
2 changes: 2 additions & 0 deletions classes/ArchiveJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class ArchiveJob {
'username',
'firstname',
'lastname',
'idnumber',
'timestart',
'timefinish',
'date',
Expand Down Expand Up @@ -1218,6 +1219,7 @@ public static function generate_attempt_filename($course, $cm, $quiz, int $attem
'username' => $userinfo->username,
'firstname' => $userinfo->firstname,
'lastname' => $userinfo->lastname,
'idnumber' => $userinfo->idnumber,
];

// Substitute variables.
Expand Down
25 changes: 17 additions & 8 deletions classes/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function get_attempts_metadata(?array $filterattemptids = null): array {
// Get all requested attempts.
return $DB->get_records_sql(
"SELECT qa.id AS attemptid, qa.userid, qa.attempt, qa.state, qa.timestart, qa.timefinish, ".
" u.username, u.firstname, u.lastname ".
" u.username, u.firstname, u.lastname, u.idnumber ".
"FROM {quiz_attempts} qa LEFT JOIN {user} u ON qa.userid = u.id ".
"WHERE qa.preview = 0 AND qa.quiz = :quizid " . ($filterwhereclause ?? ''),
[
Expand Down Expand Up @@ -393,17 +393,26 @@ public function generate(int $attemptid, array $sections): string {

// Section: Quiz header.
if ($sections['header']) {

$quizheaderdata = [];

// User name and link.
$attemptuser = $DB->get_record('user', ['id' => $attemptobj->get_userid()]);
$userpicture = new \user_picture($attemptuser);
$userpicture->courseid = $attemptobj->get_courseid();
$userlink = new \action_link(
new \moodle_url('/user/view.php', ['id' => $attemptuser->id, 'course' => $attemptobj->get_courseid()]),
fullname($attemptuser, true)
);
global $OUTPUT;
$quizheaderdata['user'] = [
'title' => $userpicture,
'content' => new \action_link(
new \moodle_url('/user/view.php', ['id' => $attemptuser->id, 'course' => $attemptobj->get_courseid()]),
fullname($attemptuser, true)
),
'title' => get_string('user'),
'content' => $OUTPUT->render($userpicture) . ' ' . $OUTPUT->render($userlink),
];

// User ID number.
$quizheaderdata['useridnumber'] = [
'title' => get_string('idnumber'),
'content' => $attemptuser->idnumber ?: '<i>'.get_string('none').'</i>',
];

// Quiz metadata.
Expand Down Expand Up @@ -494,7 +503,7 @@ public function generate(int $attemptid, array $sections): string {
$feedback = $attemptobj->get_overall_feedback($grade);
$quizheaderdata['feedback'] = [
'title' => get_string('feedback', 'quiz'),
'content' => $feedback,
'content' => $feedback ?: '<i>'.get_string('none').'</i>',
];
}

Expand Down
5 changes: 5 additions & 0 deletions classes/external/get_attempts_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public static function execute_returns(): external_single_structure {
'Last name for this quiz attempt',
VALUE_REQUIRED
),
'idnumber' => new external_value(
PARAM_TEXT,
'ID number of the user for this quiz attempt',
VALUE_REQUIRED
),
'timestart' => new external_value(
PARAM_INT,
'Timestamp of when the quiz attempt started',
Expand Down
2 changes: 1 addition & 1 deletion docs/development/unittests.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ you can run the tests using the following commands:
```
- Running a single test suite:
```text
vendor/bin/phpunit --colors --testdox mod/quiz/report/archiver/tests/Report_test.php
vendor/bin/phpunit --colors --testdox mod/quiz/report/archiver/tests/report_test.php
```

!!! warning
Expand Down
1 change: 1 addition & 0 deletions lang/de/quiz_archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
$string['export_attempts_filename_pattern_variable_username'] = 'Nutzer Anmeldename';
$string['export_attempts_filename_pattern_variable_firstname'] = 'Nutzer Vorname';
$string['export_attempts_filename_pattern_variable_lastname'] = 'Nutzer Nachname';
$string['export_attempts_filename_pattern_variable_idnumber'] = 'Nutzer ID-Nummer';
$string['export_attempts_filename_pattern_variable_timestart'] = 'Versuchsstart (Unix-Zeitstempel)';
$string['export_attempts_filename_pattern_variable_timefinish'] = 'Versuchsende (Unix-Zeitstempel)';
$string['export_attempts_filename_pattern_variable_date'] = 'Aktuelles Datum <small>(YYYY-MM-DD)</small>';
Expand Down
1 change: 1 addition & 0 deletions lang/en/quiz_archiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
$string['export_attempts_filename_pattern_variable_username'] = 'Student username';
$string['export_attempts_filename_pattern_variable_firstname'] = 'Student first name';
$string['export_attempts_filename_pattern_variable_lastname'] = 'Student last name';
$string['export_attempts_filename_pattern_variable_idnumber'] = 'Student ID number';
$string['export_attempts_filename_pattern_variable_timestart'] = 'Attempt start unix timestamp';
$string['export_attempts_filename_pattern_variable_timefinish'] = 'Attempt finish unix timestamp';
$string['export_attempts_filename_pattern_variable_date'] = 'Current date <small>(YYYY-MM-DD)</small>';
Expand Down
1 change: 1 addition & 0 deletions tests/report_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ public function test_get_attempts_metadata(): void {
$this->assertNotEmpty($attempt->username, 'Attempt metadata does not contain username');
$this->assertNotEmpty($attempt->firstname, 'Attempt metadata does not contain firstname');
$this->assertNotEmpty($attempt->lastname, 'Attempt metadata does not contain lastname');
$this->assertNotNull($attempt->idnumber, 'Attempt metadata does not contain idnumber'); // ID number can be empty.

// Test filtered.
$attemptsfilteredexisting = $report->get_attempts_metadata($rc->attemptids);
Expand Down

0 comments on commit 5835c60

Please sign in to comment.