From c635dcda6c75a20bf3bf7e4008de953297951f4e Mon Sep 17 00:00:00 2001 From: defacer Date: Mon, 24 May 2004 10:35:43 +0000 Subject: [PATCH] Fix for bug 1451: Now when moving to a calendar screen (technically, view.php) from a course block, the course drop down list defaults to that course. The implementation is OK, but I may change it (there is a faster way). --- calendar/lib.php | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index d6a3218234..ba94217bc4 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -115,6 +115,19 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y $events = get_records_select('event', $whereclause); } + // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after + // possibly removing courseid 1 from $courses, there is only one course left, then clicking on a day in the month + // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra + // arguments to this function. + + $courses = array_diff($courses, array(1)); + if(count($courses) == 1) { + $morehref = '&course='.reset($courses); + } + else { + $morehref = ''; + } + // We want to have easy access by day, since the display is on a per-day basis. // Arguments passed by reference. calendar_events_by_day($events, $display->tstart, $eventsbyday, $durationbyday, $typesbyday); @@ -163,7 +176,7 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y // Special visual fx if an event is defined if(isset($eventsbyday[$day])) { - $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day&', $day, $m, $y); + $dayhref = calendar_get_link_href(CALENDAR_URL.'view.php?view=day'.$morehref.'&', $day, $m, $y); // OverLib popup $popupcontent = ''; @@ -260,7 +273,7 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxevents, $fromtime=0) { global $CFG; - $display = &New object; + $display = &New stdClass; $display->range = $daysinfuture; // How many days in the future we 'll look $display->maxevents = $maxevents; @@ -294,6 +307,19 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve $events = get_records_select('event', $whereclause); } + // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after + // possibly removing courseid 1 from $courses, there is only one course left, then clicking on a day in the month + // will also set the $SESSION->cal_courses_shown variable to that one course. Otherwise, we 'd need to add extra + // arguments to this function. + + $courses = array_diff($courses, array(1)); + if(count($courses) == 1) { + $morehref = '&course='.reset($courses); + } + else { + $morehref = ''; + } + if($events !== false) { foreach($events as $event) { if($processed >= $display->maxevents) break; @@ -324,7 +350,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve $time = calendar_time_representation($event->timestart + $event->timeduration); // This var always has the printable time representation - $eventtime = ''.$day.' ('.$time.')'; + $eventtime = ''.$day.' ('.$time.')'; } else if($event->timeduration) { @@ -336,7 +362,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve $timeend = calendar_time_representation($event->timestart + $event->timeduration); // Set printable representation - $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day&', $enddate['mday'], $enddate['mon'], $enddate['year']). + $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $enddate['mday'], $enddate['mon'], $enddate['year']). ' ('.$timestart.' -> '.$timeend.')'; } else { @@ -347,8 +373,8 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve $timeend = calendar_time_representation($event->timestart + $event->timeduration); // Set printable representation - $eventtime = calendar_get_link_tag($daystart, CALENDAR_URL.'view.php?view=day&', $startdate['mday'], $startdate['mon'], $startdate['year']). - ' ('.$timestart.') -> '.calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day&', $enddate['mday'], $enddate['mon'], $enddate['year']). + $eventtime = calendar_get_link_tag($daystart, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $startdate['mday'], $startdate['mon'], $startdate['year']). + ' ('.$timestart.') -> '.calendar_get_link_tag($dayend, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $enddate['mday'], $enddate['mon'], $enddate['year']). ' ('.$timeend.')'; } } @@ -358,7 +384,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve $time = calendar_time_representation($event->timestart); // Set printable representation - $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day&', $startdate['mday'], $startdate['mon'], $startdate['year']).' ('.$time.')'; + $eventtime = calendar_get_link_tag($day, CALENDAR_URL.'view.php?view=day'.$morehref.'&', $startdate['mday'], $startdate['mon'], $startdate['year']).' ('.$time.')'; } $outkey = count($output); -- 2.39.5