mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-36095 Section availability: Make behaviour consistent with activities
This commit is contained in:
parent
10ad21dc9a
commit
b12d8cd881
3 changed files with 45 additions and 19 deletions
|
@ -57,7 +57,7 @@ if (!empty($CFG->enableavailability)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$mform = new editsection_form($PAGE->url, array('course' => $course, 'editoroptions' => $editoroptions,
|
$mform = new editsection_form($PAGE->url, array('course' => $course, 'editoroptions' => $editoroptions,
|
||||||
'cs' => $section, 'showavailability' => $section->showavailability));
|
'cs' => $section));
|
||||||
$mform->set_data($section); // set current value
|
$mform->set_data($section); // set current value
|
||||||
|
|
||||||
$returnurl = course_get_url($course, $sectionreturn);
|
$returnurl = course_get_url($course, $sectionreturn);
|
||||||
|
|
|
@ -54,11 +54,19 @@ class editsection_form extends moodleform {
|
||||||
$mform->addHelpButton('groupingid', 'groupingsection', 'group');
|
$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',
|
$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',
|
$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
|
// Conditions based on grades
|
||||||
$gradeoptions = array();
|
$gradeoptions = array();
|
||||||
|
@ -162,8 +170,6 @@ class editsection_form extends moodleform {
|
||||||
CONDITION_STUDENTVIEW_HIDE => get_string('showavailabilitysection_hide', 'condition'));
|
CONDITION_STUDENTVIEW_HIDE => get_string('showavailabilitysection_hide', 'condition'));
|
||||||
$mform->addElement('select', 'showavailability',
|
$mform->addElement('select', 'showavailability',
|
||||||
get_string('showavailabilitysection', 'condition'), $showhide);
|
get_string('showavailabilitysection', 'condition'), $showhide);
|
||||||
|
|
||||||
$mform->setDefault('showavailability', $this->_customdata['showavailability']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->add_action_buttons();
|
$this->add_action_buttons();
|
||||||
|
|
|
@ -175,7 +175,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||||
}
|
}
|
||||||
$o.= html_writer::end_tag('div');
|
$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;
|
return $o;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +306,9 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||||
$o.= html_writer::end_tag('div');
|
$o.= html_writer::end_tag('div');
|
||||||
$o.= $this->section_activity_summary($section, $course, $mods);
|
$o.= $this->section_activity_summary($section, $course, $mods);
|
||||||
|
|
||||||
$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('div');
|
||||||
$o .= html_writer::end_tag('li');
|
$o .= html_writer::end_tag('li');
|
||||||
|
@ -388,22 +391,38 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If section is not visible to current user, display the message about that
|
* If section is not visible, display the message about that ('Not available
|
||||||
* ('Not available until...', that sort of thing). Otherwise, returns blank.
|
* 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 stdClass $section The course_section entry from DB
|
||||||
|
* @param bool $canviewhidden True if user can view hidden sections
|
||||||
* @return string HTML to output
|
* @return string HTML to output
|
||||||
*/
|
*/
|
||||||
protected function section_availability_message($section) {
|
protected function section_availability_message($section, $canviewhidden) {
|
||||||
|
global $CFG;
|
||||||
$o = '';
|
$o = '';
|
||||||
if (!$section->uservisible || $section->availableinfo) {
|
if (!$section->uservisible) {
|
||||||
$o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
|
$o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
|
||||||
if (!empty($section->availableinfo)) {
|
// Note: We only get to this function if availableinfo is non-empty,
|
||||||
|
// so there is definitely something to print.
|
||||||
$o .= $section->availableinfo;
|
$o .= $section->availableinfo;
|
||||||
} else {
|
|
||||||
$o .= get_string('notavailable');
|
|
||||||
}
|
|
||||||
$o .= html_writer::end_tag('div');
|
$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;
|
return $o;
|
||||||
}
|
}
|
||||||
|
@ -677,9 +696,10 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
|
||||||
$thissection->showavailability = 0;
|
$thissection->showavailability = 0;
|
||||||
}
|
}
|
||||||
// Show the section if the user is permitted to access it, OR if it's not available
|
// 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 ||
|
$showsection = $thissection->uservisible ||
|
||||||
($thissection->visible && !$thissection->available && $thissection->showavailability);
|
($thissection->visible && !$thissection->available && $thissection->showavailability
|
||||||
|
&& !empty($thissection->availableinfo));
|
||||||
if (!$showsection) {
|
if (!$showsection) {
|
||||||
// Hidden section message is overridden by 'unavailable' control
|
// Hidden section message is overridden by 'unavailable' control
|
||||||
// (showavailability option).
|
// (showavailability option).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue