function DatabaseHandler::get_student_majors_from_db

7.x DatabaseHandler.php DatabaseHandler::get_student_majors_from_db($student_cwid, $bool_return_as_full_record = FALSE, $perform_join_with_degrees = TRUE, $bool_skip_directives = TRUE, $bool_check_for_allow_dynamic = TRUE)
6.x DatabaseHandler.php DatabaseHandler::get_student_majors_from_db($student_cwid, $bool_return_as_full_record = FALSE, $perform_join_with_degrees = TRUE, $bool_skip_directives = TRUE, $bool_check_for_allow_dynamic = TRUE)

Returns an array (or CSV string) of major_codes from the student_degrees table for this student.

If bool_check_for_allow_dynaic is TRUE, it means that, if the student has more than one degree returned, we will make sure that they all have allow_dynamic = TRUE. If they do not, we will use the first is_editable degree we find ONLY. We do this because that means the student had a situation like we see in FlightPath 4x, where only one degree may be selected at a time, and the is_editiable degree is the track/option they selected.

File

classes/DatabaseHandler.php, line 1389

Class

DatabaseHandler

Code

function get_student_majors_from_db($student_cwid, $bool_return_as_full_record = FALSE, $perform_join_with_degrees = TRUE, $bool_skip_directives = TRUE, $bool_check_for_allow_dynamic = TRUE) {
  // Looks in the student_degrees table and returns an array of major codes.
  $rtn = array();

  // Keep track of degrees which have is_editable set to 1.
  $is_editable_true = array();
  $is_editable_false = array();

  if ($perform_join_with_degrees) {

    $catalog_year = $this->get_student_catalog_year($student_cwid);

    $res = $this->db_query("SELECT * FROM student_degrees a, degrees b
                              WHERE student_id = ? 
                              AND a.major_code = b.major_code
                              AND b.catalog_year = ?                                                            
                              ORDER BY b.advising_weight, b.major_code
                              ", $student_cwid, $catalog_year);
  }
  else {
    // No need to join with degrees table...
    $res = $this->db_query("SELECT * FROM student_degrees a
                              WHERE student_id = ?                              
                              ORDER BY major_code
                              ", $student_cwid);
  }
  while ($cur = $this->db_fetch_array($res)) {

    if ($bool_skip_directives && strstr($cur ["major_code"], "~")) {
      continue;
    }

    if ($bool_return_as_full_record) {
      $rtn [$cur ["major_code"]] = $cur;

    }
    else {
      $rtn [$cur ["major_code"]] = $cur ["major_code"];
    }

    if ($bool_check_for_allow_dynamic && !isset($cur ['allow_dynamic']) && isset($cur ['degree_id'])) {
      $cur ['allow_dynamic'] = $this->get_degree_allow_dynamic($cur ['degree_id']);
    }


    if ($cur ['is_editable'] == 1) {
      $is_editable_true [] = $cur;
    }
    else {
      $is_editable_false [] = $cur;
    }

  }

  if ($bool_check_for_allow_dynamic && count($rtn) > 1) {

    // This means that we have more than one degree selected, and we have been asked to make sure that if any of the degrees have allow_dynamic = 0, then we will
    // only select the is_editable degree.

    foreach ($is_editable_false as $major) {
      if (isset($major ['allow_dynamic']) && $major ['allow_dynamic'] == 0) {
        // Meaning, allow dynamic is NOT allowed.  So, if we have ANYTHING in is_editable_true, then use THAT, else, use THIS.
        if (count($is_editable_true) > 0) {
          // Only get out 1 major.
          $x = $is_editable_true [0];
          $new_rtn [$x ['major_code']] = $rtn [$x ['major_code']];
          $rtn = $new_rtn;
        }
        else {
          $x = $major;
          $new_rtn [$x ['major_code']] = $rtn [$x ['major_code']];
          $rtn = $new_rtn;
        }
      }
    }

  } // if bool_check_for_allow_dynamic




  return $rtn;
}