function stats_report_major_students_progress_perform_batch_operation

6.x reports.major-students-progress.inc stats_report_major_students_progress_perform_batch_operation(&$batch, $major, $school_id = 0)

This is the actual batch process function which gets called per run of the batch.

Parameters

unknown_type $batch:

unknown_type $major:

File

modules/stats/reports.major-students-progress.inc, line 145
This file handles the more complicated Major Students Progress csv export report, since it is part of a batch process.

Code

function stats_report_major_students_progress_perform_batch_operation(&$batch, $major, $school_id = 0) {


  // For later, let's get our requirement types from the pie chart config...
  $requirement_types = array();
  // Get the requested piecharts from our config...
  $temp = variable_get_for_school("pie_chart_config", "c ~ Core Requirements\nm ~ Major Requirements\ndegree ~ Degree Progress", $school_id);
  $lines = explode("\n", $temp);
  foreach ($lines as $line) {
    if (trim($line) == "") {
      continue;
    }
    $temp = explode("~", $line);
    $requirement_type = trim($temp [0]);
    $label = trim($temp [1]);
    $requirement_types [$requirement_type] = $label;

  }




  ////////////////////////////  FIRST TIME ///////////////////////////////
  // If this is our first time through, let's init our values.
  if (!isset($batch ["results"]["total"])) {
    // Our first time through.  Let's start up.    
    $batch ["results"]["current"] = 0;
    $batch ["results"]["finished"] = FALSE;


    $batch ["csv"] = "CWID, LAST, FIRST, CATALOG, MAJOR, RANK, ";

    // Get the requested piecharts from our config...
    $temp = variable_get_for_school("pie_chart_config", "c ~ Core Requirements\nm ~ Major Requirements\ndegree ~ Degree Progress", $school_id);
    $lines = explode("\n", $temp);
    foreach ($lines as $line) {
      if (trim($line) == "") {
        continue;
      }

      $temp = explode("~", $line);
      $requirement_type = trim($temp [0]);
      $label = trim($temp [1]);
      $requirement_types [$requirement_type] = $label;
      $batch ["csv"] .= "$requirement_type FULFILLED, $requirement_type TOTAL, $requirement_type PERCENT, $requirement_type GPA, ";

    }

    $batch ["csv"] .= "\n";


    // We need the "total" number of students in the selected major.    
    $res = db_query("SELECT COUNT(*) as count FROM students a, users b, student_degrees c
                     WHERE major_code = ?
                     AND is_active = 1
                     AND is_student = 1
                     AND a.cwid = b.cwid
                     AND b.school_id = ?
                     AND a.cwid = c.student_id
                     ORDER BY l_name, f_name 
                     
                     ", array($major, $school_id));
    $cur = db_fetch_array($res);

    $batch ["results"]["total"] = $cur ["count"];

  }
  ////////////////////////////////////////////////////////////////////////

  // Okay, we can now begin the actual batch process.
  $current = $batch ["results"]["current"];
  $total = $batch ["results"]["total"];

  $limit = 7; // how many records to examine for THIS time through the function.
  $c = 0; // count of records.

  $db = get_global_database_handler();


  // Find active students with this major
  $res = db_query("SELECT * FROM students a, users b, student_degrees c
                   WHERE major_code = ?
                   AND is_active = 1
                   AND is_student = 1
                   AND a.cwid = b.cwid
                   AND b.school_id = ?                   
                   AND a.cwid = c.student_id                   
                   ORDER BY l_name, f_name
                   
                   LIMIT $current, $limit", array($major, $school_id));
  while ($cur = db_fetch_array($res)) {

    if ($c >= $limit) {
      break;
    }


    $l_name = $cur ["l_name"];
    $f_name = $cur ["f_name"];

    // Remove possible trouble characters from names.
    $l_name = str_replace(",", "", $l_name);
    $f_name = str_replace(",", "", $f_name);

    $cwid = $cur ["cwid"];
    $major_code = $cur ["major_code"];
    $catalog_year = $cur ["catalog_year"];
    $rank = $cur ["rank_code"];


    $batch ["csv"] .= "$cwid, $l_name, $f_name, $catalog_year, $major_code, $rank, ";


    // Load them up fully and calculate their percentages      
    $student = new Student($cwid, $db);



    $degree_id = $db->get_degree_id($major_code, $catalog_year, FALSE, $school_id);
    if ($degree_id) {
      ///////////////////
      // Fully build up a FlightPath screen in memory, as if the student
      // were looking at this on a web page....
      $degree_plan = new DegreePlan($degree_id, $db, false, $student->array_significant_courses);
      $student->load_student_substitutions();
      $student->load_unassignments();

      $student->list_courses_taken->sort_alphabetical_order();
      $student->list_courses_taken->sort_most_recent_first();

      $fp = new FlightPath($student, $degree_plan);

      $screen = new AdvisingScreen("", $fp);
      $screen->view = "year";

      $fp->assign_courses_to_semesters(); // bare degree plan. not groups.
      $fp->assign_courses_to_groups();

      $screen->build_screen_elements();
      ////////////////

      // Okay, perform the percentage calculations...
      $degree_plan->calculate_progress_hours(FALSE, $requirement_types);
      $degree_plan->calculate_progress_quality_points(FALSE, $requirement_types);

      $use_degree_id = $degree_id;
      if (!isset($degree_plan->gpa_calculations [$use_degree_id])) {
        $use_degree_id = 0;
      }


      foreach ($requirement_types as $requirement_type => $label) {

        // Okay, let's see if this degreeplan even has any data on this requirement type.
        $total_hours = $degree_plan->gpa_calculations [$use_degree_id][$requirement_type]["total_hours"] * 1;
        $fulfilled_hours = $degree_plan->gpa_calculations [$use_degree_id][$requirement_type]["fulfilled_hours"] * 1;
        $qpts_hours = $degree_plan->gpa_calculations [$use_degree_id][$requirement_type]["qpts_hours"] * 1;
        $qpts = $degree_plan->gpa_calculations [$use_degree_id][$requirement_type]["qpts"] * 1;

        $gpa = $percent = 0;

        if ($qpts_hours > 0) {
          $gpa = fp_truncate_decimals($qpts / $qpts_hours, 3);
        }
        if ($total_hours > 0) {
          $percent = round(($fulfilled_hours / $total_hours) * 100);
        }


        $batch ["csv"] .= "$fulfilled_hours, $total_hours, $percent, $gpa, ";

      }



    }



    $batch ["csv"] .= "\n";


    $c++;

  } // while $cur = db_fetch_array  


  // Update our $batch results variables
  $batch ["results"]["current"] = $current + $c;


  if ($batch ["results"]["current"] >= $total) {
    // We are finished!
    $batch ["results"]["finished"] = TRUE;
  }

  // Add the batch_id to the SESSION so we can call it back later on.
  $_SESSION ["stats_report_major_students_progress"][$school_id] = array();
  $_SESSION ["stats_report_major_students_progress"][$school_id]["last_batch_id"] = $batch ["batch_id"];
  $_SESSION ["stats_report_major_students_progress"][$school_id]["last_timestamp"] = time();
  $_SESSION ["stats_report_major_students_progress"][$school_id]["last_major"] = $major;


}