MDL-63612 core_admin: make course card colours configurable

This commit is contained in:
Bas Brands 2019-06-20 15:26:18 +02:00
parent f7e108438f
commit c5b2ab4786
5 changed files with 41 additions and 4 deletions

View File

@ -76,6 +76,24 @@ preferences,moodle|/user/preferences.php|t/preferences',
$ADMIN->add('appearance', $temp);
// Course colours section.
$temp = new admin_settingpage('coursecolors', new lang_string('coursecolorsettings', 'admin'));
$temp->add(new admin_setting_heading('coursecolorheading', '',
new lang_string('coursecolorheading_desc', 'admin')));
$basecolors = ['#81ecec', '#74b9ff', '#a29bfe', '#dfe6e9', '#00b894',
'#0984e3', '#b2bec3', '#fdcb6e', '#fd79a8', '#6c5ce7'];
foreach ($basecolors as $key => $color) {
$number = $key + 1;
$name = 'core_admin/coursecolor' . $number;
$title = get_string('coursecolor', 'admin', $number);
$setting = new admin_setting_configcolourpicker($name, $title, '', $color);
$temp->add($setting);
}
$ADMIN->add('appearance', $temp);
// Calendar settings.
$temp = new admin_settingpage('calendar', new lang_string('calendarsettings','admin'));

View File

@ -390,6 +390,9 @@ $string['cookiehttponly'] = 'Only http cookies';
$string['cookiesecure'] = 'Secure cookies only';
$string['country'] = 'Default country';
$string['course_customfield'] = 'Course custom fields';
$string['coursecolor'] = 'Colour {$a}';
$string['coursecolorheading_desc'] = 'Any courses without a course image set in the course settings are displayed on the Dashboard with a patterned course card. The colours used in the pattern may be specified below.';
$string['coursecolorsettings'] = 'Course card colours';
$string['coursecontact'] = 'Course contacts';
$string['coursecontact_desc'] = 'This setting allows you to control who appears on the course description. Users need to have at least one of these roles in a course to be shown on the course description for that course.';
$string['coursecontactduplicates'] = 'Display all course contact roles';

View File

@ -3402,5 +3402,19 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2019062900.00);
}
if ($oldversion < 2019070400.01) {
$basecolors = ['#81ecec', '#74b9ff', '#a29bfe', '#dfe6e9', '#00b894',
'#0984e3', '#b2bec3', '#fdcb6e', '#fd79a8', '#6c5ce7'];
$colornr = 1;
foreach ($basecolors as $color) {
set_config('coursecolor' . $colornr, $color, 'core_admin');
$colornr++;
}
upgrade_main_savepoint(true, 2019070400.01);
}
return true;
}

View File

@ -1570,9 +1570,11 @@ class core_renderer extends renderer_base {
* @return string hex color code.
*/
public function get_generated_color_for_id($id) {
// The colour palette is hardcoded for now. It would make sense to combine it with theme settings.
$basecolors = ['#81ecec', '#74b9ff', '#a29bfe', '#dfe6e9', '#00b894',
'#0984e3', '#b2bec3', '#fdcb6e', '#fd79a8', '#6c5ce7'];
$colornumbers = range(1, 10);
$basecolors = [];
foreach ($colornumbers as $number) {
$basecolors[] = get_config('core_admin', 'coursecolor' . $number);
}
$color = $basecolors[$id % 10];
return $color;

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2019071200.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2019071200.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.