]> git.mjollnir.org Git - moodle.git/commitdiff
Events associated to hidden activities are now invisible in calendar, using new field...
authorgustav_delius <gustav_delius>
Wed, 5 May 2004 07:07:56 +0000 (07:07 +0000)
committergustav_delius <gustav_delius>
Wed, 5 May 2004 07:07:56 +0000 (07:07 +0000)
12 files changed:
calendar/lib.php
course/lib.php
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
lib/db/schemaEvent.xml
lib/moodlelib.php
mod/assignment/lib.php
mod/chat/lib.php
mod/quiz/lib.php
version.php

index 0a9bede6fa7d327ecbb9f3ac41c1a71501b49924..ca9f821db23f46666e1cc2f24d6d31ac7fd01eb7 100644 (file)
@@ -474,7 +474,7 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
         // Just basic time filtering
         $whereclause = $timeclause;
     }
-    return $whereclause;
+    return $whereclause.' AND visible = 1';
 }
 
 function calendar_top_controls($type, $data) {
index 3198140d83b5753af30ac80b3b3794c6d3fe0ca0..e9762fbd302e7509545b105a4ec0ca008032e187 100644 (file)
@@ -754,7 +754,11 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
         if (!empty($section->sequence)) {
             $modules = explode(",", $section->sequence);
             foreach ($modules as $moduleid) {
-                set_field("course_modules", "visible", "$visibility", "id", $moduleid);
+                if ($visibility) {
+                    show_course_module($moduleid);
+                } else {
+                    hide_course_module($moduleid);
+                }
             }
         }
         rebuild_course_cache($courseid);
@@ -1639,10 +1643,24 @@ function set_groupmode_for_module($id, $groupmode) {
 }
 
 function hide_course_module($mod) {
+    $cm = get_record('course_modules', 'id', $mod);
+    $modulename = get_field('modules', 'name', 'id', $cm->module);
+    if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
+        foreach($events as $event) {
+            hide_event($event);
+        }
+    }
     return set_field("course_modules", "visible", 0, "id", $mod);
 }
 
 function show_course_module($mod) {
+    $cm = get_record('course_modules', 'id', $mod);
+    $modulename = get_field('modules', 'name', 'id', $cm->module);
+    if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
+        foreach($events as $event) {
+            show_event($event);
+        }
+    }
     return set_field("course_modules", "visible", 1, "id", $mod);
 }
 
index 132af2d864b584d1f65b4fe1165baa19a7cb7e43..9b208228bb985046cabe286a010fb8fa683bb1df 100644 (file)
@@ -258,15 +258,15 @@ function main_upgrade($oldversion=0) {
         // Commented out - see below where it's done properly
     }
 
-       if ($oldversion < 2003032500) {
-           modify_database("", "CREATE TABLE `prefix_user_coursecreators` (
+    if ($oldversion < 2003032500) {
+        modify_database("", "CREATE TABLE `prefix_user_coursecreators` (
                              `id` int(10) unsigned NOT NULL auto_increment,
                              `userid` int(10) unsigned NOT NULL default '0',
                              PRIMARY KEY  (`id`),
                              UNIQUE KEY `id` (`id`)
                              ) TYPE=MyISAM COMMENT='One record per course creator';");
-       }
-       if ($oldversion < 2003032602) {
+    }
+    if ($oldversion < 2003032602) {
         // Redoing it because of no prefix last time
         execute_sql(" ALTER TABLE `{$CFG->prefix}log_display` CHANGE `module` `module` VARCHAR( 20 ) NOT NULL ");
         // Add some indexes for speed
@@ -274,11 +274,11 @@ function main_upgrade($oldversion=0) {
         execute_sql(" ALTER TABLE `{$CFG->prefix}log` ADD INDEX(userid) ");
     }
 
-       if ($oldversion < 2003041400) {
+    if ($oldversion < 2003041400) {
         table_column("course_modules", "", "visible", "integer", "1", "unsigned", "1", "not null", "score");
     }
 
-       if ($oldversion < 2003042104) {  // Try to update permissions of all files
+    if ($oldversion < 2003042104) {  // Try to update permissions of all files
         if ($files = get_directory_list($CFG->dataroot)) {
             echo "Attempting to update permissions for all files... ignore any errors.";
             foreach ($files as $file) {
@@ -752,6 +752,19 @@ function main_upgrade($oldversion=0) {
         table_column("course", "hiddentopics", "hiddensections", "integer", "2", "unsigned", "0", "not null");
     }
 
+    if ($oldversion < 2004050400) {     /// add a visible field for events
+        table_column("event", "", "visible", "tinyint", "1", "", "1", "not null", "timeduration");
+        if ($events = get_records('event')) {
+            foreach($events as $event) {
+                if ($moduleid = get_field('modules', 'id', 'name', $event->modulename)) {
+                    if (get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $event->instance) == 0) {
+                        set_field('event', 'visible', 0, 'id', $event->id);
+                    }
+                }
+            }
+        }
+    }
+
     return $result;
 
 }
index 32e6353e2c493a290cf35e5309ef319327c43b5f..5405ab5fdc5800a5bce2d25188122be5d7e7794d 100644 (file)
@@ -151,6 +151,7 @@ CREATE TABLE `prefix_event` (
   `eventtype` varchar(20) NOT NULL default '',
   `timestart` int(10) unsigned NOT NULL default '0',
   `timeduration` int(10) unsigned NOT NULL default '0',
+  `visible` tinyint(4) NOT NULL default '1',
   `timemodified` int(10) unsigned NOT NULL default '0',
   PRIMARY KEY  (`id`),
   UNIQUE KEY `id` (`id`),
index a49247c5ede202185b491b42785a4a6d6c07ff57..1adf113f29ffafa81f0d2f7201c87b2285da2c44 100644 (file)
@@ -493,6 +493,19 @@ function main_upgrade($oldversion=0) {
     if ($oldversion < 2004043001) {     /// Add hiddentopics field to control hidden topics behaviour
         table_column("course", "", "hiddensections", "integer", "2", "unsigned", "0", "not null", "visible");
     }
+    
+    if ($oldversion < 2004050400) {     /// add a visible field for events
+        table_column("event", "", "visible", "tinyint", "1", "", "1", "not null", "timeduration");
+        if ($events = get_records('event')) {
+            foreach($events as $event) {
+                if ($moduleid = get_field('modules', 'id', 'name', $event->modulename)) {
+                    if (get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $event->instance) == 0) {
+                        set_field('event', 'visible', 0, 'id', $event->id);
+                    }
+                }
+            }
+        }
+    }
 
     return $result;
 
index 15f61a0a28c07b52fe800465f30630dee061fc3e..e0237d70f0489232e5f88a4bd3360209e3d55055 100644 (file)
@@ -95,6 +95,7 @@ CREATE TABLE prefix_event (
    eventtype varchar(20) NOT NULL default '',
    timestart integer NOT NULL default '0',
    timeduration integer NOT NULL default '0',
+   visible integer NOT NULL default '1',
    timemodified integer NOT NULL default '0'
 );
 
index c2b5ef187b83aa9639081b4ff3c319cb8893d181..894730afe82a79d9f7555531df896818c5cbae13 100755 (executable)
@@ -1,57 +1 @@
-<?xml version="1.0"?>\r
-<schema>\r
-  <table name="event">\r
-    <field name="id" type="I" size="10">\r
-      <KEY/>\r
-      <AUTOINCREMENT/>\r
-    </field>\r
-    <field name="name" type="X">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="description" type="C" size="255" default="">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="courseid" type="I" size="10" default="0">\r
-      <KEY/>\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="groupid" type="I" size="10" default="0">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="userid" type="I" size="10" default="0">\r
-      <KEY/>\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="modulename" type="C" size="20" default="">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="instance" type="I" size="10" default="0">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="eventtype" type="C" size="20" default="">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="timestart" type="I" size="10" default="0">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="timeduration" type="I" size="10" default="0">\r
-      <NOTNULL/>\r
-    </field>\r
-    <field name="timemodified" type="I" size="10" default="0">\r
-      <NOTNULL/>\r
-    </field>\r
-  </table>\r
-  <sql>\r
-    <descr>Insert 1 row for testing only...comment out later</descr>\r
-    <query platform="postgres|postgres7">\r
-      insert into event values (1,1,1,1,1,1,1,1,1,1,1,1)\r
-    </query>\r
-    <query platform="mysql">\r
-      insert into event values (1,1,1,1,1,1,1,1,1,1,1,1)\r
-    </query>\r
-    <query platform="oci8po">\r
-      insert into event values (1,1,1,1,1,1,1,1,1,1,1,1)\r
-    </query>\r
-  </sql>\r
-</schema>\r
-\r
+<?xml version="1.0"?>\r\r<schema>\r\r  <table name="event">\r\r    <field name="id" type="I" size="10">\r\r      <KEY/>\r\r      <AUTOINCREMENT/>\r\r    </field>\r\r    <field name="name" type="X">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="description" type="C" size="255" default="">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="courseid" type="I" size="10" default="0">\r\r      <KEY/>\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="groupid" type="I" size="10" default="0">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="userid" type="I" size="10" default="0">\r\r      <KEY/>\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="modulename" type="C" size="20" default="">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="instance" type="I" size="10" default="0">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="eventtype" type="C" size="20" default="">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="timestart" type="I" size="10" default="0">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="timeduration" type="I" size="10" default="0">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="visible" type="L" size="1" default="1">\r\r      <NOTNULL/>\r\r    </field>\r\r    <field name="timemodified" type="I" size="10" default="0">\r\r      <NOTNULL/>\r\r    </field>\r\r  </table>\r\r  <sql>\r\r    <descr>Insert 1 row for testing only...comment out later</descr>\r\r    <query platform="postgres|postgres7">\r\r      insert into event values (1,1,1,1,1,1,1,1,1,1,1,1,1)\r\r    </query>\r\r    <query platform="mysql">\r\r      insert into event values (1,1,1,1,1,1,1,1,1,1,1,1,1)\r\r    </query>\r\r    <query platform="oci8po">\r\r      insert into event values (1,1,1,1,1,1,1,1,1,1,1,1,1)\r\r    </query>\r\r  </sql>\r\r</schema>\r
\ No newline at end of file
index 5c4d8383164ee80916ad030cf3f8c661ab049a9c..197b179bacc6903988fee9fd109a2e25990fca06 100644 (file)
@@ -1036,7 +1036,7 @@ function remove_course_contents($courseid, $showfeedback=true) {
 /**
 * Returns a boolean: is the user a member of the given group?
 *
-* @param       type description
+* @param    type description
 */
 function ismember($groupid, $userid=0) {
     global $USER;
@@ -1063,7 +1063,7 @@ function ismember($groupid, $userid=0) {
 /**
 * Returns the group ID of the current user in the given course
 *
-* @param       type description
+* @param    type description
 */
 function mygroupid($courseid) {
     global $USER;
@@ -1080,7 +1080,7 @@ function mygroupid($courseid) {
 * what the current default groupmode is:
 * NOGROUPS, SEPARATEGROUPS or VISIBLEGROUPS
 *
-* @param       type description
+* @param    type description
 */
 function groupmode($course, $cm=null) {
 
@@ -1094,7 +1094,7 @@ function groupmode($course, $cm=null) {
 /**
 * Sets the current group in the session variable
 *
-* @param       type description
+* @param    type description
 */
 function set_current_group($courseid, $groupid) {
     global $SESSION;
@@ -1106,7 +1106,7 @@ function set_current_group($courseid, $groupid) {
 /**
 * Gets the current group for the current user as an id or an object
 *
-* @param       type description
+* @param    type description
 */
 function get_current_group($courseid, $full=false) {
     global $SESSION, $USER;
@@ -1133,7 +1133,7 @@ function get_current_group($courseid, $full=false) {
 * It will use a given "groupid" parameter and try to use
 * that to reset the current group for the user.
 *
-* @param       type description
+* @param    type description
 */
 function get_and_set_current_group($course, $groupmode, $groupid=-1) {
 
@@ -1177,7 +1177,7 @@ function get_and_set_current_group($course, $groupmode, $groupid=-1) {
 * Otherwise returns the current group if there is one
 * Otherwise returns false if groups aren't relevant
 *
-* @param       type description
+* @param    type description
 */
 function setup_and_print_groups($course, $groupmode, $urlroot) {
 
@@ -1999,6 +1999,42 @@ function delete_event($id) {
 }
 
 
+function hide_event($event) {
+/// call this function to hide an event in the calendar table
+/// the event will be identified by the id field of the $event object
+
+    global $CFG;
+
+    if (!empty($CFG->calendar)) { // call the update_event function of the selected calendar
+        if (file_exists("$CFG->dirroot/calendar/$CFG->calendar/lib.php")) {
+            include_once("$CFG->dirroot/calendar/$CFG->calendar/lib.php");
+            $calendar_hide_event = $CFG->calendar.'_hide_event';
+            if (function_exists($calendar_hide_event)) {
+                $calendar_hide_event($event);
+            }
+        }
+    }
+    return set_field('event', 'visible', 0, 'id', $event->id);
+}
+
+
+function show_event($event) {
+/// call this function to unhide an event in the calendar table
+/// the event will be identified by the id field of the $event object
+
+    global $CFG;
+
+    if (!empty($CFG->calendar)) { // call the update_event function of the selected calendar
+        if (file_exists("$CFG->dirroot/calendar/$CFG->calendar/lib.php")) {
+            include_once("$CFG->dirroot/calendar/$CFG->calendar/lib.php");
+            $calendar_show_event = $CFG->calendar.'_show_event';
+            if (function_exists($calendar_show_event)) {
+                $calendar_show_event($event);
+            }
+        }
+    }
+    return set_field('event', 'visible', 1, 'id', $event->id);
+}
 
 
 /// ENVIRONMENT CHECKING  ////////////////////////////////////////////////////////////
index a538067f461789f30b2ae149087edf532b20f4c6..6502e4279832697e79923db90a2281449045b845 100644 (file)
@@ -112,6 +112,7 @@ function assignment_refresh_events($courseid = 0) {
             return true;
         }
     }
+    $moduleid = get_field('modules', 'id', 'name', 'assignment');
 
     foreach ($assignments as $assignment) {
         $event = NULL;
@@ -130,9 +131,10 @@ function assignment_refresh_events($courseid = 0) {
             $event->instance    = $assignment->id;
             $event->eventtype   = 'due';
             $event->timeduration = 0;
-
+            $event->visible     = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $assignment->id);
             add_event($event);
         }
+
     }
     return true;
 }
index cbb0e743982f5d5c6a8237c57b35613e02e17841..594c5b817117864286d023cbce97785f1f5a4be7 100644 (file)
@@ -235,6 +235,7 @@ function chat_refresh_events($courseid = 0) {
             return true;
         }
     }
+    $moduleid = get_field('modules', 'id', 'name', 'chat');
 
     foreach ($chats as $chat) {
         $event = NULL;
@@ -253,7 +254,8 @@ function chat_refresh_events($courseid = 0) {
             $event->instance    = $chat->id;
             $event->eventtype   = $chat->schedule;
             $event->timeduration = 0;
-
+            $event->visible     = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $chat->id);
+            
             add_event($event);
         }
     }
index 697b85c21de73022f50b26fa9c0289e08f4e89ec..49451352aca9572b0d738a81473312ac6a889acf 100644 (file)
@@ -305,7 +305,8 @@ function quiz_refresh_events($courseid = 0) {
             return true;
         }
     }
-
+    $moduleid = get_field('modules', 'id', 'name', 'quiz');
+    
     foreach ($quizzes as $quiz) {
         $event = NULL;
         $event->name        = addslashes($quiz->name);
@@ -326,6 +327,7 @@ function quiz_refresh_events($courseid = 0) {
             $event->modulename  = 'quiz';
             $event->instance    = $quiz->id;
             $event->eventtype   = 'start';
+            $event->visible     = get_field('course_modules', 'visible', 'module', $moduleid, 'instance', $quiz->id);
 
             add_event($event);
         }
index 0820e579219fec1a8dab6c2dc370b008a9505290..cb1d18c2b1b301b3a148061f00983babe265edc8 100644 (file)
@@ -5,7 +5,7 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2004050300;   // The current version is a date (YYYYMMDDXX)
+$version = 2004050500;   // The current version is a date (YYYYMMDDXX)
 
 $release = "1.3 development";   // User-friendly version number