function Student::load_test_scores

6.x Student.php Student::load_test_scores()
1 call to Student::load_test_scores()

File

classes/Student.php, line 261

Class

Student

Code

function load_test_scores() 
 {
  // If the student has any scores (from standardized tests)
  // then load them here.

  $st = null;

  $c = 0;
  $old_row = "";

  $res = db_query("SELECT * FROM student_tests
                     WHERE student_id = ?     
                     AND school_id = ?            
                     ORDER BY date_taken DESC, test_id, category_id ", $this->student_id, $this->school_id);
  while ($cur = db_fetch_array($res)) {

    $c++;

    extract($cur, 3, "db");

    if (!isset($db_position)) {
      $db_position = 0;
    }

    // Get the test's description, if available.

    $res2 = db_query("SELECT * FROM standardized_tests
                        WHERE test_id = ?
                        AND category_id = ?
                        AND school_id = ?
                        ORDER BY position", $db_test_id, $db_category_id, $this->school_id);
    $cur2 = db_fetch_array($res2);
    $db_test_description = trim($cur2 ["test_description"]);
    $db_category_description = trim($cur2 ["category_description"]);

    // Did we find anything in the table?  If not, just use the codes themselves
    if ($db_test_description == "") {
      $db_test_description = t("Test code:") . " " . $db_test_id;
    }
    if ($db_category_description == "") {
      $db_category_description = $db_category_id;
    }

    if (!(($db_date_taken . $db_test_id) == $old_row)) 
     {
      // We are at a new test.  Add the old test to our list.
      if ($st != null) {
        $this->list_standardized_tests->add($st);

      }

      $st = new StandardizedTest();
      $st->test_id = $db_test_id;
      $st->date_taken = $db_date_taken;

      // Is the date unavailable?
      if ($st->date_taken == "" || $st->date_taken == NULL || strstr($st->date_taken, "0000")) {
        $st->bool_date_unavailable = TRUE;
      }

      $st->description = $db_test_description;
      $old_row = $db_date_taken . $db_test_id;

    }

    $st->categories [$db_position . $c]["description"] = $db_category_description;
    $st->categories [$db_position . $c]["category_id"] = $db_category_id;
    $st->categories [$db_position . $c]["score"] = $db_score;

  }

  // Add the last one created.
  if ($st != null) {
    $this->list_standardized_tests->add($st);
  }


}