Skip to content

Commit

Permalink
MDL-33212 Course page: Eye icon should override other conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed May 28, 2012
1 parent 2ddb941 commit 054d245
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion course/lib.php
Expand Up @@ -1763,7 +1763,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
// see the activity itself, or for staff)
if (!$mod->uservisible) {
echo '<div class="availabilityinfo">'.$mod->availableinfo.'</div>';
} else if ($canviewhidden && !empty($CFG->enableavailability)) {
} else if ($canviewhidden && !empty($CFG->enableavailability) && $mod->visible) {
$ci = new condition_info($mod);
$fullinfo = $ci->get_full_information();
if($fullinfo) {
Expand Down
16 changes: 13 additions & 3 deletions lib/conditionlib.php
Expand Up @@ -101,16 +101,16 @@ public function __construct($cm, $expectingmissing=CONDITION_MISSING_NOTHING,

// Missing basic data from course_modules
if (!isset($cm->availablefrom) || !isset($cm->availableuntil) ||
!isset($cm->showavailability) || !isset($cm->course)) {
!isset($cm->showavailability) || !isset($cm->course) || !isset($cm->visible)) {
if ($expectingmissing<CONDITION_MISSING_EVERYTHING) {
debugging('Performance warning: condition_info constructor is
faster if you pass in $cm with at least basic fields
(availablefrom,availableuntil,showavailability,course).
(availablefrom,availableuntil,showavailability,course,visible).
[This warning can be disabled, see phpdoc.]',
DEBUG_DEVELOPER);
}
$cm = $DB->get_record('course_modules',array('id'=>$cm->id),
'id,course,availablefrom,availableuntil,showavailability');
'id, course, availablefrom, availableuntil, showavailability, visible');
}

$this->cm = clone($cm);
Expand Down Expand Up @@ -486,6 +486,16 @@ public function is_available(&$information, $grabthelot=false, $userid=0, $modin
}
}

// If the item is marked as 'not visible' then we don't change the available
// flag (visible/available are treated distinctly), but we remove any
// availability info. If the item is hidden with the eye icon, it doesn't
// make sense to show 'Available from <date>' or similar, because even
// when that date arrives it will still not be available unless somebody
// toggles the eye icon.
if (!$this->cm->visible) {
$information = '';
}

$information=trim($information);
return $available;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/simpletest/testconditionlib.php
Expand Up @@ -79,19 +79,22 @@ function test_constructor() {
$this->assertEqual(
(object)array('id'=>$id,'showavailability'=>1,
'availablefrom'=>17,'availableuntil'=>398,'course'=>64,
'conditionsgrade'=>array(), 'conditionscompletion'=>array()),
'conditionsgrade' => array(), 'conditionscompletion' => array(),
'visible' => 1),
$test->get_full_course_module());

// just the course_modules stuff; check it doesn't request that from db
$cm->showavailability=0;
$cm->availablefrom=2;
$cm->availableuntil=74;
$cm->course=38;
$cm->visible = 1;
$test=new condition_info($cm,CONDITION_MISSING_EXTRATABLE);
$this->assertEqual(
(object)array('id'=>$id,'showavailability'=>0,
'availablefrom'=>2,'availableuntil'=>74,'course'=>38,
'conditionsgrade'=>array(), 'conditionscompletion'=>array()),
'conditionsgrade' => array(), 'conditionscompletion' => array(),
'visible' => 1),
$test->get_full_course_module());

// Now let's add some actual grade/completion conditions
Expand Down

0 comments on commit 054d245

Please sign in to comment.