Permalink
Browse files

MDL-36991: Conditional activity restrictions should be displayed as list

  • Loading branch information...
1 parent 4bd6f71 commit 9a8caba23896fecce12cfc4e523e39a05e4a0d3b Danny Wahl committed with sammarshallou Dec 4, 2012
Showing with 49 additions and 4 deletions.
  1. +2 −2 lang/en/condition.php
  2. +47 −2 lib/conditionlib.php
View
@@ -98,6 +98,6 @@
$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. ';
View
@@ -761,6 +761,7 @@ public function get_full_information($modinfo=null) {
$information = '';
+
// Completion conditions
if (count($this->item->conditionscompletion) > 0) {
if ($this->item->course == $COURSE->id) {
@@ -776,9 +777,11 @@ public function get_full_information($modinfo=null) {
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 @@ public function get_full_information($modinfo=null) {
} 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 @@ public function get_full_information($modinfo=null) {
$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 @@ public function get_full_information($modinfo=null) {
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 <li> 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, '<li>', 4);
+ if ($li === false) {
+ $information = preg_replace('~^<li>(.*)</li>$~', '$1', $information);
+ } else {
+ $information = html_writer::tag('ul', $information);
+ }
+ $information = trim($information);
+ }
return $information;
}
@@ -971,9 +997,11 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
}
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 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
} 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 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
$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 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
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 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
$information = '';
}
- $information = trim($information);
+ // The information is in <li> 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, '<li>', 4);
+ if ($li === false) {
+ $information = preg_replace('~^<li>(.*)</li>$~', '$1', $information);
+ } else {
+ $information = html_writer::tag('ul', $information);
+ }
+ $information = trim($information);
+ }
return $available;
}

0 comments on commit 9a8caba

Please sign in to comment.