function _AdvisingScreen::display_popup_group_select
Search API
4.x _AdvisingScreen.php | _AdvisingScreen::display_popup_group_select(Group $place_group, $group_hours_remaining = 0) |
5.x _AdvisingScreen.php | _AdvisingScreen::display_popup_group_select(Group $place_group, $group_hours_remaining = 0, $req_by_degree_id = 0) |
This function displays the popup which lets a user select a course to be advised into a group.
Parameters
Group $place_group:
int $group_hours_remaining:
Return value
string
File
- classes/
_AdvisingScreen.php, line 3669
Class
Code
function display_popup_group_select(Group $place_group, $group_hours_remaining = 0)
{
$pC = "";
$advising_term_id = $GLOBALS ["fp_advising"]["advising_term_id"];
if ($place_group->group_id != -88)
{
// This is NOT the Add a Course group.
if (!$group = $this->degree_plan->find_group($place_group->group_id))
{
fpm("Group not found.");
return;
}
}
else {
// This is the Add a Course group.
$group = $place_group;
}
$group_id = $group->group_id;
// So now we have a group object, $group, which is most likely
// missing courses. This is because when we loaded & cached it
// earlier, we did not load any course which wasn't a "significant course,"
// meaning, the student didn't have credit for it or the like.
// So what we need to do now is reload the group, being careful
// to preserve the existing courses / sub groups in the group.
$group->reload_missing_courses();
if ($group_hours_remaining == 0)
{
// Attempt to figure out the remaining hours (NOT WORKING IN ALL CASES!)
// This specifically messes up when trying to get fulfilled hours in groups
// with branches.
$group_fulfilled_hours = $group->get_fulfilled_hours(true, true, false, $place_group->assigned_to_semester_num);
$group_hours_remaining = $place_group->hours_required - $group_fulfilled_hours;
}
$display_semesterNum = $place_group->assigned_to_semester_num;
$pC .= "<!--MSG--><!--MSG2--><!--BOXTOP-->";
$bool_display_submit = true;
$bool_display_back_to_subject_select = false;
$bool_subject_select = false;
$bool_unselectableCourses = false;
$final_course_list = new CourseList();
$group->list_courses->reset_counter();
if (!($group->list_courses->is_empty))
{
$group->list_courses->assign_semester_num($display_semesterNum);
$new_course_list = $group->list_courses;
// Is this list so long that we first need to ask the user to
// select a subject?
if ($new_course_list->get_size() > 30)
{
// First, we are only going to do this if there are more
// than 30 courses, AND more than 2 subjects in the list.
$new_course_list->sort_alphabetical_order();
$subject_array = $new_course_list->get_course_subjects();
//print_pre($new_course_list->to_string());
//var_dump($subject_array);
if (count($subject_array) > 2)
{
// First, check to see if the user has already
// selected a subject.
$selected_subject = trim(addslashes($_GET ["selected_subject"]));
if ($selected_subject == "")
{
// Prompt them to select a subject first.
$pC .= $this->draw_popup_group_subject_select($subject_array, $group->group_id, $display_semesterNum, $group_hours_remaining);
$new_course_list = new CourseList(); // empty it
$bool_display_submit = false;
$bool_subject_select = true;
}
else {
// Reduce the newCourseList to only contain the
// subjects selected.
$new_course_list->exclude_all_subjects_except($selected_subject);
$bool_display_back_to_subject_select = true;
}
}
}
$new_course_list->reset_counter();
$new_course_list->sort_alphabetical_order();
$final_course_list->add_list($new_course_list);
}
if (!($group->list_groups->is_empty))
{
// Basically, this means that this group
// has multiple subgroups. We need to find out
// which branches the student may select from
// (based on what they have already taken, or been
// advised to take), and display it (excluding duplicates).
//print_pre($group->to_string());
// The first thing we need to do, is find the subgroup
// or subgroups with the most # of matches.
$new_course_list = new CourseList();
$all_zero = true;
// Okay, this is a little squirely. What I need to do
// first is get a course list of all the courses which
// are currently either fulfilling or advised for all branches
// of this group.
$fa_course_list = new CourseList();
$group->list_groups->reset_counter();
while ($group->list_groups->has_more())
{
$branch = $group->list_groups->get_next();
$fa_course_list->add_list($branch->list_courses->get_fulfilled_or_advised(true));
}
$fa_course_list->remove_duplicates();
//print_pre($fa_course_list->to_string());
// Alright, now we create a fake student and set their
// list_courses_taken, so that we can use this student
// to recalculate the count_of_matches in just a moment.
$new_student = new Student();
$new_student->load_student();
$new_student->list_courses_taken = $fa_course_list;
$new_student->load_significant_courses_from_list_courses_taken();
// Okay, now we need to go through and re-calculate our
// count_of_matches for each branch. This is because we
// have cached this value, and after some advisings, it may
// not be true any longer.
$highest_match_count = 0;
$group->list_groups->reset_counter();
while ($group->list_groups->has_more())
{
$branch = $group->list_groups->get_next();
// recalculate count_of_matches here.
$clone_branch = new Group();
$clone_branch->list_courses = $branch->list_courses->get_clone(true);
$matches_count = $this->flightpath->get_count_of_matches($clone_branch, $new_student, null);
$branch->count_of_matches = $matches_count;
if ($matches_count >= $highest_match_count)
{ // Has more than one match on this branch.
$highest_match_count = $matches_count;
}
}
// If highestMatchCount > 0, then get all the branches
// which have that same match count.
if ($highest_match_count > 0)
{
$group->list_groups->reset_counter();
while ($group->list_groups->has_more())
{
$branch = $group->list_groups->get_next();
if ($branch->count_of_matches == $highest_match_count)
{ // This branch has the right number of matches. Add it.
$new_course_list->add_list($branch->list_courses);
$all_zero = false;
}
}
}
if ($all_zero == true)
{
// Meaning, all of the branches had 0 matches,
// so we should add all the branches to the
// newCourseList.
$group->list_groups->reset_counter();
while ($group->list_groups->has_more())
{
$branch = $group->list_groups->get_next();
$new_course_list->add_list($branch->list_courses);
}
}
else {
// Meaning that at at least one branch is favored.
// This also means that a user's course
// selections have been restricted as a result.
// Replace the MSG at the top saying so.
$msg = "<div class='tenpt'>" . t("Your selection of courses has been
restricted based on previous course selections.") . "</div>";
$pC = str_replace("<!--MSG-->", $msg, $pC);
}
// Okay, in the newCourseList object, we should
// now have a list of all the courses the student is
// allowed to take, but there are probably duplicates.
//print_pre($new_course_list->to_string());
$new_course_list->remove_duplicates();
$new_course_list->assign_group_id($group->group_id);
$new_course_list->assign_semester_num($display_semesterNum);
$final_course_list->add_list($new_course_list);
}
//print_pre($final_course_list->to_string());
// Remove courses which have been marked as "exclude" in the database.
$final_course_list->remove_excluded();
//print_pre($final_course_list->to_string());
// Here's a fun one: We need to remove courses for which the student
// already has credit that *don't* have repeating hours.
// For example, if a student took MATH 113, and it fills in to
// Core Math, then we should not see it as a choice for advising
// in Free Electives (or any other group except Add a Course).
// We also should not see it in other instances of Core Math.
if ($group->group_id != -88 && $this->bool_blank != TRUE)
{
// Only do this if NOT in Add a Course group...
// also, don't do it if we're looking at a "blank" degree.
$final_course_list->remove_previously_fulfilled($this->student->list_courses_taken, $group->group_id, true, $this->student->list_substitutions);
}
$final_course_list->sort_alphabetical_order();
if (!$final_course_list->has_any_course_selected()) {
if ($c = $final_course_list->find_first_selectable()) {
$c->bool_selected = true;
}
}
// flag any courses with more hours than are available for this group.
if ($final_course_list->assign_unselectable_courses_with_hours_greater_than($group_hours_remaining))
{
$bool_unselectableCourses = true;
}
$pC .= $this->display_popup_group_select_course_list($final_course_list, $group_hours_remaining);
// If there were no courses in the finalCourseList, display a message.
if (count($final_course_list->array_list) < 1 && !$bool_subject_select)
{
$pC .= "<tr>
<td colspan='8'>
<div class='tenpt'>
<b>Please Note:</b>
" . t("FlightPath could not find any eligible
courses to display for this list. Ask your advisor
if you have completed courses, or may enroll in
courses, which can be
displayed here.");
if (user_has_permission("can_advise_students")) {
// This is an advisor, so put in a little more
// information.
$pC .= "
<div class='tenpt' style='padding-top: 5px;'><b>" . t("Special note to advisors:") . "</b> " . t("You may still
advise a student to take a course, even if it is unselectable
in this list. Use the \"add an additional course\" link at
the bottom of the page.") . "</div>";
}
$pC .= " </div>
</td>
</tr>";
$bool_no_courses = true;
}
$pC .= $this->draw_semester_box_bottom();
$s = "s";
//print_pre($place_group->to_string());
if ($group_hours_remaining == 1) {
$s = "";
}
if ($bool_unselectableCourses == true) {
$unselectable_notice = " <div class='tenpt'><i>(" . t("Courses worth more than %hrs hour$s
may not be selected.", array("%hrs" => $group_hours_remaining)) . ")</i></div>";
if (user_has_permission("can_advise_students")) {
// This is an advisor, so put in a little more
// information.
$unselectable_notice .= "
<div class='tenpt' style='padding-top: 5px;'><b>" . t("Special note to advisors:") . "</b> " . t("You may still
advise a student to take a course, even if it is unselectable
in this list. Use the \"add an additional course\" link at
the bottom of the page.") . "</div>";
}
}
if ($group_hours_remaining < 100 && $bool_no_courses != true) {
// Don't show for huge groups (like add-a-course)
$pC .= "<div class='elevenpt' style='margin-top:5px;'>
" . t("You may select <b>@hrs</b>
hour$s from this list.", array("@hrs" => $group_hours_remaining)) . "$unselectable_notice</div>";
}
if ($bool_display_submit == true && !$this->bool_blank && $bool_no_courses != true)
{
if (user_has_permission("can_advise_students")) {
$pC .= "<input type='hidden' name='varHours' id='varHours' value=''>
<div style='margin-top: 20px;'>
" . fp_render_button(t("Select Course"), "popupAssignSelectedCourseToGroup(\"$place_group->assigned_to_semester_num\", \"$group->group_id\",\"$advising_term_id\",\"-1\");", true, "style='font-size: 10pt;'") . "
</div>
";
}
}
// Substitutors get extra information:
if (user_has_permission("can_substitute") && $group->group_id != -88)
{
$pC .= "<div class='tenpt' style='margin-top: 20px;'>
<b>" . t("Special administrative information:") . "</b>
<span id='viewinfolink'
onClick='document.getElementById(\"admin_info\").style.display=\"\"; this.style.display=\"none\"; '
class='hand' style='color: blue;'
> - " . t("Click to show") . " -</span>
<div style='padding-left: 20px; display:none;' id='admin_info'>
" . t("Information about this group:") . "<br>
" . t("Group ID:") . " $group->group_id<br>
" . t("Title:") . " $group->title<br>";
$pC .= " <i>" . t("Internal name:") . " $group->group_name</i><br>";
$pC .= " " . t("Catalog year:") . " $group->catalog_year
</div>
</div>";
}
if ($bool_display_back_to_subject_select == true) {
$csid = $GLOBALS ["current_student_id"];
$blank_degree_id = "";
if ($this->bool_blank)
{
$blank_degree_id = $this->degree_plan->degree_id;
}
$back_link = "<span class='tenpt'>
<a href='" . base_path() . "/advise/popup-group-select&window_mode=popup&group_id=$group->group_id&semester_num=$display_semesterNum&group_hours_remaining=$group_hours_remaining¤t_student_id=$csid&blank_degree_id=$blank_degree_id'
class='nounderline'>" . t("Click here to return to subject selection.") . "</a></span>";
$pC = str_replace("<!--MSG2-->", $back_link, $pC);
}
$box_top = $this->draw_semester_box_top("$group->title", !$bool_display_submit);
$pC = str_replace("<!--BOXTOP-->", $box_top, $pC);
return $pC;
}