Skip to content

Commit

Permalink
Improve layout of unenrolments
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchi committed Sep 24, 2024
1 parent d16f375 commit ed42938
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions classes/local/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ private function get_course_filter(): array {
*/
public function user_courses(): array {
global $DB;
$roleassignments = $DB->get_records_sql("SELECT ra.id raid, c.id course_id, c.fullname, c.idnumber,
c.startdate, ra.roleid
$roleassignments = $DB->get_records_sql("SELECT ra.id raid, c.id course_id, c.fullname, c.idnumber, c.shortname,
c.startdate, c.enddate, ra.roleid
FROM {course} c
JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = 50
JOIN {role_assignments} ra ON ra.contextid = ctx.id
Expand Down
28 changes: 15 additions & 13 deletions form.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,25 @@ public function definition() {
$enrolments = $customdata['enrolments'];

echo get_string('unenrolselect', 'local_enrolstaff');

$ccount = 0;
foreach ($enrolments as $course) {
$odd = $ccount & 1;
$style = $odd ? 'background-color: var(--gray-200)' : 'background-color: var(--gray-100)';
$enddate = ($course->enddate > 0) ? date('d/m/Y', $course->enddate) : '';
$label = get_string('courselabel', 'local_enrolstaff', [
'fullname' => $course->fullname,
'idnumber' => $course->idnumber,
'startunix' => date('d/m/Y', $course->startdate)]);
$label .= get_string('existingroles', 'local_enrolstaff', $course->roles);
'idnumber' => $course->shortname,
'startunix' => date('d/m/Y', $course->startdate),
'endunix' => $enddate,
]);
$label .= '<br />' . get_string('existingroles', 'local_enrolstaff', $course->roles);

$mform->addElement("html", "
<div id='fitem_id_courses' class='fitem fitem_fcheckbox femptylabel'>
<div class='felement fcheckbox'>
<span>
<input name='courses[]' type='checkbox' value='" . $course->course_id . "' id='id_courses'>
<label for='id_courses'>" . $label . "</label>
</span>
</div>
</div>");
$mform->addElement("html", '
<div class="w-100 p1" style="' . $style . '">
<input name="courses[]" type="checkbox" value="' . $course->course_id . '" id="id_courses">
<label for="id_courses">' . $label . '</label>
</div>');
$ccount++;
}

$mform->addElement('hidden', 'action', 'unenrol_select');
Expand Down
8 changes: 4 additions & 4 deletions tests/behat/enrol.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Feature: Staff member self-enrols onto an existing course
And I set the field "Module code" to "M1"
And I press "Search"
Then I should see "Select a module"
And I click on "M1 - Module 1" "radio"
And I click on "Module 1" "radio"
And I press "Select module"
Then I should see "You are about to send a request for enrolment on Module 1 with the role of Module leader"
And I press "Confirm"
Expand All @@ -82,7 +82,7 @@ Feature: Staff member self-enrols onto an existing course
And I set the field "Module code" to "M2"
And I press "Search"
Then I should see "Select a module"
And I click on "M2 - Module 2" "radio"
And I click on "Module 2" "radio"
And I press "Select module"
Then I should see "You are about to be enrolled on Module 2 with the role of Tutor"
And I press "Confirm"
Expand All @@ -102,7 +102,7 @@ Feature: Staff member self-enrols onto an existing course
And I set the field "Module code" to "QHO"
And I press "Search"
Then I should see "Select a module"
And I click on "QHO1 - QModule 1" "radio"
And I click on "QModule 1" "radio"
And I press "Select module"
Then I should see "You are about to send a request for enrolment on QModule 1 with the role of QA Module leader"
And I press "Confirm"
Expand All @@ -120,7 +120,7 @@ Feature: Staff member self-enrols onto an existing course
And I set the field "Module code" to "QHO"
And I press "Search"
Then I should see "Select a module"
And I click on "QHO1 - QModule 1" "radio"
And I click on "QModule 1" "radio"
And I press "Select module"
Then I should see "You are about to be enrolled on QModule 1 with the role of QA Tutor"
And I press "Confirm"
Expand Down
15 changes: 9 additions & 6 deletions tests/behat/unenrol.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ Feature: Staff member self-unenrols from an existing course
When I visit "/local/enrolstaff/enrolstaff.php"
And I press "Unenrol from modules"
Then I should see "Staff Unenrolment"
And I should see "M2 - Module 2 - Start date: 01/09/2023 (already enrolled as Tutor, QA Tutor)"
When I click on "M2 - Module 2 - Start date: 01/09/2023 (already enrolled as Tutor, QA Tutor)" "checkbox"
And I should see "Module 2"
And I should see "(already enrolled as Tutor, QA Tutor)"
When I click on "Module 2" "checkbox"
And I press "Unenrol from modules"
Then I should see "You have selected to unenrol from the following modules:"
And I should see "M2 - Module 2"
Expand All @@ -88,8 +89,9 @@ Feature: Staff member self-unenrols from an existing course
When I visit "/local/enrolstaff/enrolstaff.php"
And I press "Unenrol from modules"
Then I should see "Staff Unenrolment"
And I should see "M2 - Module 2 - Start date: 01/09/2023 (already enrolled as Tutor)"
When I click on "M2 - Module 2 - Start date: 01/09/2023 (already enrolled as Tutor)" "checkbox"
And I should see "Module 2"
And I should see "(already enrolled as Tutor)"
When I click on "Module 2" "checkbox"
And I press "Unenrol from modules"
Then I should see "You have selected to unenrol from the following modules:"
And I should see "M2 - Module 2"
Expand All @@ -113,8 +115,9 @@ Feature: Staff member self-unenrols from an existing course
When I visit "/local/enrolstaff/enrolstaff.php"
And I press "Unenrol from modules"
Then I should see "Staff Unenrolment"
And I should see "M2 - Module 2 - Start date: 01/09/2023 (already enrolled as Student, Tutor, QA Tutor)"
When I click on "M2 - Module 2 - Start date: 01/09/2023 (already enrolled as Student, Tutor, QA Tutor)" "checkbox"
And I should see "Module 2"
And I should see "(already enrolled as Student, Tutor, QA Tutor)"
When I click on "Module 2" "checkbox"
And I press "Unenrol from modules"
Then I should see "You have selected to unenrol from the following modules:"
And I should see "M2 - Module 2"
Expand Down

0 comments on commit ed42938

Please sign in to comment.