Best fix for bug in calendar function?

Best fix for bug in calendar function?

by Dave Balch -
Number of replies: 0

Hi,

I found that calendar_get_events()  (incorrectly) always returns an empty array when all three of the $users, $groups, $courses options are boolean - even when some of them are boolean true.

A conservative fix would be:

diff --git a/calendar/lib.php b/calendar/lib.php
index 184997e..e92b34e 100644
--- a/calendar/lib.php
+++ b/calendar/lib.php
@@ -729,8 +729,10 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
     $whereclause = '';
     $params = array();
     // Quick test
-    if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
-        return array();
+    if (is_bool($users) && empty($users) &&
+        is_bool($groups) && empty($groups) &&
+        is_bool($courses)) && empty($courses)) {
+            return array();
     }

...but I figured this might be better:

diff --git a/calendar/lib.php b/calendar/lib.php
index 184997e..1bc8ddd 100644
--- a/calendar/lib.php
+++ b/calendar/lib.php
@@ -729,8 +729,8 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
     $whereclause = '';
     $params = array();
     // Quick test
-    if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
-        return array();
+    if (empty($users) && empty($groups) && empty($courses)) {
+            return array();
     }
 
     if ((is_array($users) && !empty($users)) or is_numeric($users)) {

Am I right in thinking that there should be no case where any of $users, $groups, or $courses are passed '0' as a valid value?

Average of ratings: -