Permalink
Browse files

Merge branch 'MDL-36095-m24' of git://github.com/sammarshallou/moodle…

… into MOODLE_24_STABLE
  • Loading branch information...
2 parents 7977c78 + 331bbb7 commit 625098abc57b4a33018068454b4e7654847d3558 Sam Hemelryk committed Jan 13, 2013
Showing with 44 additions and 16 deletions.
  1. +11 −3 course/editsection_form.php
  2. +33 −13 course/format/renderer.php
View
14 course/editsection_form.php
@@ -71,11 +71,19 @@ public function definition_after_data() {
$mform->addHelpButton('groupingid', 'groupingsection', 'group');
}
- // Date and time conditions
+ // Available from/to defaults to midnight because then the display
+ // will be nicer where it tells users when they can access it (it
+ // shows only the date and not time).
+ $date = usergetdate(time());
+ $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
+
+ // Date and time conditions.
$mform->addElement('date_time_selector', 'availablefrom',
- get_string('availablefrom', 'condition'), array('optional' => true));
+ get_string('availablefrom', 'condition'),
+ array('optional' => true, 'defaulttime' => $midnight));
$mform->addElement('date_time_selector', 'availableuntil',
- get_string('availableuntil', 'condition'), array('optional' => true));
+ get_string('availableuntil', 'condition'),
+ array('optional' => true, 'defaulttime' => $midnight));
// Conditions based on grades
$gradeoptions = array();
View
46 course/format/renderer.php
@@ -175,7 +175,8 @@ protected function section_header($section, $course, $onsectionpage, $sectionret
}
$o.= html_writer::end_tag('div');
- $o .= $this->section_availability_message($section);
+ $o .= $this->section_availability_message($section,
+ has_capability('moodle/course:viewhiddensections', $context));
return $o;
}
@@ -305,7 +306,9 @@ protected function section_summary($section, $course, $mods) {
$o.= html_writer::end_tag('div');
$o.= $this->section_activity_summary($section, $course, null);
- $o.= $this->section_availability_message($section);
+ $context = context_course::instance($course->id);
+ $o .= $this->section_availability_message($section,
+ has_capability('moodle/course:viewhiddensections', $context));
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('li');
@@ -389,22 +392,38 @@ private function section_activity_summary($section, $course, $mods) {
}
/**
- * If section is not visible to current user, display the message about that
- * ('Not available until...', that sort of thing). Otherwise, returns blank.
+ * If section is not visible, display the message about that ('Not available
+ * until...', that sort of thing). Otherwise, returns blank.
+ *
+ * For users with the ability to view hidden sections, it shows the
+ * information even though you can view the section and also may include
+ * slightly fuller information (so that teachers can tell when sections
+ * are going to be unavailable etc). This logic is the same as for
+ * activities.
*
* @param stdClass $section The course_section entry from DB
+ * @param bool $canviewhidden True if user can view hidden sections
* @return string HTML to output
*/
- protected function section_availability_message($section) {
+ protected function section_availability_message($section, $canviewhidden) {
+ global $CFG;
$o = '';
- if (!$section->uservisible || $section->availableinfo) {
+ if (!$section->uservisible) {
$o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
- if (!empty($section->availableinfo)) {
- $o .= $section->availableinfo;
- } else {
- $o .= get_string('notavailable');
- }
+ // Note: We only get to this function if availableinfo is non-empty,
+ // so there is definitely something to print.
+ $o .= $section->availableinfo;
$o .= html_writer::end_tag('div');
+ } else if ($canviewhidden && !empty($CFG->enableavailability) && $section->visible) {
+ $ci = new condition_info_section($section);
+ $fullinfo = $ci->get_full_information();
+ if ($fullinfo) {
+ $o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
+ $o .= get_string(
+ ($section->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden'),
+ 'condition', $fullinfo);
+ $o .= html_writer::end_tag('div');
+ }
}
return $o;
}
@@ -671,9 +690,10 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
continue;
}
// Show the section if the user is permitted to access it, OR if it's not available
- // but showavailability is turned on
+ // but showavailability is turned on (and there is some available info text).
$showsection = $thissection->uservisible ||
- ($thissection->visible && !$thissection->available && $thissection->showavailability);
+ ($thissection->visible && !$thissection->available && $thissection->showavailability
+ && !empty($thissection->availableinfo));
if (!$showsection) {
// Hidden section message is overridden by 'unavailable' control
// (showavailability option).

0 comments on commit 625098a

Please sign in to comment.