Пример #1
0
 public function loadFromCsv($file)
 {
     while ($movieText = fgetcsv($file)) {
         //print_r($movie);
         //var_dump($streamName);
         $streamName = trim($movieText[1]);
         if (!isset($this->dates[$movieText[0]])) {
             $this->dates[$movieText[0]] = 1;
             //	echo $this->dates[$movieText[0]];
         } else {
             $this->dates[$movieText[0]]++;
         }
         $flixUrl = "http://www.omdbapi.com/?r=json&t=" . urlencode($streamName);
         //var_dump($flixUrl);
         $ch = curl_init();
         $timeout = 5;
         curl_setopt($ch, CURLOPT_URL, $flixUrl);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         $data = curl_exec($ch);
         curl_close($ch);
         $flixData = json_decode($data, true);
         $movie = new Movie();
         if (isset($flixData['Title'])) {
             $movie->setTitle($flixData['Title']);
         } else {
             $movie->setTitle($streamName);
         }
         if (isset($flixData['Runtime'])) {
             $movie->setDuration($flixData['Runtime']);
         } else {
             $movie->setDuration(null);
         }
         if (isset($flixData['imdbRating'])) {
             $movie->setimdbRating($flixData['imdbRating']);
         } else {
             $movie->setimdbRating(null);
         }
         if (isset($flixData['imdbRating'])) {
             $movie->setimdbRating($flixData['imdbRating']);
         } else {
             $movie->setimdbRating(null);
         }
         if (isset($flixData['Genre'])) {
             $movie->setGeneres(explode(", ", $flixData['Genre']));
         } else {
             $movie->setGeneres(array());
         }
         if (!$this->movieExists($movie)) {
             array_push($this->movies, $movie);
         }
         //}
         //print_r($this->movies);
     }
 }
 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()}";
         }
     }
 }
Пример #3
0
    $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!";
    }
}