Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-36704: wrap pending conditions in span tags

  • Loading branch information...
commit 5e9fd83df8f2c175681fa5a81d36df5ee313cb1e 1 parent 2d7c5ee
@jk3us jk3us authored sammarshallou committed
Showing with 42 additions and 33 deletions.
  1. +31 −22 lib/conditionlib.php
  2. +11 −11 lib/tests/conditionlib_test.php
View
53 lib/conditionlib.php 100644 → 100755
@@ -303,7 +303,8 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
array($this->item->groupingid, $userid));
if (!$gotit && !has_capability('moodle/site:accessallgroups', $context, $userid)) {
$available = false;
- $information .= get_string('groupingnoaccess', 'condition');
+ $information .= html_writer::tag('span',
+ get_string('groupingnoaccess', 'condition'), array('class'=>"conditionalrule groupingnoaccess"));
}
} else {
// Request is for current user - use cache
@@ -332,7 +333,8 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
$usergroupings = $CONDITIONLIB_PRIVATE->groupingscache[$this->item->course];
if ($usergroupings !== true && !array_key_exists($this->item->groupingid, $usergroupings)) {
$available = false;
- $information .= get_string('groupingnoaccess', 'condition');
+ $information .= html_writer::tag('span',
+ get_string('groupingnoaccess', 'condition'), array('class'=>"conditionalrule groupingnoaccess"));
}
}
}
@@ -776,9 +778,9 @@ public function get_full_information($modinfo=null) {
if (empty($modinfo->cms[$cmid])) {
continue;
}
- $information .= get_string(
- 'requires_completion_' . $expectedcompletion,
- 'condition', $modinfo->cms[$cmid]->name) . ' ';
+ $information .= html_writer::tag('span',
+ get_string('requires_completion_' . $expectedcompletion, 'condition', $modinfo->cms[$cmid]->name).' ',
+ array('class'=>"conditionalrule requires_completion"));
}
}
@@ -797,7 +799,8 @@ public function get_full_information($modinfo=null) {
} else {
$string = 'range';
}
- $information .= get_string('requires_grade_'.$string, 'condition', $minmax->name).' ';
+ $information .= html_writer::tag('span', get_string('requires_grade_'.$string, 'condition', $minmax->name).' ',
+ array('class'=>"conditionalrule requires_grade"));
}
}
@@ -859,19 +862,22 @@ public function get_full_information($modinfo=null) {
if ($this->item->availablefrom && $this->item->availableuntil) {
if ($shortfrom && $shortuntil && $daybeforeuntil == $this->item->availablefrom) {
- $information .= get_string('requires_date_both_single_day', 'condition',
- self::show_time($this->item->availablefrom, true));
+ $information .= html_writer::tag('span',
+ get_string('requires_date_both_single_day', 'condition', self::show_time($this->item->availablefrom, true)),
+ array('class'=>"conditionalrule requires_date_both_single_day"));
} else {
- $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::tag('span',
+ get_string('requires_date_both', 'condition',
+ (object)array('from' => self::show_time($this->item->availablefrom, $shortfrom),
+ 'until' => self::show_time($displayuntil, $shortuntil))),
+ array('class'=>"conditionalrule requires_date_both"));
}
} else if ($this->item->availablefrom) {
- $information .= get_string('requires_date', 'condition',
- self::show_time($this->item->availablefrom, $shortfrom));
+ $information .= html_writer::tag('span', get_string('requires_date', 'condition',
+ self::show_time($this->item->availablefrom, $shortfrom)), array('class'=>"conditionalrule requires_date"));
} else if ($this->item->availableuntil) {
- $information .= get_string('requires_date_before', 'condition',
- self::show_time($displayuntil, $shortuntil));
+ $information .= html_writer::tag('span', get_string('requires_date_before', 'condition',
+ self::show_time($displayuntil, $shortuntil)), array('class'=>"conditionalrule requires_date_before"));
}
$information = trim($information);
@@ -971,9 +977,9 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
}
if (!$thisisok) {
$available = false;
- $information .= get_string(
- 'requires_completion_' . $expectedcompletion,
- 'condition', $modinfo->cms[$cmid]->name) . ' ';
+ $information .= html_writer::tag('span',
+ get_string('requires_completion_' . $expectedcompletion, 'condition', $modinfo->cms[$cmid]->name).' ',
+ array('class'=>"conditionalrule requires_completion"));
}
}
}
@@ -999,7 +1005,9 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
} else {
$string = 'range';
}
- $information .= get_string('requires_grade_' . $string, 'condition', $minmax->name) . ' ';
+ $information .= html_writer::tag('span',
+ get_string('requires_grade_' . $string, 'condition', $minmax->name).' ',
+ array('class'=>"conditionalrule requires_grade"));
}
}
}
@@ -1024,9 +1032,10 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
if (time() < $this->item->availablefrom) {
$available = false;
- $information .= get_string('requires_date', 'condition',
- self::show_time($this->item->availablefrom,
- self::is_midnight($this->item->availablefrom)));
+ $information .= html_writer::tag('span',
+ get_string('requires_date', 'condition',
+ self::show_time($this->item->availablefrom, self::is_midnight($this->item->availablefrom))),
+ array('class'=>"conditionalrule availablefrom"));
}
}
View
22 lib/tests/conditionlib_test.php 100644 → 100755
@@ -481,7 +481,7 @@ function test_is_available() {
condition_info::wipe_session_cache();
$this->assertFalse($ci->is_available($text,false));
- $this->assertEquals(get_string('requires_completion_1','condition','xxx'),$text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_completion_1','condition','xxx').' ',array('class'=>'conditionalrule requires_completion')),$text);
completion_info::wipe_session_cache();
$completion=new completion_info($DB->get_record('course',array('id'=>$courseid)));
$completion->update_state($oldcm,COMPLETION_COMPLETE);
@@ -513,7 +513,7 @@ function test_is_available() {
// Add a condition on a value existing...
$ci->add_grade_condition($gradeitemid,null,null,true);
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_any','condition','frog'),$text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_any','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
// Fake it existing
$DB->insert_record('grade_grades',(object)array(
@@ -529,7 +529,7 @@ function test_is_available() {
$ci->add_grade_condition($gradeitemid,3.78001,null,true);
condition_info::wipe_session_cache();
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_min','condition','frog'),$text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_min','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
// ...just on 3.78...
$ci->wipe_conditions();
@@ -542,7 +542,7 @@ function test_is_available() {
$ci->add_grade_condition($gradeitemid,null,3.78,true);
condition_info::wipe_session_cache();
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_max','condition','frog'),$text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_max','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
// ...less than 3.78001
$ci->wipe_conditions();
@@ -561,7 +561,7 @@ function test_is_available() {
$ci->add_grade_condition($gradeitemid,4,5,true);
condition_info::wipe_session_cache();
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_range','condition','frog'),$text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_range','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
}
public function test_section_is_available() {
@@ -632,7 +632,7 @@ public function test_section_is_available() {
// Completion: Check
$this->assertFalse($ci->is_available($text, false));
- $this->assertEquals(get_string('requires_completion_1', 'condition', 'xxx'), $text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_completion_1', 'condition', 'xxx').' ',array('class'=>'conditionalrule requires_completion')), $text);
completion_info::wipe_session_cache();
$completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
$completion->update_state($cm, COMPLETION_COMPLETE);
@@ -665,7 +665,7 @@ public function test_section_is_available() {
$ci->wipe_conditions();
$ci->add_grade_condition($gradeitemid, null, null, true);
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_any', 'condition', 'frog'), $text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_any', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
// Grade: Fake it existing
$DB->insert_record('grade_grades', (object)array(
@@ -680,7 +680,7 @@ public function test_section_is_available() {
$ci->add_grade_condition($gradeitemid, 3.78001, null, true);
condition_info_section::wipe_session_cache();
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_min', 'condition', 'frog'), $text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_min', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
// Grade: ...just on 3.78...
$ci->wipe_conditions();
@@ -693,7 +693,7 @@ public function test_section_is_available() {
$ci->add_grade_condition($gradeitemid, null, 3.78, true);
condition_info_section::wipe_session_cache();
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_max', 'condition', 'frog'), $text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_max', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
// Grade: ...less than 3.78001
$ci->wipe_conditions();
@@ -712,7 +712,7 @@ public function test_section_is_available() {
$ci->add_grade_condition($gradeitemid, 4, 5, true);
condition_info_section::wipe_session_cache();
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(get_string('requires_grade_range', 'condition', 'frog'), $text);
+ $this->assertEquals(html_writer::tag('span',get_string('requires_grade_range', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
// Grouping: Not member
$groupingid = $this->make_grouping($courseid, 'Grouping');
@@ -721,7 +721,7 @@ public function test_section_is_available() {
$ci = new condition_info_section((object)array('id' => $sectionid),
CONDITION_MISSING_EVERYTHING);
$this->assertFalse($ci->is_available($text));
- $this->assertEquals(trim(get_string('groupingnoaccess', 'condition')), $text);
+ $this->assertEquals(html_writer::tag('span',get_string('groupingnoaccess', 'condition'),array('class'=>'conditionalrule groupingnoaccess')), $text);
// Grouping: Member
$this->assertTrue(groups_add_member($groupid, $USER->id));
Please sign in to comment.
Something went wrong with that request. Please try again.