mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-47466-master' of https://github.com/tehanuyor/moodle
This commit is contained in:
commit
62e965c9b8
1 changed files with 14 additions and 21 deletions
|
@ -683,19 +683,18 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$whereclause = '';
|
$whereclause = '';
|
||||||
|
$params = array();
|
||||||
// Quick test
|
// Quick test
|
||||||
if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
|
if(is_bool($users) && is_bool($groups) && is_bool($courses)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_array($users) && !empty($users)) {
|
if ((is_array($users) && !empty($users)) or is_numeric($users)) {
|
||||||
// Events from a number of users
|
// Events from a number of users
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||||
$whereclause .= ' (userid IN ('.implode(',', $users).') AND courseid = 0 AND groupid = 0)';
|
list($insqlusers, $inparamsusers) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED);
|
||||||
} else if(is_numeric($users)) {
|
$whereclause .= " (userid $insqlusers AND courseid = 0 AND groupid = 0)";
|
||||||
// Events from one user
|
$params = array_merge($params, $inparamsusers);
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
|
||||||
$whereclause .= ' (userid = '.$users.' AND courseid = 0 AND groupid = 0)';
|
|
||||||
} else if($users === true) {
|
} else if($users === true) {
|
||||||
// Events from ALL users
|
// Events from ALL users
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||||
|
@ -704,14 +703,12 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
|
||||||
// No user at all, do nothing
|
// No user at all, do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_array($groups) && !empty($groups)) {
|
if ((is_array($groups) && !empty($groups)) or is_numeric($groups)) {
|
||||||
// Events from a number of groups
|
// Events from a number of groups
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||||
$whereclause .= ' groupid IN ('.implode(',', $groups).')';
|
list($insqlgroups, $inparamsgroups) = $DB->get_in_or_equal($groups, SQL_PARAMS_NAMED);
|
||||||
} else if(is_numeric($groups)) {
|
$whereclause .= " groupid $insqlgroups ";
|
||||||
// Events from one group
|
$params = array_merge($params, $inparamsgroups);
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR ';
|
|
||||||
$whereclause .= ' groupid = '.$groups;
|
|
||||||
} else if($groups === true) {
|
} else if($groups === true) {
|
||||||
// Events from ALL groups
|
// Events from ALL groups
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR ';
|
if(!empty($whereclause)) $whereclause .= ' OR ';
|
||||||
|
@ -719,15 +716,11 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
|
||||||
}
|
}
|
||||||
// boolean false (no groups at all): we don't need to do anything
|
// boolean false (no groups at all): we don't need to do anything
|
||||||
|
|
||||||
if(is_array($courses) && !empty($courses)) {
|
if ((is_array($courses) && !empty($courses)) or is_numeric($courses)) {
|
||||||
if(!empty($whereclause)) {
|
|
||||||
$whereclause .= ' OR';
|
|
||||||
}
|
|
||||||
$whereclause .= ' (groupid = 0 AND courseid IN ('.implode(',', $courses).'))';
|
|
||||||
} else if(is_numeric($courses)) {
|
|
||||||
// One course
|
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||||
$whereclause .= ' (groupid = 0 AND courseid = '.$courses.')';
|
list($insqlcourses, $inparamscourses) = $DB->get_in_or_equal($courses, SQL_PARAMS_NAMED);
|
||||||
|
$whereclause .= " (groupid = 0 AND courseid $insqlcourses)";
|
||||||
|
$params = array_merge($params, $inparamscourses);
|
||||||
} else if ($courses === true) {
|
} else if ($courses === true) {
|
||||||
// Events from ALL courses
|
// Events from ALL courses
|
||||||
if(!empty($whereclause)) $whereclause .= ' OR';
|
if(!empty($whereclause)) $whereclause .= ' OR';
|
||||||
|
@ -761,7 +754,7 @@ function calendar_get_events($tstart, $tend, $users, $groups, $courses, $withdur
|
||||||
$whereclause .= ' AND visible = 1';
|
$whereclause .= ' AND visible = 1';
|
||||||
}
|
}
|
||||||
|
|
||||||
$events = $DB->get_records_select('event', $whereclause, null, 'timestart');
|
$events = $DB->get_records_select('event', $whereclause, $params, 'timestart');
|
||||||
if ($events === false) {
|
if ($events === false) {
|
||||||
$events = array();
|
$events = array();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue