]> git.mjollnir.org Git - moodle.git/commitdiff
New feature replacing the old zoom function.
authormoodler <moodler>
Mon, 28 Apr 2003 13:29:26 +0000 (13:29 +0000)
committermoodler <moodler>
Mon, 28 Apr 2003 13:29:26 +0000 (13:29 +0000)
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)

course/lib.php
course/topics.php
course/weeks.php
lib/datalib.php
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
version.php

index 5316579e732e77ff213361d1bb40a202a99f4ecf..6ec9a6d2bbcaa4a5e4fb138e4de989e9339b9fa1 100644 (file)
@@ -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) {
index 4035aff102f0b1564f85ac2e738ecd4dcc724bd7..77fd7e8477f4ffd7861ea6a2804d74dc516e729d 100644 (file)
@@ -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);
         }
     }
 
 
     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);
         echo "</td>";
         echo "<td nowrap $colorsides valign=top align=center width=10>";
         echo "<font size=1>";
-        if (isset($USER->topic)) {
+        if ($displaysection == $section) {
             $strshowalltopics = get_string("showalltopics");
             echo "<a href=\"view.php?id=$course->id&topic=all\" title=\"$strshowalltopics\"><img src=\"$pixpath/i/all.gif\" height=25 width=16 border=0></a><br><br>";
         } else {
index 5a2c34c255d97c0e2baa8be676756123bc62e7c2..21f66eecb24513211ad9bf9573d31bedb2d8e6a0 100644 (file)
@@ -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 = "<DIV ALIGN=\"CENTER\">$searchform</DIV>";
+    $searchform = "<div align=\"center\">$searchform</div>";
     print_side_block(get_string("search","forum"), $searchform);
     
 
@@ -64,7 +66,7 @@
 
 
 /// Start main column
-    echo "</TD><TD WIDTH=\"*\">";
+    echo "</td><td width=\"*\">";
     print_heading_block(get_string("weeklyoutline"), "100%", "outlineheadingblock");
     print_spacer(8, 1, true);
 
             echo "</div>";
         }
 
-        echo "</TD>";
-        echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\" class=\"weeklyoutlineside\" VALIGN=top ALIGN=CENTER WIDTH=10>";
-        echo "&nbsp;</TD>";
-        echo "</TR>";
-        echo "<TR><TD COLSPAN=3><IMG SRC=\"../pix/spacer.gif\" WIDTH=1 HEIGHT=1></TD></TR>";
+        echo "</td>";
+        echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\" valign=top align=center width=10>";
+        echo "&nbsp;</td>";
+        echo "</tr>";
+        echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
     }
 
 
 
         $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));
         echo "</td>";
         echo "<td nowrap $colorsides valign=top align=center width=10>";
         echo "<font size=1>";
-        if (isset($USER->section)) {
+        if ($displaysection == $week) { 
             $strshowallweeks = get_string("showallweeks");
             echo "<a href=\"view.php?id=$course->id&week=all\" title=\"$strshowallweeks\"><img src=\"$pixpath/i/all.gif\" height=25 width=16 border=0></a></font>";
         } else {
index 36e9341f22dc541f052b7cda86168275a991c5d7..576f684cdf66b04b413c81032f9c115bd6462d0d 100644 (file)
@@ -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;
 }
 
index d5573066ce0d6945bb4d8824269ebfed7b673dc4..c317b6011f5a0ab230555113a434a85d9b98ccac 100644 (file)
@@ -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;
 
 }
index 06f1434d69d86493a44e3e7b526ac775ad252a1f..748b0ce29feb0485750852ca82a18e0e12c9a23f 100644 (file)
@@ -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');
index 183795ddf2153a2f9d605127cae0d08e5a9f4e77..8727340d8b38a4ad3f352e03190baa1f7be0542e 100644 (file)
@@ -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;
 }
index 05c38c10a52ae30ac2b8ee5f5d70081b0f7148ef..526472df0b25d186de17978a9a56c66571242c3c 100644 (file)
@@ -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',
index 9b34b2d35d42acad97d328d8a929f0d80776562c..4c7e7893e2d74cf44d637d17571730becdc8ce7d 100644 (file)
@@ -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