Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Child courses import list empty MDL-7424; added new count_courses_not…
…in_metacourse() function, the old one was kept for BC
  • Loading branch information
skodak committed Nov 9, 2006
1 parent 6403e67 commit 493cde2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 4 additions & 5 deletions course/importstudents.php
Expand Up @@ -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();
}
}

Expand Down
16 changes: 16 additions & 0 deletions lib/datalib.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 493cde2

Please sign in to comment.