protected function buildDomainObject($row) { $movie = new Movie(); $movie->setId($row['mov_id']); $movie->setTitle($row['mov_title']); $movie->setDecriptionShort($row['mov_description_short']); $movie->setDecriptionLong($row['mov_description_long']); $movie->setDirector($row['mov_director']); $movie->setYear($row['mov_year']); $movie->setImage($row['mov_image']); if (array_key_exists('id_categorie', $row)) { $categoryID = $row['cat_id']; $category = $this->categoryDAO->find($categoryId); $movie->setCategory($category); } return $movie; }
public function db_add_movie() { if (isset($_POST['submit'])) { try { $db = new Database(); $movie = new Movie($db); $movie->setTitle(htmlspecialchars($_POST['movie-title'])); $movie->setDirector(htmlspecialchars($_POST['movie-director'])); $movie->setSynopsis(htmlspecialchars($_POST['movie-synopsis'])); $movie->setYear(htmlspecialchars($_POST['movie-year'])); $movie->setCountry(htmlspecialchars($_POST['movie-country'])); $movie->setDuration(htmlspecialchars($_POST['movie-duration'])); $movie->add_movie(); } catch (Exception $e) { echo "Error: {$e->getMessage()}"; } } }
$movie = new Movie($db); $selected = substr($_POST['update_title'], 1, -1); $movie->setId($selected); $rows = $movie->find_movie_by_id(); if (is_array($rows)) { try { $view = new View(); $view->view_selected_movie($rows); } catch (Exception $e) { echo "Error: {$e->getMessage()}"; } } else { throw new Exception("Error: Please contact the tech guys."); } $db = NULL; } if (isset($_POST['update_movie'])) { $db = new Database(); $movie = new Movie($db); $selected = $_POST['movie_id']; $movie->setId($selected); $movie->setTitle($_POST['movie-title']); $movie->setDirector($_POST['movie-director']); $movie->setSynopsis($_POST['movie-synopsis']); $movie->setYear($_POST['movie-year']); $movie->setCountry($_POST['movie-country']); $movie->setDuration($_POST['movie-duration']); if ($movie->update_movie()) { echo "It works!"; } }
// match html from imdb foreach (match_all('/<tr class="(even|odd)">(.*?)<\\/tr>/ms', $html, 2) as $m) { $rank++; $id = match('/<td class="titleColumn">.*?<a href="\\/title\\/(tt\\d+)\\/.*?"/msi', $m, 1); $title = match('/<td class="titleColumn">.*?<a.*?>(.*?)<\\/a>/msi', $m, 1); $year = match('/<td class="titleColumn">.*?<span.*?>\\((.*?)\\)<\\/span>/msi', $m, 1); $rating = match('/<td class="ratingColumn">.*?<strong.*?>(.*?)<\\/strong>/msi', $m, 1); $poster = match('/<td class="posterColumn">.*?<img src="(.*?)"/msi', $m, 1); $votesURL = "http://www.imdb.com/title/" . $id . "/"; $votes = getvotes($votesURL); // create each movie object and set the variables $movie = new Movie(); $movie->setId($id); $movie->setRank($rank); $movie->setTitle($title); $movie->setYear($year); $movie->setRating($rating); $movie->setVotes($votes); // insert $movie objects into an array array_push($top10Movies, $movie); // stop at 10 if ($rank == 10) { break; } } $date = $db->select("movies", "date_added"); // insert into database using medoo if it does not exist foreach ($top10Movies as $movie) { // check database for matching date, if same day update, else insert if (in_array($today, $date)) { $db->update("movies", ["imdb_id" => $movie->getId(), "rank" => $movie->getRank(), "rating" => $movie->getRating(), "title" => $movie->getTitle(), "year" => $movie->getYear(), "number_of_votes" => $movie->getVotes(), "date_added" => $today], ["date_added" => $today, "rank" => $movie->getRank()]);