From 5b2f32ca92121a1ffdb7a164ca52bc5210dfcf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Fri, 9 Jun 2017 10:37:29 +0200 Subject: [PATCH] MDL-58985 course: Fix display of availability information The availability info text can be either a one line short text such as "Hidden from students" but it can also be a long HTML formatted text with the list of all restricted access conditions. For the latter, using bootstrap labels was not appropriate. This extends the template context data with some boolean flags that allow to better distinguish the source and meaning of the availability information and display it accordingly. Credit goes to Marina Glancy for the solution idea. --- course/format/renderer.php | 4 +- course/renderer.php | 23 +++++++++-- .../templates/core/availability_info.mustache | 38 ++++++++++++++++++- .../templates/core/availability_info.mustache | 38 ++++++++++++++++++- 4 files changed, 94 insertions(+), 9 deletions(-) diff --git a/course/format/renderer.php b/course/format/renderer.php index f16bdd61ca3..b630ad8bef4 100644 --- a/course/format/renderer.php +++ b/course/format/renderer.php @@ -559,7 +559,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { // so there is definitely something to print. $formattedinfo = \core_availability\info::format_info( $section->availableinfo, $section->course); - $o .= $this->courserenderer->availability_info($formattedinfo); + $o .= $this->courserenderer->availability_info($formattedinfo, 'isrestricted'); } } else if ($canviewhidden && !empty($CFG->enableavailability)) { // Check if there is an availability restriction. @@ -568,7 +568,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base { if ($fullinfo) { $formattedinfo = \core_availability\info::format_info( $fullinfo, $section->course); - $o .= $this->courserenderer->availability_info($formattedinfo); + $o .= $this->courserenderer->availability_info($formattedinfo, 'isrestricted isfullinfo'); } } return $o; diff --git a/course/renderer.php b/course/renderer.php index bee3fe78f70..565f90c3f80 100644 --- a/course/renderer.php +++ b/course/renderer.php @@ -728,7 +728,24 @@ class core_course_renderer extends plugin_renderer_base { * @return string */ public function availability_info($text, $additionalclasses = '') { + $data = ['text' => $text, 'classes' => $additionalclasses]; + $additionalclasses = array_filter(explode(' ', $additionalclasses)); + + if (in_array('ishidden', $additionalclasses)) { + $data['ishidden'] = 1; + + } else if (in_array('isstealth', $additionalclasses)) { + $data['isstealth'] = 1; + + } else if (in_array('isrestricted', $additionalclasses)) { + $data['isrestricted'] = 1; + + if (in_array('isfullinfo', $additionalclasses)) { + $data['isfullinfo'] = 1; + } + } + return $this->render_from_template('core/availability_info', $data); } @@ -752,7 +769,7 @@ class core_course_renderer extends plugin_renderer_base { if (!empty($mod->availableinfo)) { $formattedinfo = \core_availability\info::format_info( $mod->availableinfo, $mod->get_course()); - $output = $this->availability_info($formattedinfo); + $output = $this->availability_info($formattedinfo, 'isrestricted'); } return $output; } @@ -775,9 +792,9 @@ class core_course_renderer extends plugin_renderer_base { // Display information about conditional availability. // Don't add availability information if user is not editing and activity is hidden. if ($mod->visible || $this->page->user_is_editing()) { - $hidinfoclass = ''; + $hidinfoclass = 'isrestricted isfullinfo'; if (!$mod->visible) { - $hidinfoclass = 'hide'; + $hidinfoclass .= ' hide'; } $ci = new \core_availability\info_module($mod); $fullinfo = $ci->get_full_information(); diff --git a/theme/boost/templates/core/availability_info.mustache b/theme/boost/templates/core/availability_info.mustache index 3cc64343b67..56cf9c37528 100644 --- a/theme/boost/templates/core/availability_info.mustache +++ b/theme/boost/templates/core/availability_info.mustache @@ -15,13 +15,47 @@ along with Moodle. If not, see . }} {{! - Availability info. + @template core/availability_info + + Renders the availability info on the course outline page. + + Availability info can be displayed for activity modules or whole course + sections. Activity modules can be either hidden from students, or available + but not shown on course page (stealth), or the access can be restricted by + configured conditions. Sections can be hidden. + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * classes String list of CSS classes for the wrapping element + * text HTML formatted text with the actual availability information + * ishidden Boolean flag indiciating that the item is hidden from students + * isstealth Boolean flag indicating that the item is in stealth mode + * isrestricted Boolean flag indicating that restricted access conditions apply + * isfullinfo Boolean flag indicating that the full list of restricted + access conditions is displayed (aka teacher's view). Example context (json): - { "classes": "", "text": "This activity is not available" } + { + "classes": "", + "text": "Not available unless: ", + "ishidden": 0, + "isstealth": 0, + "isrestricted": 1, + "isfullinfo": 1 + } }} {{#text}}
+ {{^isrestricted}} {{{text}}} + {{/isrestricted}} + {{#isrestricted}} + {{#str}}restricted, core{{/str}} {{{text}}} + {{/isrestricted}}
{{/text}} diff --git a/theme/bootstrapbase/templates/core/availability_info.mustache b/theme/bootstrapbase/templates/core/availability_info.mustache index fd81eb50ea1..ee90c956307 100644 --- a/theme/bootstrapbase/templates/core/availability_info.mustache +++ b/theme/bootstrapbase/templates/core/availability_info.mustache @@ -15,13 +15,47 @@ along with Moodle. If not, see . }} {{! - Availability info. + @template core/availability_info + + Renders the availability info on the course outline page. + + Availability info can be displayed for activity modules or whole course + sections. Activity modules can be either hidden from students, or available + but not shown on course page (stealth), or the access can be restricted by + configured conditions. Sections can be hidden. + + Classes required for JS: + * none + + Data attributes required for JS: + * none + + Context variables required for this template: + * classes String list of CSS classes for the wrapping element + * text HTML formatted text with the actual availability information + * ishidden Boolean flag indiciating that the item is hidden from students + * isstealth Boolean flag indicating that the item is in stealth mode + * isrestricted Boolean flag indicating that restricted access conditions apply + * isfullinfo Boolean flag indicating that the full list of restricted + access conditions is displayed (aka teacher's view). Example context (json): - { "classes": "", "text": "This activity is not available" } + { + "classes": "", + "text": "Not available unless:
  • It is on or after 8 June 2012
", + "ishidden": 0, + "isstealth": 0, + "isrestricted": 1, + "isfullinfo": 1 + } }} {{#text}}
+ {{^isrestricted}} {{{text}}} + {{/isrestricted}} + {{#isrestricted}} + {{#str}}restricted, core{{/str}} {{{text}}} + {{/isrestricted}}
{{/text}}