MDL-32505 course: drop course_display table and settings
This commit is contained in:
@@ -100,7 +100,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
$temp->add(new admin_setting_configcheckbox('navshowmycoursecategories', new lang_string('navshowmycoursecategories', 'admin'), new lang_string('navshowmycoursecategories_help', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('navshowallcourses', new lang_string('navshowallcourses', 'admin'), new lang_string('confignavshowallcourses', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configtext('navcourselimit',new lang_string('navcourselimit','admin'),new lang_string('confignavcourselimit', 'admin'),20,PARAM_INT));
|
||||
$temp->add(new admin_setting_configcheckbox('navlinkcoursesections', new lang_string('navlinkcoursesections', 'admin'), new lang_string('navlinkcoursesections_help', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('usesitenameforsitepages', new lang_string('usesitenameforsitepages', 'admin'), new lang_string('configusesitenameforsitepages', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('linkadmincategories', new lang_string('linkadmincategories', 'admin'), new lang_string('linkadmincategories_help', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('navshowfrontpagemods', new lang_string('navshowfrontpagemods', 'admin'), new lang_string('navshowfrontpagemods_help', 'admin'), 1));
|
||||
|
||||
@@ -30,13 +30,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
$topic = optional_param('topic', -1, PARAM_INT);
|
||||
|
||||
if ($topic != -1) {
|
||||
$displaysection = course_set_display($course->id, $topic);
|
||||
} else {
|
||||
$displaysection = course_get_display($course->id);
|
||||
}
|
||||
$displaysection = optional_param('topic', 0, PARAM_INT);
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
|
||||
|
||||
@@ -29,13 +29,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
|
||||
$week = optional_param('week', -1, PARAM_INT);
|
||||
|
||||
if ($week != -1) {
|
||||
$displaysection = course_set_display($course->id, $week);
|
||||
} else {
|
||||
$displaysection = course_get_display($course->id);
|
||||
}
|
||||
$displaysection = optional_param('week', 0, PARAM_INT);
|
||||
|
||||
$streditsummary = get_string('editsummary');
|
||||
$stradd = get_string('add');
|
||||
|
||||
@@ -1276,73 +1276,6 @@ function get_all_sections($courseid) {
|
||||
return $coursesections[$courseid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the course section to display or 0 meaning show all sections. Returns 0 for guests.
|
||||
* It also sets the $USER->display cache to array($courseid=>return value)
|
||||
*
|
||||
* @param int $courseid The course id
|
||||
* @return int Course section to display, 0 means all
|
||||
*/
|
||||
function course_get_display($courseid) {
|
||||
global $USER, $DB;
|
||||
|
||||
if (!isloggedin() or isguestuser()) {
|
||||
//do not get settings in db for guests
|
||||
return 0; //return the implicit setting
|
||||
}
|
||||
|
||||
if (!isset($USER->display[$courseid])) {
|
||||
if (!$display = $DB->get_field('course_display', 'display', array('userid' => $USER->id, 'course'=>$courseid))) {
|
||||
$display = 0; // all sections option is not stored in DB, this makes the table much smaller
|
||||
}
|
||||
//use display cache for one course only - we need to keep session small
|
||||
$USER->display = array($courseid => $display);
|
||||
}
|
||||
|
||||
return $USER->display[$courseid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Show one section only or all sections.
|
||||
*
|
||||
* @param int $courseid The course id
|
||||
* @param mixed $display show only this section, 0 or 'all' means show all sections
|
||||
* @return int Course section to display, 0 means all
|
||||
*/
|
||||
function course_set_display($courseid, $display) {
|
||||
global $USER, $DB;
|
||||
|
||||
if ($display === 'all' or empty($display)) {
|
||||
$display = 0;
|
||||
}
|
||||
|
||||
if (!isloggedin() or isguestuser()) {
|
||||
//do not store settings in db for guests
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($display == 0) {
|
||||
//show all, do not store anything in database
|
||||
$DB->delete_records('course_display', array('userid' => $USER->id, 'course' => $courseid));
|
||||
|
||||
} else {
|
||||
if ($DB->record_exists('course_display', array('userid' => $USER->id, 'course' => $courseid))) {
|
||||
$DB->set_field('course_display', 'display', $display, array('userid' => $USER->id, 'course' => $courseid));
|
||||
} else {
|
||||
$record = new stdClass();
|
||||
$record->userid = $USER->id;
|
||||
$record->course = $courseid;
|
||||
$record->display = $display;
|
||||
$DB->insert_record('course_display', $record);
|
||||
}
|
||||
}
|
||||
|
||||
//use display cache for one course only - we need to keep session small
|
||||
$USER->display = array($courseid => $display);
|
||||
|
||||
return $display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set highlighted section. Only one section can be highlighted at the time.
|
||||
*
|
||||
@@ -3020,10 +2953,6 @@ function move_section($course, $section, $move) {
|
||||
course_set_marker($course->id, $section);
|
||||
}
|
||||
|
||||
// if the focus is on the section that is being moved, then move the focus along
|
||||
if (course_get_display($course->id) == $section) {
|
||||
course_set_display($course->id, $sectiondest);
|
||||
}
|
||||
|
||||
// Fix order if needed. The database prevents duplicate sections, but it is
|
||||
// possible there could be a gap in the numbering.
|
||||
@@ -3099,10 +3028,6 @@ function move_section_to($course, $section, $destination) {
|
||||
course_set_marker($course, $course->marker-1);
|
||||
}
|
||||
|
||||
// if the focus is on the section that is being moved, then move the focus along
|
||||
if (course_get_display($course->id) == $section) {
|
||||
course_set_display($course->id, $destination);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -695,8 +695,6 @@ $string['navadduserpostslinks'] = 'Add links to view user posts';
|
||||
$string['navadduserpostslinks_help'] = 'If enabled two links will be added to each user in the navigation to view discussions the user has started and posts the user has made in forums throughout the site or in specific courses.';
|
||||
$string['navigationupgrade'] = 'This upgrade introduces two new navigation blocks that will replace these blocks: Administration, Courses, Activities and Participants. If you had set any special permissions on those blocks you should check to make sure everything is behaving as you want it.';
|
||||
$string['navcourselimit'] = 'Course limit';
|
||||
$string['navlinkcoursesections'] = 'Link course sections';
|
||||
$string['navlinkcoursesections_help'] = 'If enabled course sections will be shown as links within the navigation.';
|
||||
$string['navshowfrontpagemods'] = 'Show front page activities in the navigation';
|
||||
$string['navshowfrontpagemods_help'] = 'If enabled, front page activities will be shown on the navigation under site pages.';
|
||||
$string['navshowallcourses'] = 'Show all courses';
|
||||
|
||||
+2
-16
@@ -206,7 +206,7 @@
|
||||
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="course_completions" COMMENT="Course completion records" PREVIOUS="course_completion_notify" NEXT="course_display">
|
||||
<TABLE NAME="course_completions" COMMENT="Course completion records" PREVIOUS="course_completion_notify" NEXT="enrol">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="userid"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="course"/>
|
||||
@@ -227,21 +227,7 @@
|
||||
<INDEX NAME="timecompleted" UNIQUE="false" FIELDS="timecompleted" PREVIOUS="course"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="course_display" COMMENT="Stores info about how to display the course" PREVIOUS="course_completions" NEXT="enrol">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="course"/>
|
||||
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="userid"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="course" NEXT="display"/>
|
||||
<FIELD NAME="display" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="course_userid" UNIQUE="false" FIELDS="course, userid"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="enrol" COMMENT="Instances of enrolment plugins used in courses, fields marked as custom have a plugin defined meaning, core does not touch them. Create a new linked table if you need even more custom fields." PREVIOUS="course_display" NEXT="user_enrolments">
|
||||
<TABLE NAME="enrol" COMMENT="Instances of enrolment plugins used in courses, fields marked as custom have a plugin defined meaning, core does not touch them. Create a new linked table if you need even more custom fields." PREVIOUS="course_completions" NEXT="user_enrolments">
|
||||
<FIELDS>
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="enrol"/>
|
||||
<FIELD NAME="enrol" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="status"/>
|
||||
|
||||
@@ -456,5 +456,27 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2012050300.03);
|
||||
}
|
||||
|
||||
if ($oldversion < 2012050300.04) {
|
||||
|
||||
// Define table course_display to be dropped
|
||||
$table = new xmldb_table('course_display');
|
||||
|
||||
// Conditionally launch drop table for course_display
|
||||
if ($dbman->table_exists($table)) {
|
||||
$dbman->drop_table($table);
|
||||
}
|
||||
|
||||
// Main savepoint reached
|
||||
upgrade_main_savepoint(true, 2012050300.04);
|
||||
}
|
||||
|
||||
if ($oldversion < 2012050300.05) {
|
||||
|
||||
// Clean up removed admin setting.
|
||||
unset_config('navlinkcoursesections');
|
||||
|
||||
upgrade_main_savepoint(true, 2012050300.05);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-2
@@ -4641,9 +4641,8 @@ function remove_course_contents($courseid, $showfeedback = true, array $options
|
||||
}
|
||||
$DB->update_record('course', $oldcourse);
|
||||
|
||||
// Delete course sections and user selections
|
||||
// Delete course sections.
|
||||
$DB->delete_records('course_sections', array('course'=>$course->id));
|
||||
$DB->delete_records('course_display', array('course'=>$course->id));
|
||||
|
||||
// delete legacy, section and any other course files
|
||||
$fs->delete_area_files($coursecontext->id, 'course'); // files from summary and section
|
||||
|
||||
@@ -1762,12 +1762,12 @@ class global_navigation extends navigation_node {
|
||||
$viewhiddensections = has_capability('moodle/course:viewhiddensections', $this->page->context);
|
||||
|
||||
$urlfunction = 'callback_'.$courseformat.'_get_section_url';
|
||||
if (empty($CFG->navlinkcoursesections) || !function_exists($urlfunction)) {
|
||||
if ($course->coursedisplay == COURSE_DISPLAY_SINGLEPAGE || !function_exists($urlfunction)) {
|
||||
$urlfunction = null;
|
||||
}
|
||||
|
||||
$keyfunction = 'callback_'.$courseformat.'_request_key';
|
||||
$key = course_get_display($course->id);
|
||||
$key = 0;
|
||||
if (defined('AJAX_SCRIPT') && AJAX_SCRIPT == '0' && function_exists($keyfunction) && $this->page->url->compare(new moodle_url('/course/view.php'), URL_MATCH_BASE)) {
|
||||
$key = optional_param($keyfunction(), $key, PARAM_INT);
|
||||
}
|
||||
|
||||
@@ -212,9 +212,11 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
|
||||
$record = $DB->get_record('context_temp', array());
|
||||
$this->assertEquals(5, $record->id);
|
||||
|
||||
/** FIXME: danp
|
||||
$this->assertEquals(0, $DB->count_records('course_display'));
|
||||
$originaldisplayid = $DB->insert_record('course_display', array('userid'=>2, 'course'=>1, 'display'=>1));
|
||||
$this->assertEquals(1, $originaldisplayid);
|
||||
*/
|
||||
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->assertEquals(2, $course->id);
|
||||
@@ -232,8 +234,10 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$this->assertEquals(2, $course->id);
|
||||
|
||||
/** FIXME: danp
|
||||
$displayid = $DB->insert_record('course_display', array('userid'=>2, 'course'=>1, 'display'=>1));
|
||||
$this->assertEquals($originaldisplayid, $displayid);
|
||||
*/
|
||||
|
||||
$this->assertEquals(2, $DB->count_records('user'));
|
||||
$DB->delete_records('user', array('id'=>2));
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$version = 2012050300.03; // YYYYMMDD = weekly release date of this DEV branch
|
||||
$version = 2012050300.05; // YYYYMMDD = weekly release date of this DEV branch
|
||||
// RR = release increments - 00 in DEV branches
|
||||
// .XX = incremental changes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user