public static function updateReview() { // Process updating review $reviews = ReviewsDB::getReviewsBy('reviewId', $_SESSION['arguments']); if (empty($reviews)) { HomeView::show(); header('Location: /' . $_SESSION['base']); } elseif ($_SERVER["REQUEST_METHOD"] == "GET") { $_SESSION['reviews'] = $reviews; ReviewView::showUpdate(); } else { $parms = $reviews[0]->getParameters(); $parms['score'] = array_key_exists('score', $_POST) ? $_POST['score'] : $reviews[0]->getScore(); $parms['review'] = array_key_exists('review', $_POST) ? $_POST['review'] : $reviews[0]->getReview(); $newReview = new Review($parms); $newReview->setReviewId($reviews[0]->getReviewId()); $review = ReviewsDB::updateReview($newReview); if ($review->getErrorCount() != 0) { $_SESSION['reviews'] = array($newReview); ReviewView::showUpdate(); } else { HomeView::show(); header('Location: /' . $_SESSION['base']); } } }
<?php $input = array("reviewerName" => "Kay", "submissionID" => 2, "score" => "5", "review" => "This was a great presentation"); $theReview = new Review($input); echo "The review {$theReview}"; echo "The reviewer name is " . $theReview->getReviewerName() . "<br>"; $_SESSION = array('reviews' => array($theReview), 'base' => "mvcdbcrud"); ReviewView::show(); ?> <h2>It should show display the review form with errors at the top if invalid entry</h2> <?php $input = array("reviewerName" => "Kay#"); $theReview = new Review($input); echo "The review {$theReview}"; echo "The reviewer name is " . $theReview->getReviewerName() . "<br>"; $_SESSION = array('reviews' => array($theReview), 'base' => "mvcdbcrud"); ReviewView::show(); ?> <h2>It should allow updating when a valid review is passed</h2> <?php $validTest = array("reviewerName" => "Kay", "submissionId" => 2, "score" => "5", "review" => "This was a great presentation"); $review = new Review($validTest); $review->setReviewId(1); echo $review; $_SESSION = array('reviews' => array($review), 'base' => "mvcdbcrud"); ReviewView::showUpdate(); ?> </body> </html>