This commit is contained in:
Jun Pataleta 2024-05-09 11:45:45 +08:00
commit 823c7d752e
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
2 changed files with 49 additions and 2 deletions

View File

@ -23,6 +23,7 @@ use context_system;
use context_user;
use core\context;
use core_component;
use core_date;
use html_writer;
use lang_string;
use moodle_url;
@ -429,6 +430,8 @@ class user extends base {
'email' => new lang_string('email'),
'city' => new lang_string('city'),
'country' => new lang_string('country'),
'lang' => new lang_string('language'),
'timezone' => new lang_string('timezone'),
'theme' => new lang_string('theme'),
'description' => new lang_string('description'),
'firstnamephonetic' => new lang_string('firstnamephonetic'),
@ -596,6 +599,24 @@ class user extends base {
return get_string_manager()->get_list_of_countries();
}
/**
* List of options for the field lang.
*
* @return string[]
*/
public static function get_options_for_lang(): array {
return get_string_manager()->get_list_of_translations();
}
/**
* List of options for the field timezone.
*
* @return string[]
*/
public static function get_options_for_timezone(): array {
return core_date::get_list_of_timezones(null, true);
}
/**
* List of options for the field theme.
*

View File

@ -40,7 +40,7 @@ require_once("{$CFG->dirroot}/reportbuilder/tests/helpers.php");
* @copyright 2022 Paul Holden <paulh@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class users_test extends core_reportbuilder_testcase {
final class users_test extends core_reportbuilder_testcase {
/**
* Test default datasource
@ -77,6 +77,8 @@ class users_test extends core_reportbuilder_testcase {
'idnumber' => 'U0001',
'city' => 'London',
'country' => 'GB',
'lang' => 'en',
'timezone' => 'Europe/London',
'theme' => 'boost',
'interests' => ['Horses'],
]);
@ -98,6 +100,8 @@ class users_test extends core_reportbuilder_testcase {
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastname']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:city']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:country']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lang']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:timezone']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:description']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:firstnamephonetic']);
$generator->create_column(['reportid' => $report->get('id'), 'uniqueidentifier' => 'user:lastnamephonetic']);
@ -155,6 +159,8 @@ class users_test extends core_reportbuilder_testcase {
$lastname,
$city,
$country,
$lang,
$timezone,
$description,
$firstnamephonetic,
$lastnamephonetic,
@ -187,6 +193,8 @@ class users_test extends core_reportbuilder_testcase {
$this->assertEquals($user->lastname, $lastname);
$this->assertEquals($user->city, $city);
$this->assertEquals('United Kingdom', $country);
$this->assertEquals('English (en)', $lang);
$this->assertEquals('Europe/London', $timezone);
$this->assertEquals($user->description, $description);
$this->assertEquals($user->firstnamephonetic, $firstnamephonetic);
$this->assertEquals($user->lastnamephonetic, $lastnamephonetic);
@ -216,7 +224,7 @@ class users_test extends core_reportbuilder_testcase {
*
* @return array[]
*/
public function datasource_filters_provider(): array {
public static function datasource_filters_provider(): array {
return [
// User.
'Filter user' => ['user:userselect', [
@ -327,6 +335,22 @@ class users_test extends core_reportbuilder_testcase {
'user:country_operator' => select::EQUAL_TO,
'user:country_value' => 'AU',
], false],
'Filter lang' => ['user:lang', [
'user:lang_operator' => select::EQUAL_TO,
'user:lang_value' => 'en',
], true],
'Filter lang (no match)' => ['user:lang', [
'user:lang_operator' => select::EQUAL_TO,
'user:lang_value' => 'de',
], false],
'Filter timezone' => ['user:timezone', [
'user:timezone_operator' => select::EQUAL_TO,
'user:timezone_value' => 'Europe/Barcelona',
], true],
'Filter timezone (no match)' => ['user:timezone', [
'user:timezone_operator' => select::EQUAL_TO,
'user:timezone_value' => 'Australia/Perth',
], false],
'Filter theme' => ['user:theme', [
'user:theme_operator' => select::EQUAL_TO,
'user:theme_value' => 'boost',
@ -487,6 +511,8 @@ class users_test extends core_reportbuilder_testcase {
'address' => 'Big Farm',
'city' => 'Barcelona',
'country' => 'ES',
'lang' => 'en',
'timezone' => 'Europe/Barcelona',
'theme' => 'boost',
'description' => 'Hello there',
'moodlenetprofile' => '@zoe1@example.com',