Login   Register  
PHP Classes
elePHPant
Icontem

File: new.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Randy Gerritse  >  IMDBSearch  >  new.php  >  Download  
File: new.php
Role: Auxiliary script
Content type: text/plain
Description: is called from list.php if a user has clicked one of the 'multiple records'-options, adds the chosen title to the local db
Class: IMDBSearch
Search the Internet Movie DataBase
Author: By
Last change:
Date: 2003-07-30 10:25
Size: 2,712 bytes
 

Contents

Class file image Download
<?
/*    Retrieves a record and adds it to local db
    called from list.php
    Don't modify without written authorization
    Created by: Randy Gerritse
    Email: randy@randy.nu
    ©2003, All rights reserved.
    ================================================================================ */

require("init.php");

$imdb = new IMDBSearch($_REQUEST["item"]);
if (!isset(
$imdb->imdb_result["multiple"])) {
    
    
$indb $connection->execute($sql->checkID($imdb->imdb_result["id"]));
    if (
count($indb) <= 0) {
        
        
//add the movie
        
$connection->execute($sql->addMovie($imdb->imdb_result["id"],$imdb->imdb_result["title"],$imdb->imdb_result["cover"],$imdb->imdb_result["year"],$imdb->imdb_result["rating"],$imdb->imdb_result["tagline"],$imdb->imdb_result["outline"],$imdb->imdb_result["outlinemore"]));
        
        
//get the movie genres
        
if (count($imdb->imdb_result["genre"]) > 0) {
            foreach (
$imdb->imdb_result["genre"] as $genre) {
                
//create the genre if not existent
                
$genres $connection->execute($sql->getGenre($genre));
                if (
count($genres) <= 0) {
                    
$genreid $connection->execute($sql->createGenre(strtolower($genre)));
                } else {
                    
$gen current($genres);
                    
$genreid $gen["id"];
                }
                
//add the movie to the genre
                
$connection->execute($sql->addMovieToGenre($imdb->imdb_result["id"],$genreid));
            }
        }
        
        
//get the movie cast
        
if (count($imdb->imdb_result["cast"]) > 0) {
            foreach (
$imdb->imdb_result["cast"] as $actor) {
                
//create the actor if not existent
                
$actors $connection->execute($sql->getActor($actor["Name"]));
                if (
count($actors) <= 0) {
                    
$actorid $connection->execute($sql->createActor($actor["Name"]));
                } else {
                    
$act current($actors);
                    
$actorid $act["id"];
                }
                
//add the actor to the movie
                
$connection->execute($sql->addActorToMovie($imdb->imdb_result["id"],$actorid,$actor["Character"]));
            }
        }
        
        
//get the directors
        
if (count($imdb->imdb_result["directors"]) > 0) {
            foreach (
$imdb->imdb_result["directors"] as $director) {
                
//create the director if not existent
                
$directors $connection->execute($sql->getDirector($director["name"]));
                if (
count($directors) <= 0) {
                    
$directorid $connection->execute($sql->createDirector($director["name"]));
                } else {
                    
$dir current($directors);
                    
$directorid $dir["id"];
                }
                
//add the director to the movie
                
$connection->execute($sql->addDirectorToMovie($imdb->imdb_result["id"],$directorid));
            }
        }
        
        echo 
'('.$imdb->imdb_result["rating"].') '.$imdb->imdb_result["title"].' (id = '.$imdb->imdb_result["id"].')<br>';
        
flush();
    } else 
        echo 
"al bestaand";
}
?>