MDL-81070 course: Display contact names in the search result by admin
This commit is contained in:
@@ -129,6 +129,12 @@ class helper {
|
||||
'value' => join('<br />', $roledetails)
|
||||
);
|
||||
}
|
||||
|
||||
$contactsdetails = self::get_contacts_by_role_details($course);
|
||||
if ($contactsdetails) {
|
||||
$details['coursecontact'] = $contactsdetails;
|
||||
}
|
||||
|
||||
if ($course->can_review_enrolments()) {
|
||||
$enrolmentlines = array();
|
||||
$instances = \enrol_get_instances($course->id, true);
|
||||
@@ -163,6 +169,54 @@ class helper {
|
||||
return $details;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the course contact details, if any.
|
||||
*
|
||||
* @param \core_course_list_element $course
|
||||
* @return array|null Returns null if there are no contacts, otherwise an array of contact details.
|
||||
*/
|
||||
private static function get_contacts_by_role_details(\core_course_list_element $course): ?array {
|
||||
if (!$course->can_access()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$contactsbyrole = [];
|
||||
foreach ($course->get_course_contacts() as $contact) {
|
||||
$rolenames = array_map(
|
||||
fn($role) => $role->displayname,
|
||||
$contact['roles']
|
||||
);
|
||||
$contacturl = new \moodle_url('/user/view.php', ['id' => $contact['user']->id]);
|
||||
$coursecontact = \html_writer::link($contacturl, $contact['username']);
|
||||
|
||||
foreach ($rolenames as $rolename) {
|
||||
if (!array_key_exists($rolename, $contactsbyrole)) {
|
||||
$contactsbyrole[$rolename] = [];
|
||||
}
|
||||
$contactsbyrole[$rolename][] = $coursecontact;
|
||||
}
|
||||
}
|
||||
$contactsbyrolelist = [];
|
||||
foreach ($contactsbyrole as $rolename => $contacts) {
|
||||
$contactsbyrolelist[] = get_string(
|
||||
'contactsbyrolelist',
|
||||
'moodle',
|
||||
(object) [
|
||||
'role' => $rolename,
|
||||
'contacts' => implode(', ', $contacts),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($contactsbyrolelist)) {
|
||||
return null;
|
||||
}
|
||||
return [
|
||||
'key' => \get_string('coursecontact', 'admin'),
|
||||
'value' => join('<br>', $contactsbyrolelist),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of actions that can be performed upon a category being shown in a list.
|
||||
*
|
||||
|
||||
@@ -27,6 +27,35 @@ Feature: Courses can be searched for and moved in bulk.
|
||||
And I should not see "English Y1"
|
||||
And I should not see "English Y2"
|
||||
|
||||
Scenario: Search courses displays contact names
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | t1@example.com |
|
||||
| teacher2 | Teacher | 2 | t2@example.com |
|
||||
| teacher3 | Teacher | 3 | t3@example.com |
|
||||
| teacher4 | Teacher | 4 | t3@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | BIO1 | editingteacher |
|
||||
| teacher2 | ENG2 | editingteacher |
|
||||
| teacher3 | BIO1 | teacher |
|
||||
| teacher4 | BIO1 | editingteacher |
|
||||
And I log in as "admin"
|
||||
And I navigate to "Appearance > Courses" in site administration
|
||||
And I set the following fields to these values:
|
||||
| Teacher | 1 |
|
||||
| Non-editing teacher | 1 |
|
||||
And I press "Save changes"
|
||||
When I go to the courses management page
|
||||
And I set the field "Search" to "BIO1"
|
||||
And I press "Search"
|
||||
Then I should see "Biology Y1"
|
||||
When I follow "Biology Y1"
|
||||
Then I should see "Course contacts"
|
||||
And I should see "Teacher: Teacher 1, Teacher 4"
|
||||
And I should see "Non-editing teacher: Teacher 3"
|
||||
And I should not see "Teacher: Teacher 2"
|
||||
|
||||
@javascript
|
||||
Scenario: Search courses and move results in bulk
|
||||
Given I log in as "admin"
|
||||
|
||||
@@ -297,6 +297,7 @@ $string['confirmednot'] = 'Your registration has not yet been confirmed. Please
|
||||
$string['confirmcheckfull'] = 'Are you absolutely sure you want to confirm {$a} ?';
|
||||
$string['confirmcoursemove'] = 'Are you sure you want to move this course ({$a->course}) into this category ({$a->category})?';
|
||||
$string['considereddigitalminor'] = 'You are too young to create an account on this site.';
|
||||
$string['contactsbyrolelist'] = '{$a->role}: {$a->contacts}';
|
||||
$string['content'] = 'Content';
|
||||
$string['contentexport_aboutthiscourse'] = 'Course summary';
|
||||
$string['contentexport_coursesummary'] = 'This file is part of the content downloaded from <a href="{$a->courselink}">{$a->coursename}</a>.';
|
||||
|
||||
Reference in New Issue
Block a user