MDL-86159 mod_bigbluebuttonbn: consistent/correct course name format.

This commit is contained in:
Paul Holden
2025-11-14 07:57:47 +00:00
parent 982a10e9cf
commit a02b804a77
3 changed files with 54 additions and 13 deletions
@@ -26,8 +26,8 @@ namespace mod_bigbluebuttonbn\local\helpers;
use cache;
use cache_store;
use context;
use context_course;
use core\context;
use core\context\{course, system};
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
use stdClass;
@@ -81,11 +81,11 @@ class roles {
/**
* Returns an array containing all the users in a context wrapped for html select element.
*
* @param context_course $context
* @param course $context
* @param null $bbactivity
* @return array $users
*/
public static function get_users_array(context_course $context, $bbactivity = null) {
public static function get_users_array(course $context, $bbactivity = null) {
// CONTRIB-7972, check the group of current user and course group mode.
$groups = null;
$users = (array) get_enrolled_users($context, '', 0, 'u.*', null, 0, 0, true);
@@ -120,11 +120,10 @@ class roles {
public static function has_capability_in_course(int $courseid, string $capability) {
global $DB;
if (empty($courseid) || !$DB->record_exists('course', ['id' => $courseid])) {
return has_capability('moodle/site:config', \context_system::instance());
return has_capability('moodle/site:config', system::instance());
}
$coursecontext = context_course::instance($courseid);
return has_capability($capability, $coursecontext);
return has_capability($capability, course::instance($courseid));
}
/**
@@ -440,7 +439,7 @@ class roles {
*/
public static function import_get_courses_for_select(instance $instance): array {
if ($instance->is_admin()) {
$courses = get_courses('all', 'c.fullname ASC');
$courses = get_courses('all', 'c.fullname ASC', 'c.id, c.shortname, c.fullname');
// It includes the name of the site as a course (category 0), so remove the first one.
unset($courses['1']);
} else {
@@ -452,7 +451,10 @@ class roles {
});
$coursesforselect = [];
foreach ($courses as $course) {
$coursesforselect[$course->id] = $course->fullname . " (" . $course->shortname . ")";
$coursesforselect[$course->id] = format_string(
get_course_display_name_for_list($course),
options: ['context' => course::instance($course->id)],
);
}
return $coursesforselect;
}
@@ -39,7 +39,7 @@ Feature: Manage and list recordings
Scenario Outline: I check that I can import recordings into the Recording activity from other activities
When I am on the "<instancename>" "bigbluebuttonbn activity" page logged in as "admin"
And I click on "Import recording links" "button"
And I select "Test Course 1 (C1)" from the "sourcecourseid" singleselect
And I select "Test Course 1" from the "sourcecourseid" singleselect
And I select "RoomRecordings" from the "sourcebn" singleselect
# add the first recording
And I click on "a.action-icon" "css_element" in the "Recording 1" "table_row"
@@ -59,7 +59,7 @@ Feature: Manage and list recordings
When I am on the "RoomRecordings1" "bigbluebuttonbn activity" page logged in as "admin"
And I change window size to "large"
And I click on "Import recording links" "button"
And I select "Test Course 1 (C1)" from the "sourcecourseid" singleselect
And I select "Test Course 1" from the "sourcecourseid" singleselect
And I select "RoomRecordings" from the "sourcebn" singleselect
# add the first recording
And I click on "a.action-icon" "css_element" in the "Recording 1" "table_row"
@@ -76,7 +76,7 @@ Feature: Manage and list recordings
And I wait until the page is ready
But I should not see "Recording 1"
And I click on "Import recording links" "button"
And I select "Test Course 1 (C1)" from the "sourcecourseid" singleselect
And I select "Test Course 1" from the "sourcecourseid" singleselect
And I select "RoomRecordings" from the "sourcebn" singleselect
And I should see "Recording 1"
@@ -17,6 +17,7 @@
namespace mod_bigbluebuttonbn\local\helpers;
use context_course;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
/**
@@ -27,7 +28,6 @@ use mod_bigbluebuttonbn\test\testcase_helper_trait;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Laurent David ([email protected])
* @covers \mod_bigbluebuttonbn\local\helpers\roles
* @coversDefaultClass \mod_bigbluebuttonbn\local\helpers\roles
*/
final class roles_test extends \advanced_testcase {
use testcase_helper_trait;
@@ -91,4 +91,43 @@ final class roles_test extends \advanced_testcase {
$users = roles::get_users_array($context, $bbactivity);
$this->assertCount($numstudents + $numteachers, $users);
}
/**
* Test getting courses from which we can import
*/
public function test_import_get_courses_for_select(): void {
$this->resetAfterTest();
$this->setAdminUser();
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
$courseone = $this->getDataGenerator()->create_course();
[$context, $cm, $activity] = $this->create_instance($courseone);
$instance = instance::get_from_instanceid($activity->id);
// Course two should be returned, because it has an activity instance.
$coursetwo = $this->getDataGenerator()->create_course([
'fullname' => '<span class="multilang" lang="en">English</span><span class="multilang" lang="es">Spanish</span>',
]);
$this->create_instance($coursetwo);
// Course three should not be returned, because it has no activity instance.
$coursethree = $this->getDataGenerator()->create_course();
$coursesforselect = roles::import_get_courses_for_select($instance);
$this->assertEquals([
$courseone->id => $courseone->fullname,
$coursetwo->id => 'English',
], $coursesforselect);
// Display extended course names.
set_config('courselistshortnames', 1);
$coursesforselect = roles::import_get_courses_for_select($instance);
$this->assertEquals([
$courseone->id => "{$courseone->shortname} {$courseone->fullname}",
$coursetwo->id => "{$coursetwo->shortname} English",
], $coursesforselect);
}
}