]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12313 basically rationalising getting calendar events function calls
authordwoolhead <dwoolhead>
Mon, 26 Nov 2007 14:43:28 +0000 (14:43 +0000)
committerdwoolhead <dwoolhead>
Mon, 26 Nov 2007 14:43:28 +0000 (14:43 +0000)
calendar/export_execute.php
calendar/lib.php
calendar/view.php

index 2afb1ff6d8c6da7675b196bd78af85c4cfbcc78e..001a2c12f165c318e5da852237eadffe2dd60ac0 100644 (file)
@@ -99,17 +99,7 @@ if(!empty($what) && !empty($time)) {
         die();
     }
 }
-$whereclause = calendar_sql_where($timestart, $timeend, $include_user ? array($user->id) : false, false, array_keys($courses), false);
-if($whereclause === false) {
-    $events = array();
-}
-else {
-    $events = get_records_select('event', $whereclause, 'timestart');
-}
-
-if ($events === false) {
-    $events = array();
-}
+$events = calendar_get_events($timestart, $timeend, $include_user ? array($user->id) : false, false, array_keys($courses), false);
 
 $ical = new iCalendar;
 $ical->add_property('method', 'PUBLISH');
index c92310188f7cd8e4cff2d2dadc906ea55c544d9e..d4d9ac4d3e22edc506d996e66e5605da10ac3c21 100644 (file)
@@ -136,18 +136,11 @@ function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_y
 
 
     // Get the events matching our criteria. Don't forget to offset the timestamps for the user's TZ!
-    $whereclause = calendar_sql_where(
+    $events = calendar_get_events(
         usertime($display->tstart) - dst_offset_on($display->tstart),
         usertime($display->tend) - dst_offset_on($display->tend),
         $users, $groups, $courses);
 
-    if($whereclause === false) {
-        $events = array();
-    }
-    else {
-        $events = get_records_select('event', $whereclause, 'timestart');
-    }
-
     // Set event course class for course events
     if (!empty($events)) {
         foreach ($events as $eventid => $event) {
@@ -396,12 +389,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve
     $display->tend = usergetmidnight($display->tstart + DAYSECS * $display->range + 3 * HOURSECS) - 1;
 
     // Get the events matching our criteria
-    $whereclause = calendar_sql_where($display->tstart, $display->tend, $users, $groups, $courses);
-    if ($whereclause === false) {
-        $events = false;
-    } else {
-        $events = get_records_select('event', $whereclause, 'timestart');
-    }
+    $events = calendar_get_events($display->tstart, $display->tend, $users, $groups, $courses);
 
     // This is either a genius idea or an idiot idea: in order to not complicate things, we use this rule: if, after
     // possibly removing SITEID from $courses, there is only one course left, then clicking on a day in the month
@@ -570,11 +558,23 @@ function calendar_print_event($event) {
 
 }
 
-function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withduration=true, $ignorehidden=true) {
+/**
+ * Get calendar events
+ * @param int $tstart Start time of time range for events
+ * @param int $tend   End time of time range for events
+ * @param array/int/boolean $users array of users, user id or boolean for all/no user events
+ * @param array/int/boolean $groups array of groups, group id or boolean for all/no group events
+ * @param array/int/boolean $courses array of courses, course id or boolean for all/no course events
+ * @param boolean $withduration whether only events starting within time range selected
+ *                              or events in progress/already started selected as well
+ * @param boolean $ignorehidden whether to select only visible events or all events
+ * @return array of selected events or an empty array if there aren't any (or there was an error)
+ */
+function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withduration=true, $ignorehidden=true) {
     $whereclause = '';
     // Quick test
     if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
-        return false;
+        return array();
     }
 
     if(is_array($users) && !empty($users)) {
@@ -642,7 +642,7 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
     // events no matter what. Allowing the code to proceed might return a completely
     // valid query with only time constraints, thus selecting ALL events in that time frame!
     if(empty($whereclause)) {
-        return false;
+        return array();
     }
 
     if($withduration) {
@@ -664,7 +664,11 @@ function calendar_sql_where($tstart, $tend, $users, $groups, $courses, $withdura
         $whereclause .= ' AND visible = 1';
     }
 
-    return $whereclause;
+    $events = get_records_select('event', $whereclause, 'timestart');
+    if ($events === false) {
+        $events = array();
+    }
+    return $events;
 }
 
 function calendar_top_controls($type, $data) {
index 47cc1fa98b3460958eac909ffdb806b5657da4b1..a8c9431222c7f9cac7c77ec5046847c829ed3b80 100644 (file)
@@ -361,13 +361,7 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users, $course
     }
 
     // Get events from database
-    $whereclause = calendar_sql_where(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
-    if($whereclause === false) {
-        $events = array();
-    }
-    else {
-        $events = get_records_select('event', $whereclause, 'timestart');
-    }
+    $events = calendar_get_events(usertime($display->tstart), usertime($display->tend), $users, $groups, $courses);
     if (!empty($events)) {
         foreach($events as $eventid => $event) {
             if (!empty($event->modulename)) {