MDL-36017 Fields numsections, hiddensections and coursedisplay are now format-specific options

- Fields added to format_legacy as default course format options;
- Upgrade script copies fields values from table course to course_format_options;
- Fields removed from table course;
- Fields removed from edit course form;
- Since front-page course has a 'numsections' setting, format_site defines it as it's option;
- Removed accessing those fields in core code unless we know that format supports them and in this
  case instead of $course = $DB->get_record('course'); we use:
  $course = course_get_format($courseorid)->get_course(); This way all format-specific options
  are added to the $course object
This commit is contained in:
Marina Glancy
2012-11-02 10:56:19 +08:00
parent 7b7d2f4d12
commit b5cf83f080
24 changed files with 196 additions and 99 deletions
+40 -2
View File
@@ -98,8 +98,46 @@ class format_legacy extends format_base {
}
}
// else, default behavior:
return parent::get_view_url($section, $options);
// if function is not defined
if (!$this->uses_sections() ||
!array_key_exists('coursedisplay', $this->course_format_options())) {
// default behaviour
return parent::get_view_url($section, $options);
}
$course = $this->get_course();
$url = new moodle_url('/course/view.php', array('id' => $course->id));
$sr = null;
if (array_key_exists('sr', $options)) {
$sr = $options['sr'];
}
if (is_object($section)) {
$sectionno = $section->section;
} else {
$sectionno = $section;
}
if ($sectionno !== null) {
if ($sr !== null) {
if ($sr) {
$usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
$sectionno = $sr;
} else {
$usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
}
} else {
$usercoursedisplay = $course->coursedisplay;
}
if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
} else {
if (!empty($options['navigation'])) {
return null;
}
$url->set_anchor('section-'.$sectionno);
}
}
return $url;
}
/**
+38 -25
View File
@@ -355,35 +355,20 @@ abstract class format_base {
public function get_view_url($section, $options = array()) {
$course = $this->get_course();
$url = new moodle_url('/course/view.php', array('id' => $course->id));
$sr = null;
if (array_key_exists('sr', $options)) {
$sr = $options['sr'];
}
if (is_object($section)) {
$sectionno = $options['sr'];
} else if (is_object($section)) {
$sectionno = $section->section;
} else {
$sectionno = $section;
}
if ($sectionno !== null) {
if ($sr !== null) {
if ($sr) {
$usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
$sectionno = $sr;
} else {
$usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
}
} else {
$usercoursedisplay = $course->coursedisplay;
}
if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$url->param('section', $sectionno);
} else {
if (!empty($options['navigation'])) {
return null;
}
$url->set_anchor('section-'.$sectionno);
}
if (!empty($options['navigation']) && $sectionno !== null) {
// by default assume that sections are never displayed on separate pages
return null;
}
if ($this->uses_sections() && $sectionno !== null) {
$url->set_anchor('section-'.$sectionno);
}
return $url;
}
@@ -796,5 +781,33 @@ class format_site extends format_base {
public function get_view_url($section, $options = array()) {
return new moodle_url('/');
}
}
/**
* Returns the list of blocks to be automatically added on the site frontpage when moodle is installed
*
* @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT
* each of values is an array of block names (for left and right side columns)
*/
public function get_default_blocks() {
return blocks_get_default_site_course_blocks();
}
/**
* Definitions of the additional options that site uses
*
* @param bool $foreditform
* @return array of options
*/
public function course_format_options($foreditform = false) {
static $courseformatoptions = false;
if ($courseformatoptions === false) {
$courseformatoptions = array(
'numsections' => array(
'default' => 1,
'type' => PARAM_INT,
),
);
}
return $courseformatoptions;
}
}
+3
View File
@@ -448,6 +448,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
*/
protected function get_nav_links($course, $sections, $sectionno) {
// FIXME: This is really evil and should by using the navigation API.
$course = course_get_format($course)->get_course();
$canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
or !$course->hiddensections;
@@ -542,6 +543,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
global $PAGE;
$modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course();
// Can we view the section in question?
if (!($sectioninfo = $modinfo->get_section_info($displaysection))) {
@@ -637,6 +639,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
global $PAGE;
$modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course();
$context = context_course::instance($course->id);
// Title with completion help icon.
+1
View File
@@ -45,6 +45,7 @@ if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context)
}
// make sure all sections are created
$course = course_get_format($course)->get_course();
course_create_sections_if_missing($course, range(0, $course->numsections));
$renderer = $PAGE->get_renderer('format_topics');
+1
View File
@@ -38,6 +38,7 @@ if ($week = optional_param('week', 0, PARAM_INT)) {
// End backwards-compatible aliasing..
// make sure all sections are created
$course = course_get_format($course)->get_course();
course_create_sections_if_missing($course, range(0, $course->numsections));
$renderer = $PAGE->get_renderer('format_weeks');