public static function run() { $action = array_key_exists('action', $_SESSION) ? $_SESSION['action'] : ""; $arguments = $_SESSION['arguments']; switch ($action) { case "new": if ($_SERVER["REQUEST_METHOD"] == "POST") { $reviewData = new ReviewData($_POST); if ($reviewData->getErrorCount() == 0) { $dbReviewData = ReviewDB::addReview($reviewData); HomeView::show(); } else { ReviewView::show($reviewData); } } else { ReviewView::show(null); } break; case "show": $users = UsersDB::getUsersBy('userId', $arguments); $_SESSION['user'] = !empty($users) ? $users[0] : null; self::show(); break; case "showall": $_SESSION['reviews'] = ReviewDB::getReviewsBy(); $_SESSION['headertitle'] = "h00dFliX Reviews"; $_SESSION['footertitle'] = "<h3>The footer goes here</h3>"; ReviewsView::showall(); break; case "update": echo "Update"; self::updateUser(); break; default: } }
public static function run() { if ($_SERVER["REQUEST_METHOD"] == "POST") { $reviewData = new ReviewData($_POST); if ($reviewData->getErrorCount() == 0) { HomeView::show(); } else { ReviewView::show($reviewData); } } else { ReviewView::show(null); } }
public static function getReviewsArray($rowSets) { // Return an array of Review objects extracted from $rowSets $reviews = array(); foreach ($rowSets as $reviewRow) { $review = new ReviewData($reviewRow); $review->setReviewId($reviewRow['reviewId']); array_push($reviews, $review); } return $reviews; }
<h2>It should have an error when the reviewed by contains invalid characters</h2> <?php $invalidUser = array("movieTitle" => "Friday", "reviewedBy" => "Thugnifi(en7", "reviewedOn" => "2015-10", "review" => "A+! Great Movie!"); $reviewTest3 = new ReviewData($invalidUser); $test2 = empty($reviewTest3->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test2; echo "The error for movieTitle is: " . $reviewTest3->getError('userName') . "<br>"; echo "The object is: {$reviewTest3}<br>"; ?> <h2>It should have an error when the reviewed on is empty</h2> <?php $invalidUser = array("movieTitle" => "Friday", "reviewedBy" => "Thugnificent", "reviewedOn" => "", "review" => "A+! Great Movie!"); $reviewTest4 = new ReviewData($invalidUser); $test2 = empty($reviewTest4->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test2; echo "The error for movieTitle is: " . $reviewTest4->getError('reviewedOn') . "<br>"; echo "The object is: {$reviewTest4}<br>"; ?> <h2>It should have an error when the review is empty</h2> <?php $invalidUser = array("movieTitle" => "Friday", "reviewedBy" => "Thugnificent", "reviewedOn" => "2015-10", "review" => ""); $reviewTest5 = new ReviewData($invalidUser); $test2 = empty($reviewTest5->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test2; echo "The error for movieTitle is: " . $reviewTest5->getError('review') . "<br>"; echo "The object is: {$reviewTest5}<br>"; ?> </body> </html>