public static function run() { // Perform actions related to a user $action = array_key_exists('action', $_SESSION) ? $_SESSION['action'] : ""; $arguments = $_SESSION['arguments']; switch ($action) { case "new": self::newUser(); break; case "show": $users = UsersDB::getUsersBy('userId', $arguments); $_SESSION['user'] = !empty($users) ? $users[0] : null; self::show(); break; case "showall": $_SESSION['movies'] = MoviesDB::getMoviesBy(); $_SESSION['headertitle'] = "h00dFliX Movies"; $_SESSION['footertitle'] = "<h3>The footer goes here</h3>"; ShowMoviesView::showall(); break; case "update": echo "Update"; self::updateUser(); break; default: } }
public static function run() { if ($_SERVER["REQUEST_METHOD"] == "POST") { $movieData = new MovieData($_POST); $dbMovieData = MoviesDB::updateMovie($movieData); if ($movieData->getErrorCount() == 0) { HomeView::show(); } else { RequestMovieView::show($movieData); } } else { RequestMovieView::show(null); } }
public static function updateMovies($movie) { // Update a review try { $_SESSION['movie'] = $movie; $db = Database::getDB(); if (is_null($movie) || $movie->getErrorCount() > 0) { return $movie; } $checkMovie = MoviesDB::getMoviesBy('movieId', $movie->getMovieId()); echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; print_r($checkMovie); if (empty($checkMovie)) { $movie->setError('movieId', 'MOVIE_DOES_NOT_EXIST'); } /*elseif ($checkMovie[0]->getSubmissionId() != $movie->getSubmissionId()) $movie->setError('movieId', 'REVIEW_HAS_WRONG_SUBMISSION_ID'); elseif ($checkMovie[0]->getreviewerName() != $movie->getReviewerName()) $movie->setError('movieId', 'REVIEWER_NAME_DOES_NOT_MATCH');*/ if ($movie->getErrorCount() > 0) { echo "<br>"; } echo "<br>"; echo "<br>"; print_r($movie); return $movie; $query = "UPDATE Movies SET copyAvailable = :copyAvailable\r\n\t \t\t\t WHERE movieTitle = :movieTitle"; $statement = $db->prepare($query); //$statement->bindValue(":movieId", $movie->getMovieId()); $statement->bindValue(":movieTitle", $movie->getMovieTitle()); $statement->bindValue(":copyAvailable", $movie->makeCopyUnavailable()); $statement->execute(); $statement->closeCursor(); } catch (Exception $e) { // Not permanent error handling $movie->setError('movieId', 'MOVIE_COULD_NOT_BE_UPDATED'); } return $movie; }