Skip to content

Commit

Permalink
MDL-67042 customfield: Display only fields visible to everybody
Browse files Browse the repository at this point in the history
When defining the available filters for the Dashboard, only the
fields visible to everyone should be displayed in the Custom field
filter.
  • Loading branch information
sarjona committed Nov 22, 2019
1 parent a5f618d commit 5a119f3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion blocks/myoverview/classes/output/main.php
Expand Up @@ -366,7 +366,9 @@ public function get_customfield_values_for_export() {
return [];
}
$field = \core_customfield\field_controller::create($fieldid);
if (!$field->supports_course_grouping()) {
$isvisible = $field->get_configdata_property('visibility') == \core_course\customfield\course_handler::VISIBLETOALL;
// Only visible fields to everybody supporting course grouping will be displayed.
if (!$field->supports_course_grouping() || !$isvisible) {
return []; // The field shouldn't have been selectable in the global settings, but just skip it now.
}
$values = $field->course_grouping_format_values($values);
Expand Down
2 changes: 1 addition & 1 deletion blocks/myoverview/lang/en/block_myoverview.php
Expand Up @@ -54,7 +54,7 @@
$string['completepercent'] = '{$a}% complete';
$string['customfield'] = 'Custom field';
$string['customfiltergrouping'] = 'Field to use';
$string['customfiltergrouping_nofields'] = 'This option requires a course custom field to be set up.';
$string['customfiltergrouping_nofields'] = 'This option requires a course custom field to be set up and visible to everyone.';
$string['displaycategories'] = 'Display categories';
$string['displaycategories_help'] = 'Display the course category on dashboard course items including cards, list items and summary items.';
$string['favourites'] = 'Starred';
Expand Down
4 changes: 3 additions & 1 deletion customfield/classes/api.php
Expand Up @@ -431,7 +431,9 @@ public static function get_fields_supporting_course_grouping() {
$fields = $DB->get_records_sql($sql);
foreach ($fields as $field) {
$inst = field_controller::create(0, $field);
if ($inst->supports_course_grouping()) {
$isvisible = $inst->get_configdata_property('visibility') == \core_course\customfield\course_handler::VISIBLETOALL;
// Only visible fields to everybody supporting course grouping will be displayed.
if ($inst->supports_course_grouping() && $isvisible) {
$ret[$inst->get('shortname')] = $inst->get('name');
}
}
Expand Down
2 changes: 1 addition & 1 deletion lang/en/course.php
Expand Up @@ -35,7 +35,7 @@
$string['customfield_islocked_help'] = 'If the field is locked, only users with the capability to change locked custom fields (by default users with the default role of manager only) will be able to change it in the course settings.';
$string['customfield_notvisible'] = 'Nobody';
$string['customfield_visibility'] = 'Visible to';
$string['customfield_visibility_help'] = 'This setting determines who can view the custom field name and value in the list of courses.';
$string['customfield_visibility_help'] = 'This setting determines who can view the custom field name and value in the list of courses or in the available custom field filter of the Dashboard.';
$string['customfield_visibletoall'] = 'Everyone';
$string['customfield_visibletoteachers'] = 'Teachers';
$string['customfieldsettings'] = 'Common course custom fields settings';
Expand Down

0 comments on commit 5a119f3

Please sign in to comment.