Child courses import list empty MDL-7424; added new count_courses_notin_metacourse() function, the old one was kept for BC

This commit is contained in:
skodak 2006-11-09 21:12:31 +00:00
parent 6403e67965
commit 493cde249e
2 changed files with 20 additions and 5 deletions

View File

@ -110,13 +110,12 @@
/// If no search results then get potential students for this course excluding users already in course
if (empty($searchcourses)) {
$numcourses = count_courses_notin_metacourse($course->id);
$numcourses = get_courses_notin_metacourse($course->id,true);
$courses = array();
if ($numcourses <= MAX_COURSES_PER_PAGE) {
if ($numcourses > 0 and $numcourses <= MAX_COURSES_PER_PAGE) {
$courses = get_courses_notin_metacourse($course->id);
} else {
$courses = array();
}
}

View File

@ -97,6 +97,22 @@ function get_courses_notin_metacourse($metacourseid,$count=false) {
return get_records_sql($sql);
}
function count_courses_notin_metacourse($metacourseid) {
global $CFG;
$alreadycourses = get_courses_in_metacourse($metacourseid);
$sql = "SELECT 1, COUNT(c.id) AS notin FROM {$CFG->prefix}course c
WHERE ".((!empty($alreadycourses)) ? "c.id NOT IN (".implode(',',array_keys($alreadycourses)).")
AND " : "")." c.id !=$metacourseid and c.id != ".SITEID." and c.metacourse != 1";
if (!$result = get_records_sql($sql)) {
return 0;
}
return $result[1]->notin;
}
/**
* Search through course users
*