MDL-32508 course: Switch to 'section' URL param
authorDan Poltawski <dan@moodle.com>
Thu, 26 Apr 2012 12:49:36 +0000 (20:49 +0800)
committerDan Poltawski <dan@moodle.com>
Fri, 4 May 2012 02:52:58 +0000 (10:52 +0800)
This is a course format independent url param and replaces weekly/topic specific params.
By using a standardised param we are able to use this url consistenly across the codebase
and reduce the risk of param collision

course/format/topics/format.php
course/format/weeks/format.php
course/view.php

index 515cd44..6f2cb3e 100644 (file)
@@ -30,7 +30,14 @@ defined('MOODLE_INTERNAL') || die();
 require_once($CFG->libdir.'/filelib.php');
 require_once($CFG->libdir.'/completionlib.php');
 
-$displaysection = optional_param('topic', 0, PARAM_INT);
+// Horrible backwards compatible parameter aliasing
+if ($topic = optional_param('topic', 0, PARAM_INT)) {
+    $url = $PAGE->url;
+    $url->param('section', $topic);
+    debugging('Outdated topic param passed to course/view.php', DEBUG_DEVELOPER);
+    redirect($url);
+}
+// End backwards-compatible aliasing..
 
 $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
index a6894e6..336df35 100644 (file)
@@ -29,8 +29,6 @@ defined('MOODLE_INTERNAL') || die();
     require_once($CFG->libdir.'/filelib.php');
     require_once($CFG->libdir.'/completionlib.php');
 
-    $displaysection = optional_param('week', 0, PARAM_INT);
-
     $streditsummary  = get_string('editsummary');
     $stradd          = get_string('add');
     $stractivities   = get_string('activities');
@@ -46,6 +44,15 @@ defined('MOODLE_INTERNAL') || die();
         $strmovedown = get_string('movedown');
     }
 
+   // Horrible backwards compatible parameter aliasing
+    if ($week = optional_param('week', 0, PARAM_INT)) {
+        $url = $PAGE->url;
+        $url->param('section', $week);
+        debugging('Outdated week param passed to course/view.php', DEBUG_DEVELOPER);
+        redirect($url);
+    }
+    // End backwards-compatible aliasing..
+
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
     //Print the Your progress icon if the track completion is enabled
index ea6e3ca..a817865 100644 (file)
 
     $course = $DB->get_record('course', $params, '*', MUST_EXIST);
 
-    $PAGE->set_url('/course/view.php', array('id' => $course->id)); // Defined here to avoid notices on errors etc
+    $urlparams = array('id' => $course->id);
+    if ($section) {
+        $urlparams['section'] = $section;
+    }
+
+    $PAGE->set_url('/course/view.php', $urlparams); // Defined here to avoid notices on errors etc
 
     preload_course_contexts($course->id);
     $context = context_course::instance($course->id, MUST_EXIST);
@@ -78,6 +83,7 @@
 
     require_once($CFG->dirroot.'/calendar/lib.php');    /// This is after login because it needs $USER
 
+    //TODO: danp do we need different urls?
     add_to_log($course->id, 'course', 'view', "view.php?id=$course->id", "$course->id");
 
     $course->format = clean_param($course->format, PARAM_ALPHA);
         $USER->editing = 0;
     }
 
-    $SESSION->fromdiscussion = $CFG->wwwroot .'/course/view.php?id='. $course->id;
+    $SESSION->fromdiscussion = $PAGE->url->out(false);
 
 
     if ($course->id == SITEID) {
         }
     }
 
+    // CAUTION, hacky fundamental variable defintion to follow!
+    // Note that because of the way course fromats are constructed though
+    // inclusion we pass parameters around this way..
+    $displaysection = $section;
+
     // Include the actual course format.
     require($CFG->dirroot .'/course/format/'. $course->format .'/format.php');
     // Content wrapper end.