COURSE DISPLAY REVAMP
OK, some big changes here to the front end, particularly in course categories and course display. Course categories can now be nested (to any level). Courses and course categories can now be manually sorted any way required. There is a groovy front end for managing these, and a better range of options for formatting the front page. It all still needs some polishing, which I'll be doing over the next couple of days, including better auto-sorting. I would not use this on production systems just yet.
This commit is contained in:
+48
-8
@@ -83,6 +83,9 @@ function table_column($table, $oldfield, $field, $type="integer", $size="10",
|
||||
case "mysqlt":
|
||||
|
||||
switch (strtolower($type)) {
|
||||
case "text":
|
||||
$type = "TEXT";
|
||||
break;
|
||||
case "integer":
|
||||
$type = "INTEGER($size)";
|
||||
break;
|
||||
@@ -821,16 +824,24 @@ function get_site () {
|
||||
|
||||
|
||||
function get_courses($category=0, $sort="fullname ASC") {
|
||||
/// Returns list of courses
|
||||
/// Returns list of courses, for whole site, or category
|
||||
|
||||
if ($category > 0) { // Return all courses in one category
|
||||
$courses = get_records("course", "category", $category, $sort);
|
||||
if ($category === 0) { // Return all courses, except site
|
||||
$courses = get_records_select("course", "category > 0", $sort);
|
||||
|
||||
} else if ($category < 0) { // Return all courses, even the site
|
||||
} else if ($category === -1) { // Return all courses, even the site
|
||||
$courses = get_records("course", "", "", $sort);
|
||||
|
||||
} else { // Return all courses, except site
|
||||
$courses = get_records_select("course", "category > 0", $sort);
|
||||
} else { // $category is an object
|
||||
$courses = get_records("course", "category", $category->id);
|
||||
if ($courses) { // Reorder them
|
||||
$courselist = explode(',', $category->courseorder);
|
||||
$outcourses = array();
|
||||
foreach ($courselist as $courseid) {
|
||||
$outcourses[] = $courses[$courseid];
|
||||
}
|
||||
$courses = $outcourses;
|
||||
}
|
||||
}
|
||||
|
||||
if ($courses) { /// Remove unavailable courses from the list
|
||||
@@ -845,8 +856,37 @@ function get_courses($category=0, $sort="fullname ASC") {
|
||||
return $courses;
|
||||
}
|
||||
|
||||
function get_categories() {
|
||||
return get_records("course_categories", "", "", "name");
|
||||
function get_my_courses($userid, $sort="c.fullname ASC") {
|
||||
global $CFG;
|
||||
|
||||
return get_records_sql("SELECT c.*
|
||||
FROM {$CFG->prefix}course c,
|
||||
{$CFG->prefix}user_students s,
|
||||
{$CFG->prefix}user_teachers t
|
||||
WHERE (s.userid = '$userid' AND s.course = c.id)
|
||||
OR (t.userid = '$userid' AND t.course = c.id)
|
||||
GROUP BY c.id
|
||||
ORDER BY $sort");
|
||||
}
|
||||
|
||||
|
||||
function get_categories($parent="none", $sort="sortorder ASC") {
|
||||
if ($parent == "none") {
|
||||
$categories = get_records("course_categories", "", "", $sort);
|
||||
} else {
|
||||
$categories = get_records("course_categories", "parent", $parent, $sort);
|
||||
}
|
||||
if ($categories) { /// Remove unavailable categories from the list
|
||||
$admin = isadmin();
|
||||
foreach ($categories as $key => $category) {
|
||||
if (!$category->visible) {
|
||||
if (!$admin) {
|
||||
unset($categories[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -413,6 +413,15 @@ function main_upgrade($oldversion=0) {
|
||||
execute_sql(" ALTER TABLE `{$CFG->prefix}user_teachers` ADD INDEX courseuserid (course,userid) ");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003072803) {
|
||||
table_column("course_categories", "", "description", "text", "", "", "");
|
||||
table_column("course_categories", "", "parent", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "courseorder", "text", "", "", "");
|
||||
table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
|
||||
table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,12 @@ CREATE TABLE `prefix_course` (
|
||||
CREATE TABLE `prefix_course_categories` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`name` varchar(255) NOT NULL default '',
|
||||
`description` text NOT NULL,
|
||||
`parent` int(10) unsigned NOT NULL default '0',
|
||||
`sortorder` int(10) unsigned NOT NULL default '0',
|
||||
`courseorder` text NOT NULL,
|
||||
`visible` tinyint(1) NOT NULL default '1',
|
||||
`timemodified` int(10) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `id` (`id`)
|
||||
) TYPE=MyISAM COMMENT='Course categories';
|
||||
|
||||
@@ -184,6 +184,15 @@ function main_upgrade($oldversion=0) {
|
||||
execute_sql(" CREATE INDEX {$CFG->prefix}user_teachers_courseuserid_idx ON {$CFG->prefix}user_teachers (course,userid) ");
|
||||
}
|
||||
|
||||
if ($oldversion < 2003072802) {
|
||||
table_column("course_categories", "", "description", "text", "", "", "");
|
||||
table_column("course_categories", "", "parent", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "sortorder", "integer", "10", "unsigned");
|
||||
table_column("course_categories", "", "courseorder", "text", "", "", "");
|
||||
table_column("course_categories", "", "visible", "integer", "1", "unsigned", "1");
|
||||
table_column("course_categories", "", "timemodified", "integer", "10", "unsigned");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -31,6 +31,12 @@ CREATE TABLE prefix_course (
|
||||
CREATE TABLE prefix_course_categories (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name varchar(255) NOT NULL default ''
|
||||
description text NOT NULL default '',
|
||||
parent integer NOT NULL default '0',
|
||||
sortorder integer NOT NULL default '0',
|
||||
courseorder text NOT NULL default '',
|
||||
visible integer NOT NULL default '1',
|
||||
timemodified` integer NOT NULL default '0'
|
||||
);
|
||||
|
||||
CREATE TABLE prefix_course_display (
|
||||
|
||||
+14
-3
@@ -725,7 +725,7 @@ function print_footer ($course=NULL) {
|
||||
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
|
||||
}
|
||||
} else {
|
||||
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot\">".get_string("home")."</a>";
|
||||
$homelink = "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">".get_string("home")."</a>";
|
||||
$course = get_site();
|
||||
}
|
||||
|
||||
@@ -1079,6 +1079,17 @@ function update_module_button($moduleid, $courseid, $string) {
|
||||
}
|
||||
}
|
||||
|
||||
function update_category_button($categoryid) {
|
||||
// Prints the editing button on a module "view" page
|
||||
global $CFG;
|
||||
|
||||
if (isadmin()) {
|
||||
$string = get_string("editthiscategory");
|
||||
return "<form target=_parent method=get action=\"$CFG->wwwroot/course/category.php\">".
|
||||
"<input type=hidden name=id value=\"$categoryid\">".
|
||||
"<input type=submit value=\"$string\"></form>";
|
||||
}
|
||||
}
|
||||
|
||||
function navmenu($course, $cm=NULL) {
|
||||
// Given a course and a (current) coursemodule
|
||||
@@ -1184,7 +1195,7 @@ function error ($message, $link="") {
|
||||
$link = "$SESSION->fromurl";
|
||||
unset($SESSION->fromurl);
|
||||
} else {
|
||||
$link = "$CFG->wwwroot";
|
||||
$link = "$CFG->wwwroot/";
|
||||
}
|
||||
}
|
||||
print_continue($link);
|
||||
@@ -1245,7 +1256,7 @@ function notice ($message, $link="") {
|
||||
if (!empty($_SERVER["HTTP_REFERER"])) {
|
||||
$link = $_SERVER["HTTP_REFERER"];
|
||||
} else {
|
||||
$link = $CFG->wwwroot;
|
||||
$link = "$CFG->wwwroot/";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user