Example #1
0
 /**
  * DEPRECATED- this seemed like a good idea at the time, but we're now doing it using CSV lists
  *  Associates students with an exam instance ID by cohort
  * @global type $CFG
  * @param type $id
  * @param type $studentID The ID of the student to associate
  * @return XML-formatted string containing details of the student, or an error if the insert query fails
  */
 public function associateStudentsWithInstanceByCohort($id, $cohortID)
 {
     global $CFG;
     $conn = mysqli_connect($CFG->db, $CFG->dbuser, $CFG->dbuserpass, $CFG->schema) or die('<data><error>failed connecting to database</error><detail>' . mysqli_error($conn) . '</detail></data>');
     // get all students belonging to a cohort
     $query = "SELECT ID FROM students WHERE cohort = {$cohortID};";
     $result = mysqli_query($conn, $query) or die('<data><error>lookup query failed</error><detail>' . mysqli_error($conn) . $query . '</detail></data>');
     while ($row = mysqli_fetch_array($result)) {
         // check to see we're not doubling up
         $checkQuery = "SELECT * FROM student_exam_instance_link WHERE students_ID = {$row['ID']} AND exam_instances_ID = {$id}";
         $checkresult = mysqli_query($conn, $checkQuery) or die('<data><error>check query failed</error><detail>' . mysqli_error($conn) . $checkQuery . '</detail></data>');
         //  print("result count:".mysqli_num_rows($checkresult));
         if (mysqli_num_rows($checkresult) == 0) {
             //   print('inserting...');
             $query = "INSERT INTO {$CFG->schema}.student_exam_instance_link (exam_instances_ID, students_ID) \n            VALUES({$id}, {$row['ID']});";
             $result2 = mysqli_query($conn, $query) or die('<data><error>insert query failed</error><detail>' . mysqli_error($conn) . $query . '</detail></data>');
         }
     }
     if (mysqli_insert_id($conn) > 0) {
         // return all just added
         $enumlib = new EnumLib();
         return $enumlib->getStudentsByCohortIDAssociatedWithInstance($id, $cohortID);
     } else {
         return '<data><error>associateStudentsWithInstanceByCohort operation failed</error><detail>' . mysqli_error($conn) . '</detail></data>';
     }
     // return "<data><id>$returnStr</id></data>";
 }