Exemple #1
0
 /**
  *    Deletes row with specified id field.
  */
 public function testdeleteRowById()
 {
     $this->BuildArray();
     // reset variables.
     $classInstance = new tutor\src\classes\GenericAClass();
     $this->assertTrue(isset($classInstance));
     //Can't depend on the new record not supplying own id. Can't use line above.
     $mylocalArray['tG_AssignmentName'] = 'Test';
     $mylocalArray['tG_FormName'] = '537dummy_form.php';
     $results = $classInstance->deleteRowsNamed($mylocalArray['tG_AssignmentName']);
     $this->myArray['tG_AssignmentName'] = 'xyx';
     $result = $classInstance->insertRecord($mylocalArray);
     // get record back and use id.
     $row = $classInstance->getLastDbEntryAsArray();
     $this->assertTrue($row['tG_AssignmentName'] === 'Test');
     $this->assertTrue($row['tG_FormName'] === '537dummy_form.php');
     $results = $classInstance->deleteRowById($row['id']);
     $this->assertTrue($results === 1);
     $result = $classInstance->deleteRowsNamed("Test");
     // clean up.
     // delete the record that was added.
     $r = $classInstance->deleteRowsNamed('Test');
     $this->assertTrue($r === 0);
     $this->BuildArray();
     // reset variables.
 }
 /**
  * Gets the student's next assignment.
  */
 public function getNextLesson()
 {
     // Formerly cAssignment_get_next_lesson.
     date_default_timezone_set('UTC');
     $file = 'logs/ALC_getNextLesson.log';
     $log_file = fopen($file, 'w');
     $v = var_export($_POST, TRUE);
     $string = __LINE__ . '  $_POST = ' . $v . "\n\n";
     fwrite($log_file, $string);
     $_SESSION['tC_ServerTimeStarted'] = microtime(TRUE);
     $_SESSION['from'] = __LINE__ . '  ' . __FILE__;
     $v = var_export($_SESSION, TRUE);
     $string = __LINE__ . '  $_SESSION = ' . $v . "\n\n";
     fwrite($log_file, $string);
     // $_POST variables with the same key overwrite $_SESSION variables.
     $_data = array_merge($_SESSION, $_POST);
     $v = var_export($_data, TRUE);
     $string = __LINE__ . '  $_data = ' . $v . "\n\n";
     fwrite($log_file, $string);
     // This file requires, as input,  a student id.
     // Insure the student identifier is present. Error if not found.
     if (empty($_data['tA_S_ID']) === TRUE) {
         $string = "\n" . __LINE__ . ' $_data["tA_S_ID"] = ' . $_data['tA_S_ID'];
         fwrite($log_file, $string . "\n\n");
         fwrite($log_file, __LINE__ . ' microtime(true) = ' . microtime(TRUE) . "\n");
         $msg = ' cAssignment_get_next_lesson.php    Must have "tA_S_ID" in $_data.';
         $msg = $msg . "\n" . __LINE__ . ' Missing $_data["tA_S_ID"] can not proceed';
         trigger_error($msg, E_USER_ERROR);
     }
     // Now find a lesson.
     $loops = 0;
     // See while ($loops < 6 ); near end.
     do {
         // Now get the student information and set all session variables.
         $_data['tA_S_ID'] = filter_var($_data['tA_S_ID'], FILTER_UNSAFE_RAW);
         $string = "\n" . __LINE__ . ' $_data["tA_S_ID"] = ' . $_data['tA_S_ID'];
         fwrite($log_file, $string . "\n\n");
         $last_lesson_id = $_data['tA_id'];
         $_data['last_gA'] = NULL;
         if (isset($_data['lesson_id']) === TRUE) {
             $last_lesson_id = $_data['lesson_id'];
         } else {
             $last_lesson_id = '';
         }
         // START NEW session with the existing relevant data.
         $v = var_export($_data, TRUE);
         $string = "\n" . __LINE__ . ' $_data = ' . $v . "\n\n";
         fwrite($log_file, $string . "\n");
         $_SESSION = $_data;
         $v = var_export($_SESSION, TRUE);
         $string = "\n" . __LINE__ . ' $_SESSION = ' . $v . "\n\n";
         fwrite($log_file, $string . "\n");
         // Get next assignment to do from the login data.
         // $next_lesson = new tutor\src\classes\AssignmentsClass();
         $next_lesson = new tutor\classes\AssignmentsClass();
         // Return a single lesson as a tAssignments row.
         $lesson = $next_lesson->getNextAssignmentToDo($_data['tA_S_ID'], $last_lesson_id);
         $v = var_export($lesson, TRUE);
         $string = "\n" . __LINE__ . ' $lesson = ' . $v . "\n\n";
         fwrite($log_file, $string . "\n");
         // Assign the lessons variables to the $_SESSION variable.
         // $next_lesson->setSessionVariablesFromLesson($lesson);
         // From the assignment name retrieve the generic assignment and assign
         // its variables  to the $_SESSION variable.
         require_once '../../src/classes/GenericAClass.inc';
         $my_next_ga = new tutor\src\classes\GenericAClass();
         $my_next_ga->setSessionVariablesFromTGAssignmentName($lesson['tG_AssignmentName']);
         fwrite($log_file, __LINE__ . ' microtime(true) = ' . microtime(TRUE) . "\n\n");
         $v = var_export($_SESSION, TRUE);
         $string = "\n" . __LINE__ . ' $_SESSION = ' . $v . "\n\n";
         fwrite($log_file, $string . "\n");
         // We should now have the data to prepare the next lesson.
         fwrite($log_file, __LINE__ . ' microtime(true) = ' . microtime(FALSE) . "\n\n");
         $_SESSION['tG_path_to_lesson'] = trim($_SESSION['tG_path_to_lesson']);
         $_SESSION['tG_FormName'] = trim($_SESSION['tG_FormName']);
         $file = $_SESSION['tG_path_to_lesson'] . $_SESSION['tG_FormName'];
         $string = "\n" . __LINE__ . ' $file = ' . $file;
         fwrite($log_file, $string . "\n");
         // Build the URL to the next lesson.
         $go_next = '';
         $go_next = 'http://jim-fuqua.com/' . $file;
         $string = "\n" . __LINE__ . ' cA go_next = ' . $go_next;
         fwrite($log_file, $string . "\n");
         // Check to see that we really have a file to go to.
         if (file_exists($go_next) === FALSE) {
             $msg = $msg . "\n" . __LINE__ . ' File to go to does not exist.';
             trigger_error($msg, E_USER_ERROR);
         }
         // Following line is the exit from this php file.
         echo $go_next;
         // Preceding line causes a new lesson to load.
         /* Exit the do while. */
         break 2;
         $loops++;
     } while ($loops < 6);
 }
 // Get next assignment to do from the login data.
 $next_lesson = new tutor\src\classes\AssignmentsClass();
 // Return a single lesson as a tAssignments row.
 $lesson = $next_lesson->getNextAssignmentToDo($_data['tA_S_ID'], $last_lesson_id);
 $v = var_export($lesson, TRUE);
 $string = "\n" . __LINE__ . ' $lesson = ' . $v . "\n\n";
 fwrite($log_file, $string . "\n");
 // Assign the lessons variables to the $_SESSION variable.
 // $next_lesson->setSessionVariablesFromLesson($lesson);
 // From the assignment name retrieve the generic assignment and assign
 // its variables  to the $_SESSION variable.
 console . log('116');
 require_once '../src/classes/GenericAClass.inc';
 console . error(message);
 console . log('118');
 $my_next_ga = new tutor\src\classes\GenericAClass();
 $my_next_ga->setSessionVariablesFromTGAssignmentName($lesson['tG_AssignmentName']);
 fwrite($log_file, __LINE__ . ' microtime(TRUE) = ' . microtime(TRUE) . "\n\n");
 $v = var_export($_SESSION, TRUE);
 $string = "\n" . __LINE__ . ' $_SESSION = ' . $v . "\n\n";
 fwrite($log_file, $string . "\n");
 // We should now have the data to prepare the next lesson.
 fwrite($log_file, __LINE__ . ' microtime(TRUE) = ' . microtime(TRUE) . "\n\n");
 $_SESSION['tG_path_to_lesson'] = trim($_SESSION['tG_path_to_lesson']);
 $_SESSION['tG_FormName'] = trim($_SESSION['tG_FormName']);
 $file = $_SESSION['tG_path_to_lesson'] . $_SESSION['tG_FormName'];
 $string = "\n" . __LINE__ . ' $file = ' . $file;
 fwrite($log_file, $string . "\n");
 // Build the URL to the next lesson.
 $go_next = '';
 $go_next = 'http://jim-fuqua.com/' . $file;