From: gustav_delius Date: Wed, 5 May 2004 07:07:56 +0000 (+0000) Subject: Events associated to hidden activities are now invisible in calendar, using new field... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=dcd338ffdc5e8153f6e72840dee8795ddca39e0c;p=moodle.git Events associated to hidden activities are now invisible in calendar, using new field 'visible' in table 'event' which is updated each time a course module is hidden or unhidden. --- diff --git a/calendar/lib.php b/calendar/lib.php index 0a9bede6fa..ca9f821db2 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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) { diff --git a/course/lib.php b/course/lib.php index 3198140d83..e9762fbd30 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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); } diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 132af2d864..9b208228bb 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -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; } diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 32e6353e2c..5405ab5fdc 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -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`), diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index a49247c5ed..1adf113f29 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -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; diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index 15f61a0a28..e0237d70f0 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -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' ); diff --git a/lib/db/schemaEvent.xml b/lib/db/schemaEvent.xml index c2b5ef187b..894730afe8 100755 --- a/lib/db/schemaEvent.xml +++ b/lib/db/schemaEvent.xml @@ -1,57 +1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Insert 1 row for testing only...comment out later - - insert into event values (1,1,1,1,1,1,1,1,1,1,1,1) - - - insert into event values (1,1,1,1,1,1,1,1,1,1,1,1) - - - insert into event values (1,1,1,1,1,1,1,1,1,1,1,1) - - -
- +
Insert 1 row for testing only...comment out later insert into event values (1,1,1,1,1,1,1,1,1,1,1,1,1) insert into event values (1,1,1,1,1,1,1,1,1,1,1,1,1) insert into event values (1,1,1,1,1,1,1,1,1,1,1,1,1)
\ No newline at end of file diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 5c4d838316..197b179bac 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 //////////////////////////////////////////////////////////// diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index a538067f46..6502e42798 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -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; } diff --git a/mod/chat/lib.php b/mod/chat/lib.php index cbb0e74398..594c5b8171 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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); } } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 697b85c21d..49451352ac 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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); } diff --git a/version.php b/version.php index 0820e57921..cb1d18c2b1 100644 --- a/version.php +++ b/version.php @@ -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