_FlightPath::flag_outdated_substitutions

5.x _FlightPath.php _FlightPath::flag_outdated_substitutions()
4.x _FlightPath.php _FlightPath::flag_outdated_substitutions()

File

classes/_FlightPath.php, line 542

Class

_FlightPath

Code

function flag_outdated_substitutions() {
  // Go through the student's substitutions and flag ones that
  // do not apply to this degree plan.  Also, unset any bool_substitution
  // variables which were set.

  $this->student->list_substitutions->reset_counter();
  while ($this->student->list_substitutions->has_more()) {
    $substitution = $this->student->list_substitutions->get_next();

    ////////////////////////////
    // Ticket #2316, from Logan Buth, this is to better detect outdated subs for combined degrees.
    $bool_sub_valid = true;
    $outdated_note = "";

    if ($this->degree_plan->degree_id == DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE && !in_array($substitution->db_required_degree_id, $this->degree_plan->combined_degree_ids_array)) {
      //combined degree plan, degree id not in it.

      $bool_sub_valid = false;
      $sub_degree_title = fp_get_degree_title($substitution->db_required_degree_id, TRUE, TRUE, FALSE, TRUE);

      $outdated_note = t("This substitution is for the degree %did
                            which is no longer in the student's degrees.", array("%did" => $sub_degree_title));
    }
    else if ($this->degree_plan->degree_id != DegreePlan::DEGREE_ID_FOR_COMBINED_DEGREE && $this->degree_plan->degree_id != $substitution->db_required_degree_id) {

      $bool_sub_valid = false;
      $sub_degree_title = fp_get_degree_title($substitution->db_required_degree_id, TRUE, TRUE, FALSE, TRUE);
      $outdated_note = t("This substitution is for the degree %did
                            which is no longer the student's degree", array("%did" => $sub_degree_title));
    }
    //////////////





    //$required_group_id = $substitution->course_requirement->assigned_to_group_id;
    $required_group_id = $substitution->course_requirement->get_first_assigned_to_group_id(); // we assume there's only one group to get


    // First check-- does this degree even have this group ID?
    if ($bool_sub_valid && $required_group_id == 0) {
      // bare degree plan.
      // Does the bare degree plan list the course_requirement
      // anywhere?
      $bool_sub_valid = false;
      $this->degree_plan->list_semesters->reset_counter();
      while ($this->degree_plan->list_semesters->has_more() && $bool_sub_valid == false) {
        $sem = $this->degree_plan->list_semesters->get_next();
        if ($sem->list_courses->find_match($substitution->course_requirement)) {
          $bool_sub_valid = true;
        }
        else {
          // Could not find the course requirement in question.
          $bool_sub_valid = false;
          $scr = $substitution->course_requirement;
          $scr->load_descriptive_data();
          $outdated_note = t("This substitution is for the course %info on the 
                      bare degree plan, but the student's current degree does
                      not specify this course.", array("%info" => "$scr->subject_id $scr->course_num (id: $scr->course_id)"));
        }
      }


    }
    else if ($bool_sub_valid && $required_group_id != 0) {
      // required_group_id != 0, meaning, NOT the bare degree plan.
      // So, does this degree plan have a group with this id (required_group_id)?
      $bool_sub_valid = false;
      if ($g = $this->degree_plan->find_group($required_group_id)) {
        $bool_sub_valid = true;
      }
      else {
        // Could not find the group in question.  Add an "outdated_note"
        // to the sub...
        $bool_sub_valid = false;
        $new_group = new Group();
        $new_group->group_id = $required_group_id;
        $new_group->load_descriptive_data();
        $group_name = "";
        if (user_has_permission("can_access_data_entry")) {
          // only show if we are a data entry administrator.
          $group_name = "<i>$new_group->group_name,</i>";
        }
        $outdated_note = t("This substitution is for the group %info,
                  but the student's current degree does not call for this 
                  specific group.", array("%info" => "$new_group->title (id: $new_group->group_id, $group_name $new_group->catalog_year)"));
      }
    }


    if ($bool_sub_valid == false) {

      // Couldn't find a match, so remove this sub!
      $substitution->bool_outdated = true;
      $substitution->outdated_note = $outdated_note;
      $substitution->course_list_substitutions->get_first()->bool_outdated_sub = true;
      $substitution->course_list_substitutions->get_first()->set_bool_outdated_sub(0, TRUE);
      //$substitution->course_list_substitutions->get_first()->bool_substitution = false;
      $substitution->course_list_substitutions->get_first()->set_bool_substitution(0, FALSE);
      if ($substitution->course_list_substitutions->get_first()->temp_old_course_id > 0) { // Restore the course_id *if* it was set to 0 on purpose. (happens
        // when there is a sub of a transfer to kill the transfer eqv.  This will
        // restore it).
        $substitution->course_list_substitutions->get_first()->course_id = $substitution->course_list_substitutions->get_first()->temp_old_course_id;
      }
    }



  }



}