From 9a8caba23896fecce12cfc4e523e39a05e4a0d3b Mon Sep 17 00:00:00 2001 From: Danny Wahl Date: Tue, 4 Dec 2012 15:32:23 +0800 Subject: [PATCH] MDL-36991: Conditional activity restrictions should be displayed as list --- lang/en/condition.php | 4 ++-- lib/conditionlib.php | 49 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/lang/en/condition.php b/lang/en/condition.php index a888d8c7747..092b961f754 100644 --- a/lang/en/condition.php +++ b/lang/en/condition.php @@ -98,6 +98,6 @@ $string['showavailabilitysection_show'] = 'Show section greyed-out, with restric $string['startswith'] = 'starts with'; $string['userfield'] = 'User field'; $string['userfield_help'] = 'You can restrict access based on any field from the users profile.'; -$string['userrestriction_hidden'] = 'Restricted (completely hidden, no message): ‘{$a}’'; -$string['userrestriction_visible'] = 'Restricted: ‘{$a}’'; +$string['userrestriction_hidden'] = 'Restricted (completely hidden, no message): {$a}'; +$string['userrestriction_visible'] = 'Restricted: {$a}'; $string['groupingnoaccess'] = 'You do not currently belong to a group which has access to this section. '; diff --git a/lib/conditionlib.php b/lib/conditionlib.php index 96b958069d2..9ee57b06c91 100644 --- a/lib/conditionlib.php +++ b/lib/conditionlib.php @@ -761,6 +761,7 @@ abstract class condition_info_base { $information = ''; + // Completion conditions if (count($this->item->conditionscompletion) > 0) { if ($this->item->course == $COURSE->id) { @@ -776,9 +777,11 @@ abstract class condition_info_base { if (empty($modinfo->cms[$cmid])) { continue; } + $information .= html_writer::start_tag('li'); $information .= get_string( 'requires_completion_' . $expectedcompletion, 'condition', $modinfo->cms[$cmid]->name) . ' '; + $information .= html_writer::end_tag('li'); } } @@ -797,7 +800,9 @@ abstract class condition_info_base { } else { $string = 'range'; } + $information .= html_writer::start_tag('li'); $information .= get_string('requires_grade_'.$string, 'condition', $minmax->name).' '; + $information .= html_writer::end_tag('li'); } } @@ -808,7 +813,9 @@ abstract class condition_info_base { $a = new stdclass; $a->field = $details->fieldname; $a->value = $details->value; + $information .= html_writer::start_tag('li'); $information .= get_string('requires_user_field_'.$details->operator, 'condition', $a) . ' '; + $information .= html_writer::end_tag('li'); } } @@ -859,22 +866,41 @@ abstract class condition_info_base { if ($this->item->availablefrom && $this->item->availableuntil) { if ($shortfrom && $shortuntil && $daybeforeuntil == $this->item->availablefrom) { + $information .= html_writer::start_tag('li'); $information .= get_string('requires_date_both_single_day', 'condition', self::show_time($this->item->availablefrom, true)); + $information .= html_writer::end_tag('li'); } else { + $information .= html_writer::start_tag('li'); $information .= get_string('requires_date_both', 'condition', (object)array( 'from' => self::show_time($this->item->availablefrom, $shortfrom), 'until' => self::show_time($displayuntil, $shortuntil))); + $information .= html_writer::end_tag('li'); } } else if ($this->item->availablefrom) { + $information .= html_writer::start_tag('li'); $information .= get_string('requires_date', 'condition', self::show_time($this->item->availablefrom, $shortfrom)); + $information .= html_writer::end_tag('li'); } else if ($this->item->availableuntil) { + $information .= html_writer::start_tag('li'); $information .= get_string('requires_date_before', 'condition', self::show_time($displayuntil, $shortuntil)); + $information .= html_writer::end_tag('li'); } - $information = trim($information); + // The information is in
  • tags, but to avoid taking up more space + // if there is only a single item, we strip out the list tags so that it + // is plain text in that case. + if (!empty($information)) { + $li = strpos($information, '
  • ', 4); + if ($li === false) { + $information = preg_replace('~^
  • (.*)
  • $~', '$1', $information); + } else { + $information = html_writer::tag('ul', $information); + } + $information = trim($information); + } return $information; } @@ -971,9 +997,11 @@ abstract class condition_info_base { } if (!$thisisok) { $available = false; + $information .= html_writer::start_tag('li'); $information .= get_string( 'requires_completion_' . $expectedcompletion, 'condition', $modinfo->cms[$cmid]->name) . ' '; + $information .= html_writer::end_tag('li'); } } } @@ -999,7 +1027,9 @@ abstract class condition_info_base { } else { $string = 'range'; } + $information .= html_writer::start_tag('li'); $information .= get_string('requires_grade_' . $string, 'condition', $minmax->name) . ' '; + $information .= html_writer::end_tag('li'); } } } @@ -1014,7 +1044,9 @@ abstract class condition_info_base { $a = new stdClass(); $a->field = $details->fieldname; $a->value = $details->value; + $information .= html_writer::start_tag('li'); $information .= get_string('requires_user_field_'.$details->operator, 'condition', $a) . ' '; + $information .= html_writer::end_tag('li'); } } } @@ -1024,9 +1056,11 @@ abstract class condition_info_base { if (time() < $this->item->availablefrom) { $available = false; + $information .= html_writer::start_tag('li'); $information .= get_string('requires_date', 'condition', self::show_time($this->item->availablefrom, self::is_midnight($this->item->availablefrom))); + $information .= html_writer::end_tag('li'); } } @@ -1055,7 +1089,18 @@ abstract class condition_info_base { $information = ''; } - $information = trim($information); + // The information is in
  • tags, but to avoid taking up more space + // if there is only a single item, we strip out the list tags so that it + // is plain text in that case. + if (!empty($information)) { + $li = strpos($information, '
  • ', 4); + if ($li === false) { + $information = preg_replace('~^
  • (.*)
  • $~', '$1', $information); + } else { + $information = html_writer::tag('ul', $information); + } + $information = trim($information); + } return $available; }