mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
materialized path & depth for course categories.
This commit is contained in:
parent
523516fa48
commit
f41ef63ee6
@ -2330,20 +2330,38 @@ function get_categories($parent='none', $sort='sortorder ASC') {
|
||||
* $safe (bool) prevents it from assuming category-sortorder is unique, used to upgrade
|
||||
* safely from 1.4 to 1.5
|
||||
*/
|
||||
function fix_course_sortorder($categoryid=0, $n=0, $safe=0) {
|
||||
|
||||
function fix_course_sortorder($categoryid=0, $n=0, $safe=0, $depth=0, $path='') {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$count = 0;
|
||||
|
||||
$catgap = 1000; # "standard" category gap
|
||||
$tolerance = 200; # how "close" categories can get
|
||||
$catgap = 1000; // "standard" category gap
|
||||
$tolerance = 200; // how "close" categories can get
|
||||
|
||||
if ($categoryid > 0){
|
||||
// update depth and path
|
||||
$cat = get_record('course_categories', 'id', $categoryid);
|
||||
if ($cat->parent == 0) {
|
||||
$depth = 0;
|
||||
$path = '';
|
||||
} else if ($depth == 0 ) { // doesn't make sense; get from DB
|
||||
// this is only called if the $depth parameter looks dodgy
|
||||
$parent = get_record('course_categories', 'id', $cat->parent);
|
||||
$path = $parent->path;
|
||||
$depth = $parent->depth;
|
||||
}
|
||||
$path = $path . '/' . $categoryid;
|
||||
$depth = $depth + 1;
|
||||
|
||||
set_field('course_categories', 'path', addslashes($path), 'id', $categoryid);
|
||||
set_field('course_categories', 'depth', $depth, 'id', $categoryid);
|
||||
}
|
||||
|
||||
// get some basic info about courses in the category
|
||||
$info = get_record_sql('SELECT MIN(sortorder) AS min,
|
||||
MAX(sortorder) AS max,
|
||||
COUNT(sortorder) AS count
|
||||
COUNT(sortorder) AS count
|
||||
FROM ' . $CFG->prefix . 'course
|
||||
WHERE category=' . $categoryid);
|
||||
if (is_object($info)) { // no courses?
|
||||
@ -2417,7 +2435,7 @@ function fix_course_sortorder($categoryid=0, $n=0, $safe=0) {
|
||||
|
||||
if ($categories = get_categories($categoryid)) {
|
||||
foreach ($categories as $category) {
|
||||
$n = fix_course_sortorder($category->id, $n, $safe);
|
||||
$n = fix_course_sortorder($category->id, $n, $safe, $depth, $path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1520,6 +1520,11 @@ function main_upgrade($oldversion=0) {
|
||||
table_column('course','','restrictmodules','int','1','','0','not null');
|
||||
}
|
||||
|
||||
if ($oldversion < 2005081700) {
|
||||
table_column('course_categories','','depth','integer');
|
||||
table_column('course_categories','','path','varchar','255');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,8 @@ CREATE TABLE `prefix_course_categories` (
|
||||
`coursecount` int(10) unsigned NOT NULL default '0',
|
||||
`visible` tinyint(1) NOT NULL default '1',
|
||||
`timemodified` int(10) unsigned NOT NULL default '0',
|
||||
`depth` int(10) unsigned NOT NULL default '0',
|
||||
`path` varchar(255) NOT NULL default '',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`)
|
||||
) TYPE=MyISAM COMMENT='Course categories';
|
||||
|
@ -1261,8 +1261,12 @@ function main_upgrade($oldversion=0) {
|
||||
modify_database('','CREATE INDEX prefix_course_allowed_modules_course_idx ON prefix_course_allowed_modules (course);');
|
||||
modify_database('','CREATE INDEX prefix_course_allowed_modules_module_idx ON prefix_course_allowed_modules (module);');
|
||||
table_column('course','','restrictmodules','int','1','','0','not null');
|
||||
}
|
||||
}
|
||||
|
||||
if ($oldversion < 2005081700) {
|
||||
table_column('course_categories','','depth','integer');
|
||||
table_column('course_categories','','path','varchar','255');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -64,7 +64,9 @@ CREATE TABLE prefix_course_categories (
|
||||
sortorder integer NOT NULL default '0',
|
||||
coursecount integer NOT NULL default '0',
|
||||
visible integer NOT NULL default '1',
|
||||
timemodified integer NOT NULL default '0'
|
||||
timemodified integer NOT NULL default '0',
|
||||
depth integer NOT NULL default '0',
|
||||
path varchar(255) NOT NULL default ''
|
||||
);
|
||||
|
||||
CREATE TABLE prefix_course_display (
|
||||
|
@ -6,7 +6,7 @@
|
||||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2005081601; // YYYYMMDD = date
|
||||
$version = 2005081700; // YYYYMMDD = date
|
||||
// XY = increments within a single day
|
||||
|
||||
$release = '1.6 development'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user