function _DegreePlan::find_courses
Search API
4.x _DegreePlan.php | _DegreePlan::find_courses($course_id, $group_id = 0, $semester_num) |
5.x _DegreePlan.php | _DegreePlan::find_courses($course_id, $group_id = 0, $semester_num, $degree_id = 0) |
If degree_id != 0, then we will remove any course from the finished list that is NOT in the degree plan. 0 means "give me all of matches back"
File
- classes/
_DegreePlan.php, line 1265
Class
Code
function find_courses($course_id, $group_id = 0, $semester_num, $degree_id = 0)
{
// This will locate a course within the degree plan, and return
// back either that course object, or FALSE.
$new_course = new Course($course_id);
$new_semester = new Semester($semester_num);
$rtn_course_list = new CourseList();
// Okay, if the course is within a group, then
// we can first use the find_group method.
if ($group_id != "" && $group_id != 0)
{
if ($group = $this->find_group($group_id))
{
if (!($group->list_courses->is_empty))
{
if ($cL = $group->find_courses($new_course))
{
$rtn_course_list->add_list($cL);
}
}
if (!($group->list_groups->is_empty))
{
// Look within each sub group for the course...
$group->list_groups->reset_counter();
while ($group->list_groups->has_more())
{
$branch = $group->list_groups->get_next();
if (!$branch->list_courses->is_empty)
{
if ($cL = $branch->find_courses($new_course))
{
$rtn_course_list->add_list($cL);
}
}
// Here we can look for groups within groups...
}
}
}
return $rtn_course_list;
}
else if ($semester_num != -1) {
// No group specified. This course is on the
// bare degree plan. We were given a specific semester,
// so try to find it there...
if ($semester = $this->list_semesters->find_match($new_semester))
{
if ($cL = $semester->list_courses->find_all_matches($new_course))
{
if ($degree_id != 0) {
// Trim $cL of any courses NOT in our supplied degree_id.
$cL->remove_courses_not_in_degree($degree_id);
if ($cL->get_size() == 0) {
return FALSE; // we removed them all!
}
}
$rtn_course_list->add_list($cL);
return $rtn_course_list;
}
}
}
else if ($semester_num == -1)
{
// Meaning, we do not know which semester it goes in, so
// attempt all semesters, and return with the first instance.
$this->list_semesters->reset_counter();
while ($this->list_semesters->has_more())
{
$sem = $this->list_semesters->get_next();
if ($cL = $sem->list_courses->find_all_matches($new_course))
{
$rtn_course_list->add_list($cL);
return $rtn_course_list;
}
}
}
return FALSE;
}