From: moodler Date: Mon, 28 Apr 2003 13:29:26 +0000 (+0000) Subject: New feature replacing the old zoom function. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b86fc0e2a6f69275a48d70ff510527c0710142f7;p=moodle.git New feature replacing the old zoom function. Now these are saved in a new table called course_display, each user and each course can have independent settings. I'm intending to expand this table later for all the other course display stuff (like hidden topics etc) --- diff --git a/course/lib.php b/course/lib.php index 5316579e73..6ec9a6d2bb 100644 --- a/course/lib.php +++ b/course/lib.php @@ -507,6 +507,45 @@ function get_all_sections($courseid) { "section, id, course, summary, sequence"); } +function course_set_display($courseid, $display=0) { + global $USER; + + if (empty($USER)) { + return false; + } + + if ($display == "all" or empty($display)) { + $display = 0; + } + + if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) { + set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid); + } else { + $record->userid = $USER->id; + $record->course = $courseid; + $record->display = $display; + if (!insert_record("course_display", $record)) { + notify("Could not save your course display!"); + } + } + + return $USER->display[$courseid] = $display; // Note: = not == +} + +function course_section_visible($courseid, $section) { +/// Returns true/false depending on section visibility +/// Can be expanded in the future to handle more complex +/// course displays + + global $USER; + + if (empty($USER->display[$courseid])) { + return true; + } + + return $USER->display[$courseid] == $section; +} + function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, $absolute=true, $width="100%", $isediting=false) { diff --git a/course/topics.php b/course/topics.php index 4035aff102..77fd7e8477 100644 --- a/course/topics.php +++ b/course/topics.php @@ -9,10 +9,12 @@ require_once("$CFG->dirroot/mod/forum/lib.php"); if (isset($topic)) { - if ($topic == "all") { - unset($USER->topic); + $displaysection = course_set_display($course->id, $topic); + } else { + if (isset($USER->display[$course->id])) { // for admins, mostly + $displaysection = $USER->display[$course->id]; } else { - $USER->topic = $topic; + $displaysection = course_set_display($course->id, 0); } } @@ -122,11 +124,9 @@ while ($section <= $course->numsections) { - if (isset($USER->topic)) { // Just display a single topic - if ($USER->topic != $section) { - $section++; - continue; - } + if (!empty($displaysection) and $displaysection != $section) { + $section++; + continue; } $currenttopic = ($course->marker == $section); @@ -177,7 +177,7 @@ echo ""; echo ""; echo ""; - if (isset($USER->topic)) { + if ($displaysection == $section) { $strshowalltopics = get_string("showalltopics"); echo "id&topic=all\" title=\"$strshowalltopics\">

"; } else { diff --git a/course/weeks.php b/course/weeks.php index 5a2c34c255..21f66eecb2 100644 --- a/course/weeks.php +++ b/course/weeks.php @@ -6,10 +6,12 @@ if (isset($week)) { - if ($week == "all") { - unset($USER->section); + $displaysection = course_set_display($course->id, $week); + } else { + if (isset($USER->display[$course->id])) { + $displaysection = $USER->display[$course->id]; } else { - $USER->section = $week; + $displaysection = course_set_display($course->id, 0); } } @@ -55,7 +57,7 @@ /// Print a form to search forums $searchform = forum_print_search_form($course, "", true); - $searchform = "
$searchform
"; + $searchform = "
$searchform
"; print_side_block(get_string("search","forum"), $searchform); @@ -64,7 +66,7 @@ /// Start main column - echo ""; + echo ""; print_heading_block(get_string("weeklyoutline"), "100%", "outlineheadingblock"); print_spacer(8, 1, true); @@ -97,11 +99,11 @@ echo ""; } - echo ""; - echo "cellheading\" class=\"weeklyoutlineside\" VALIGN=top ALIGN=CENTER WIDTH=10>"; - echo " "; - echo ""; - echo ""; + echo ""; + echo "cellheading\" class=\"weeklyoutlineside\" valign=top align=center width=10>"; + echo " "; + echo ""; + echo ""; } @@ -118,12 +120,10 @@ $nextweekdate = $weekdate + ($weekofseconds); - if (isset($USER->section)) { // Just display a single week - if ($USER->section != $week) { - $week++; - $weekdate = $nextweekdate; - continue; - } + if (!empty($displaysection) and $displaysection != $week) { // Check this week is visible + $week++; + $weekdate = $nextweekdate; + continue; } $thisweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate)); @@ -177,7 +177,7 @@ echo ""; echo ""; echo ""; - if (isset($USER->section)) { + if ($displaysection == $week) { $strshowallweeks = get_string("showallweeks"); echo "id&week=all\" title=\"$strshowallweeks\">"; } else { diff --git a/lib/datalib.php b/lib/datalib.php index 36e9341f22..576f684cdf 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -721,6 +721,7 @@ function get_user_info_from_db($field, $value) { if ($students = get_records("user_students", "userid", $user->id)) { foreach ($students as $student) { $user->student[$student->course] = true; + $user->zoom[$student->course] = $student->zoom; } } @@ -737,6 +738,12 @@ function get_user_info_from_db($field, $value) { } } + if ($displays = get_records("course_display", "userid", $user->id)) { + foreach ($displays as $display) { + $user->display[$display->course] = $display->display; + } + } + return $user; } diff --git a/lib/db/mysql.php b/lib/db/mysql.php index d5573066ce..c317b6011f 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -363,6 +363,18 @@ function main_upgrade($oldversion=0) { execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX courseuserid (course,userid) "); } + if ($oldversion < 2003042801) { + execute_sql("CREATE TABLE `{$CFG->prefix}course_display` ( + `id` int(10) unsigned NOT NULL auto_increment, + `course` int(10) unsigned NOT NULL default '0', + `userid` int(10) unsigned NOT NULL default '0', + `display` int(10) NOT NULL default '0', + PRIMARY KEY (`id`), + UNIQUE KEY `id` (`id`), + KEY `courseuserid` (course,userid) + ) TYPE=MyISAM COMMENT='Stores info about how to display the course'"); + } + return $result; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 06f1434d69..748b0ce29f 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -64,6 +64,23 @@ CREATE TABLE `prefix_course_categories` ( ) TYPE=MyISAM COMMENT='Course categories'; # -------------------------------------------------------- + +# +# Table structure for table `course_display` +# + +CREATE TABLE `prefix_course_display` ( + `id` int(10) unsigned NOT NULL auto_increment, + `course` int(10) unsigned NOT NULL default '0', + `userid` int(10) unsigned NOT NULL default '0', + `display` int(10) NOT NULL default '0', + PRIMARY KEY (`id`), + UNIQUE KEY `id` (`id`), + KEY `courseuserid` (course,userid) +) TYPE=MyISAM COMMENT='Stores info about how to display the course'; +# -------------------------------------------------------- + + # # Table structure for table `course_modules` # @@ -240,7 +257,6 @@ CREATE TABLE `prefix_user_coursecreators` ( PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) TYPE=MyISAM COMMENT='One record per course creator'; -# -------------------------------------------------------- INSERT INTO prefix_log_display VALUES ('user', 'view', 'user', 'CONCAT(firstname," ",lastname)'); INSERT INTO prefix_log_display VALUES ('course', 'view', 'course', 'fullname'); diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 183795ddf2..8727340d8b 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -126,6 +126,17 @@ function main_upgrade($oldversion=0) { execute_sql(" CREATE INDEX coursemoduleaction ON {$CFG->prefix}log (course,module,action) "); execute_sql(" CREATE INDEX courseuserid ON {$CFG->prefix}log (course,userid) "); } + + if ($oldversion < 2003042801) { + execute_sql("CREATE TABLE {$CFG->prefix}course_display ( + id SERIAL PRIMARY KEY, + course integer NOT NULL default '0', + userid integer NOT NULL default '0', + display integer NOT NULL default '0' + )"); + + execute_sql("CREATE INDEX courseuserid ON {$CFG->prefix}course_display (course,userid)"); + } return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index 05c38c10a5..526472df0b 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -32,6 +32,15 @@ CREATE TABLE prefix_course_categories ( name varchar(255) NOT NULL default '' ); +CREATE TABLE prefix_course_display ( + id SERIAL PRIMARY KEY, + course integer NOT NULL default '0', + userid integer NOT NULL default '0', + display integer NOT NULL default '0' +); + +CREATE INDEX courseuserid ON prefix_course_display (course,userid); + CREATE TABLE prefix_course_modules ( id SERIAL PRIMARY KEY, course integer NOT NULL default '0', diff --git a/version.php b/version.php index 9b34b2d35d..4c7e7893e2 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2003042701; // The current version is a date (YYYYMMDDXX) +$version = 2003042801; // The current version is a date (YYYYMMDDXX) $release = "1.0.9 development"; // User-friendly version number