/**
  * This function checks get_table_rows().  It validates that the correct information was pulled
  * from the DB and also that it's formatting (in an array) is correct so that it can be JSON
  * encoded and sent to javascript.
  *
  */
 public function test_get_table_rows()
 {
     $this->setUser($this->friend);
     $folder = 'inbox';
     $tablerows = array();
     $fr = new folder_records($folder, $this->testcourseid);
     $fr->get_table_rows($tablerows, 0);
     $indices = array();
     $mailids = array($this->mailids[self::GENERICMAILID], $this->mailids[self::DELETEMAILID], $this->mailids[self::PARENTMAILID]);
     $this->find_indices($tablerows, $mailids, $indices);
     // Testing 3 of 4 (all unread -> 0).
     $this->check_message($tablerows[$indices[0]], $mailids[0], "Craig Jamieson", 'Test Mail 1', 0, $folder);
     $this->check_message($tablerows[$indices[1]], $mailids[1], "Craig Jamieson", 'Delete Mail 1', 0, $folder);
     $this->check_message($tablerows[$indices[2]], $mailids[2], "Craig Jamieson", 'Threaded Message Test', 0, $folder);
     $this->setUser($this->craig);
     $folder = 'sent';
     $tablerows = array();
     $fr = new folder_records($folder, $this->testcourseid);
     $fr->get_table_rows($tablerows, 0);
     $indices = array();
     $mailids = array($this->mailids[self::DELETEMAILID], $this->mailids[self::PARENTMAILID], $this->mailids[self::LASTMAILID]);
     $this->find_indices($tablerows, $mailids, $indices);
     // Testing 3 of 4 again: status field is unused, set to 1 in all cases.
     $this->check_message($tablerows[$indices[0]], $mailids[0], "Craig's Friend", 'Delete Mail 1', 1, $folder);
     $this->check_message($tablerows[$indices[1]], $mailids[1], "Craig's Friend", 'Threaded Message Test', 1, $folder);
     $this->check_message($tablerows[$indices[2]], $mailids[2], "Craig's Friend", 'Threaded Message Test', 1, $folder);
 }
 /**
  * This is function grabs the records from a particular folder, encodes them in json, and writes
  * the records to the page.
  *
  */
 private function get_folder($folder)
 {
     global $USER;
     $fr = new folder_records($folder, $this->courseid);
     $tablerows = array();
     // Changed call here because call-time pass-by-reference is deprecated in php 5.4.
     $fr->get_table_rows($tablerows, 0);
     $table = array('rows' => $tablerows);
     echo json_encode($table);
 }