public static function updateSubmission()
 {
     // Process updating submissions
     $submissions = SubmissionsDB::getSubmissionsBy('submissionId', $_SESSION['arguments']);
     if (empty($submissions)) {
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } elseif ($_SERVER["REQUEST_METHOD"] == "GET") {
         $_SESSION['submissions'] = $submissions;
         SubmissionView::showUpdate();
     } else {
         $parms = $submissions[0]->getParameters();
         $parms['submissionFile'] = array_key_exists('submissionFile', $_POST) ? $_POST['submissionFile'] : "";
         $newSubmission = new Submission($parms);
         $newSubmission->setSubmissionId($submissions[0]->getSubmissionId());
         $submission = SubmissionsDB::updateSubmission($newSubmission);
         if ($submission->getErrorCount() != 0) {
             $_SESSION['submissions'] = array($newSubmission);
             SubmissionView::showUpdate();
         } else {
             HomeView::show();
             header('Location: /' . $_SESSION['base']);
         }
     }
 }
 public function testGetAllSubmissions()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $submissions = SubmissionsDB::getAllSubmissions();
     $this->assertEquals(3, count($submissions), 'It should fetch all of the submissions in the test database');
     foreach ($submissions as $submission) {
         $this->assertTrue(is_a($submission, 'Submission'), 'It should return valid Submission objects');
     }
 }
 public function testGetSubmissionBySubmitterName()
 {
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $submissions = SubmissionsDB::getSubmissionsBy('submitterName', 'Kay');
     $this->assertEquals(count($submissions), 2, 'Kay should have two submissions');
     foreach ($submissions as $submission) {
         $this->assertTrue(is_a($submission, "Submission"), 'The returned values should be Submission objects');
         $this->assertTrue(empty($submission->getErrors()), "The returned submissions should have no errors");
     }
 }
 public static function show()
 {
     $arguments = array_key_exists('arguments', $_SESSION) ? $_SESSION['arguments'] : 0;
     $user = $_SESSION['user'];
     if (!is_null($user)) {
         $_SESSION['user'] = $user;
         $_SESSION['userSubmissions'] = SubmissionsDB::getSubmissionsBy('submitterName', $user->getUserName());
         $_SESSION['userReviews'] = ReviewsDB::getReviewsBy('reviewerName', $user->getUserName());
         UserView::show();
     } else {
         HomeView::show();
     }
 }
 public static function getAllSubmissions()
 {
     // Return all of the submissions as an array of Submission objects
     $query = "SELECT Submissions.assignmentNumber, Submissions.submissionFile, \r\n\t   \t\t            Users.userName FROM Submissions LEFT JOIN Users ON Submissions.userId = Users.userId ";
     $submissions = array();
     try {
         $db = Database::getDB();
         $statement = $db->prepare($query);
         $statement->execute();
         $submissions = SubmissionsDB::getSubmissionsArray($statement->fetchAll(PDO::FETCH_ASSOC));
         $statement->closeCursor();
     } catch (PDOException $e) {
         // Not permanent error handling
         echo "<p>Error getting all submissions " . $e->getMessage() . "</p>";
     }
     return $submissions;
 }
<h1>SubmissionsDB tests</h1>


<?php 
include_once "../models/Database.class.php";
include_once "../models/Messages.class.php";
include_once "../models/Submission.class.php";
include_once "../models/SubmissionsDB.class.php";
include_once "../models/User.class.php";
include_once "../models/UsersDB.class.php";
include_once "./makeDB.php";
?>


<h2>It should get all submissions from a test database</h2>
<?php 
makeDB('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
$submissions = SubmissionsDB::getAllSubmissions();
$submissionCount = count($submissions);
echo "Number of submissions in db is: {$submissionCount} <br>";
foreach ($submissions as $submission) {
    echo "{$submission} <br>";
}
?>
	


</body>
</html>
?>

<h2>It should not allow insertion of a duplicate submission</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
$beforeCount = count(SubmissionsDB::getSubmissionsBy());
$duplicateTest = array("submitterName" => "Kay", "assignmentNumber" => "1", "submissionFile" => "V:\test.txt");
$s1 = new Submission($duplicateTest);
$newS1 = SubmissionsDB::addSubmission($s1);
$afterCount = count(SubmissionsDB::getSubmissionsBy());
echo "The inserted submission errors:";
print_r($newS1->getErrors());
echo "Before the database has {$beforeCount}";
echo "Now the database has {$afterCount}";
?>

<h2>It should get a submission by submitter name</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
$submissions = SubmissionsDB::getSubmissionsBy('submitterName', 'Kay');
echo "<br>Number of submissions by Kay is " . count($submissions);
foreach ($submissions as $submission) {
    echo "<br>Submission: {$submission}<br>";
}
?>
</body>
</html>
 public static function updateSubmission($submission)
 {
     // Update a submission
     try {
         $db = Database::getDB();
         if (is_null($submission) || $submission->getErrorCount() > 0) {
             return $submission;
         }
         $checkSubmission = SubmissionsDB::getSubmissionsBy('submissionId', $submission->getSubmissionId());
         if (empty($checkSubmission)) {
             $submission->setError('submissionId', 'SUBMISSION_DOES_NOT_EXIST');
         } elseif ($checkSubmission[0]->getSubmitterName() != $submission->getSubmitterName()) {
             $submission->setError('submitterName', 'SUBMITTER_NAME_DOES_NOT_MATCH');
         } elseif ($checkSubmission[0]->getAssignmentNumber() != $submission->getAssignmentNumber()) {
             $submission->setError('assignmentNumber', 'SUBMISSION_ASSIGNMENT_NUMBERS_DO_NOT_MATCH');
         }
         if ($submission->getErrorCount() > 0) {
             return $submission;
         }
         $query = "UPDATE Submissions SET submissionFile = :submissionFile\r\n\t    \t\t\t                 WHERE submissionId = :submissionId";
         $statement = $db->prepare($query);
         $statement->bindValue(":submissionFile", $submission->getSubmissionFile());
         $statement->bindValue(":submissionId", $submission->getSubmissionId());
         $statement->execute();
         $statement->closeCursor();
     } catch (Exception $e) {
         // Not permanent error handling
         $submission->setError('submissionId', 'SUBMISSION_COULD_NOT_BE_UPDATED');
     }
     return $submission;
 }