Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-36704: wrap pending conditions in span tags

  • Loading branch information...
commit 5e9fd83df8f2c175681fa5a81d36df5ee313cb1e 1 parent 2d7c5ee
Jay Knight jk3us authored sammarshallou committed

Showing 2 changed files with 42 additions and 33 deletions. Show diff stats Hide diff stats

  1. +31 22 lib/conditionlib.php
  2. +11 11 lib/tests/conditionlib_test.php
53 lib/conditionlib.php 100644 → 100755
@@ -303,7 +303,8 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
303 303 array($this->item->groupingid, $userid));
304 304 if (!$gotit && !has_capability('moodle/site:accessallgroups', $context, $userid)) {
305 305 $available = false;
306   - $information .= get_string('groupingnoaccess', 'condition');
  306 + $information .= html_writer::tag('span',
  307 + get_string('groupingnoaccess', 'condition'), array('class'=>"conditionalrule groupingnoaccess"));
307 308 }
308 309 } else {
309 310 // Request is for current user - use cache
@@ -332,7 +333,8 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
332 333 $usergroupings = $CONDITIONLIB_PRIVATE->groupingscache[$this->item->course];
333 334 if ($usergroupings !== true && !array_key_exists($this->item->groupingid, $usergroupings)) {
334 335 $available = false;
335   - $information .= get_string('groupingnoaccess', 'condition');
  336 + $information .= html_writer::tag('span',
  337 + get_string('groupingnoaccess', 'condition'), array('class'=>"conditionalrule groupingnoaccess"));
336 338 }
337 339 }
338 340 }
@@ -776,9 +778,9 @@ public function get_full_information($modinfo=null) {
776 778 if (empty($modinfo->cms[$cmid])) {
777 779 continue;
778 780 }
779   - $information .= get_string(
780   - 'requires_completion_' . $expectedcompletion,
781   - 'condition', $modinfo->cms[$cmid]->name) . ' ';
  781 + $information .= html_writer::tag('span',
  782 + get_string('requires_completion_' . $expectedcompletion, 'condition', $modinfo->cms[$cmid]->name).' ',
  783 + array('class'=>"conditionalrule requires_completion"));
782 784 }
783 785 }
784 786
@@ -797,7 +799,8 @@ public function get_full_information($modinfo=null) {
797 799 } else {
798 800 $string = 'range';
799 801 }
800   - $information .= get_string('requires_grade_'.$string, 'condition', $minmax->name).' ';
  802 + $information .= html_writer::tag('span', get_string('requires_grade_'.$string, 'condition', $minmax->name).' ',
  803 + array('class'=>"conditionalrule requires_grade"));
801 804 }
802 805 }
803 806
@@ -859,19 +862,22 @@ public function get_full_information($modinfo=null) {
859 862
860 863 if ($this->item->availablefrom && $this->item->availableuntil) {
861 864 if ($shortfrom && $shortuntil && $daybeforeuntil == $this->item->availablefrom) {
862   - $information .= get_string('requires_date_both_single_day', 'condition',
863   - self::show_time($this->item->availablefrom, true));
  865 + $information .= html_writer::tag('span',
  866 + get_string('requires_date_both_single_day', 'condition', self::show_time($this->item->availablefrom, true)),
  867 + array('class'=>"conditionalrule requires_date_both_single_day"));
864 868 } else {
865   - $information .= get_string('requires_date_both', 'condition', (object)array(
866   - 'from' => self::show_time($this->item->availablefrom, $shortfrom),
867   - 'until' => self::show_time($displayuntil, $shortuntil)));
  869 + $information .= html_writer::tag('span',
  870 + get_string('requires_date_both', 'condition',
  871 + (object)array('from' => self::show_time($this->item->availablefrom, $shortfrom),
  872 + 'until' => self::show_time($displayuntil, $shortuntil))),
  873 + array('class'=>"conditionalrule requires_date_both"));
868 874 }
869 875 } else if ($this->item->availablefrom) {
870   - $information .= get_string('requires_date', 'condition',
871   - self::show_time($this->item->availablefrom, $shortfrom));
  876 + $information .= html_writer::tag('span', get_string('requires_date', 'condition',
  877 + self::show_time($this->item->availablefrom, $shortfrom)), array('class'=>"conditionalrule requires_date"));
872 878 } else if ($this->item->availableuntil) {
873   - $information .= get_string('requires_date_before', 'condition',
874   - self::show_time($displayuntil, $shortuntil));
  879 + $information .= html_writer::tag('span', get_string('requires_date_before', 'condition',
  880 + self::show_time($displayuntil, $shortuntil)), array('class'=>"conditionalrule requires_date_before"));
875 881 }
876 882
877 883 $information = trim($information);
@@ -971,9 +977,9 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
971 977 }
972 978 if (!$thisisok) {
973 979 $available = false;
974   - $information .= get_string(
975   - 'requires_completion_' . $expectedcompletion,
976   - 'condition', $modinfo->cms[$cmid]->name) . ' ';
  980 + $information .= html_writer::tag('span',
  981 + get_string('requires_completion_' . $expectedcompletion, 'condition', $modinfo->cms[$cmid]->name).' ',
  982 + array('class'=>"conditionalrule requires_completion"));
977 983 }
978 984 }
979 985 }
@@ -999,7 +1005,9 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
999 1005 } else {
1000 1006 $string = 'range';
1001 1007 }
1002   - $information .= get_string('requires_grade_' . $string, 'condition', $minmax->name) . ' ';
  1008 + $information .= html_writer::tag('span',
  1009 + get_string('requires_grade_' . $string, 'condition', $minmax->name).' ',
  1010 + array('class'=>"conditionalrule requires_grade"));
1003 1011 }
1004 1012 }
1005 1013 }
@@ -1024,9 +1032,10 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
1024 1032 if (time() < $this->item->availablefrom) {
1025 1033 $available = false;
1026 1034
1027   - $information .= get_string('requires_date', 'condition',
1028   - self::show_time($this->item->availablefrom,
1029   - self::is_midnight($this->item->availablefrom)));
  1035 + $information .= html_writer::tag('span',
  1036 + get_string('requires_date', 'condition',
  1037 + self::show_time($this->item->availablefrom, self::is_midnight($this->item->availablefrom))),
  1038 + array('class'=>"conditionalrule availablefrom"));
1030 1039 }
1031 1040 }
1032 1041
22 lib/tests/conditionlib_test.php 100644 → 100755
@@ -481,7 +481,7 @@ function test_is_available() {
481 481 condition_info::wipe_session_cache();
482 482
483 483 $this->assertFalse($ci->is_available($text,false));
484   - $this->assertEquals(get_string('requires_completion_1','condition','xxx'),$text);
  484 + $this->assertEquals(html_writer::tag('span',get_string('requires_completion_1','condition','xxx').' ',array('class'=>'conditionalrule requires_completion')),$text);
485 485 completion_info::wipe_session_cache();
486 486 $completion=new completion_info($DB->get_record('course',array('id'=>$courseid)));
487 487 $completion->update_state($oldcm,COMPLETION_COMPLETE);
@@ -513,7 +513,7 @@ function test_is_available() {
513 513 // Add a condition on a value existing...
514 514 $ci->add_grade_condition($gradeitemid,null,null,true);
515 515 $this->assertFalse($ci->is_available($text));
516   - $this->assertEquals(get_string('requires_grade_any','condition','frog'),$text);
  516 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_any','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
517 517
518 518 // Fake it existing
519 519 $DB->insert_record('grade_grades',(object)array(
@@ -529,7 +529,7 @@ function test_is_available() {
529 529 $ci->add_grade_condition($gradeitemid,3.78001,null,true);
530 530 condition_info::wipe_session_cache();
531 531 $this->assertFalse($ci->is_available($text));
532   - $this->assertEquals(get_string('requires_grade_min','condition','frog'),$text);
  532 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_min','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
533 533
534 534 // ...just on 3.78...
535 535 $ci->wipe_conditions();
@@ -542,7 +542,7 @@ function test_is_available() {
542 542 $ci->add_grade_condition($gradeitemid,null,3.78,true);
543 543 condition_info::wipe_session_cache();
544 544 $this->assertFalse($ci->is_available($text));
545   - $this->assertEquals(get_string('requires_grade_max','condition','frog'),$text);
  545 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_max','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
546 546
547 547 // ...less than 3.78001
548 548 $ci->wipe_conditions();
@@ -561,7 +561,7 @@ function test_is_available() {
561 561 $ci->add_grade_condition($gradeitemid,4,5,true);
562 562 condition_info::wipe_session_cache();
563 563 $this->assertFalse($ci->is_available($text));
564   - $this->assertEquals(get_string('requires_grade_range','condition','frog'),$text);
  564 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_range','condition','frog').' ',array('class'=>'conditionalrule requires_grade')),$text);
565 565 }
566 566
567 567 public function test_section_is_available() {
@@ -632,7 +632,7 @@ public function test_section_is_available() {
632 632
633 633 // Completion: Check
634 634 $this->assertFalse($ci->is_available($text, false));
635   - $this->assertEquals(get_string('requires_completion_1', 'condition', 'xxx'), $text);
  635 + $this->assertEquals(html_writer::tag('span',get_string('requires_completion_1', 'condition', 'xxx').' ',array('class'=>'conditionalrule requires_completion')), $text);
636 636 completion_info::wipe_session_cache();
637 637 $completion = new completion_info($DB->get_record('course', array('id' => $courseid)));
638 638 $completion->update_state($cm, COMPLETION_COMPLETE);
@@ -665,7 +665,7 @@ public function test_section_is_available() {
665 665 $ci->wipe_conditions();
666 666 $ci->add_grade_condition($gradeitemid, null, null, true);
667 667 $this->assertFalse($ci->is_available($text));
668   - $this->assertEquals(get_string('requires_grade_any', 'condition', 'frog'), $text);
  668 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_any', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
669 669
670 670 // Grade: Fake it existing
671 671 $DB->insert_record('grade_grades', (object)array(
@@ -680,7 +680,7 @@ public function test_section_is_available() {
680 680 $ci->add_grade_condition($gradeitemid, 3.78001, null, true);
681 681 condition_info_section::wipe_session_cache();
682 682 $this->assertFalse($ci->is_available($text));
683   - $this->assertEquals(get_string('requires_grade_min', 'condition', 'frog'), $text);
  683 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_min', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
684 684
685 685 // Grade: ...just on 3.78...
686 686 $ci->wipe_conditions();
@@ -693,7 +693,7 @@ public function test_section_is_available() {
693 693 $ci->add_grade_condition($gradeitemid, null, 3.78, true);
694 694 condition_info_section::wipe_session_cache();
695 695 $this->assertFalse($ci->is_available($text));
696   - $this->assertEquals(get_string('requires_grade_max', 'condition', 'frog'), $text);
  696 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_max', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
697 697
698 698 // Grade: ...less than 3.78001
699 699 $ci->wipe_conditions();
@@ -712,7 +712,7 @@ public function test_section_is_available() {
712 712 $ci->add_grade_condition($gradeitemid, 4, 5, true);
713 713 condition_info_section::wipe_session_cache();
714 714 $this->assertFalse($ci->is_available($text));
715   - $this->assertEquals(get_string('requires_grade_range', 'condition', 'frog'), $text);
  715 + $this->assertEquals(html_writer::tag('span',get_string('requires_grade_range', 'condition', 'frog').' ',array('class'=>'conditionalrule requires_grade')), $text);
716 716
717 717 // Grouping: Not member
718 718 $groupingid = $this->make_grouping($courseid, 'Grouping');
@@ -721,7 +721,7 @@ public function test_section_is_available() {
721 721 $ci = new condition_info_section((object)array('id' => $sectionid),
722 722 CONDITION_MISSING_EVERYTHING);
723 723 $this->assertFalse($ci->is_available($text));
724   - $this->assertEquals(trim(get_string('groupingnoaccess', 'condition')), $text);
  724 + $this->assertEquals(html_writer::tag('span',get_string('groupingnoaccess', 'condition'),array('class'=>'conditionalrule groupingnoaccess')), $text);
725 725
726 726 // Grouping: Member
727 727 $this->assertTrue(groups_add_member($groupid, $USER->id));

0 comments on commit 5e9fd83

Please sign in to comment.
Something went wrong with that request. Please try again.