コード例 #1
0
ファイル: lib_movies.php プロジェクト: CPNV-ES/movies
/**
 *  recoverInfoMovies
 *
 *  function
 *
 * 	@param array        $var   Contains all movie found script jonathan with id table files
 *
 *  @return             no return data
 */
function recoverInfoMovies($var)
{
    $id_movie_tmbd = array();
    $key = KEY_TMDB;
    $lang = LANG_TMDB;
    $tmdb = new tmdb($key, $lang);
    $pdo = connectDB();
    foreach ($var as $data) {
        //research id movie in thMovieDB
        $id_movies_tmdb = Search_id_movie($data[FILES_TITLE], $tmdb);
        // if id movie is not found, next movie.
        if ($id_movies_tmdb === false) {
            continue;
        }
        // research full info movie in TheMovieDB
        $Full_Info = Search_info_movie($id_movies_tmdb, $tmdb);
        // if info movie is not found, next movie.
        if ($Full_Info === false) {
            continue;
        }
        //if movie exist in db, it not insert
        if (checkMovie($Full_Info, $pdo) === false) {
            // it insert information in db (Title, Year, tagline, Description, poster)
            $id_movie_db = inserMovies($Full_Info, $pdo);
            // if exist, insert data in db
            foreach ($Full_Info["genres"] as $row) {
                if (($id_genres = getidGenre(get_object_vars($row)["name"], $pdo)) === false) {
                    $id_genres = insertGenre(get_object_vars($row)["name"], $pdo);
                }
                insert_genres_Movie($id_genres, $id_movie_db, $pdo);
            }
            foreach ($Full_Info["production_countries"] as $row) {
                if (($id_countrie = getidCountries(get_object_vars($row)["name"], $pdo)) === false) {
                    $id_countrie = Insert_Countries(get_object_vars($row)["name"], $pdo);
                }
                insert_countrie_movie($id_countrie, $id_movie_db, $pdo);
            }
            foreach ($Full_Info["production_companies"] as $row) {
                if (($id_studios = getidstudios(get_object_vars($row)["name"], $pdo)) === false) {
                    $id_studios = Insert_studios(get_object_vars($row)["name"], $pdo);
                }
                insert_studios_Movie($id_studios, $id_movie_db, $pdo);
            }
            // insert ten actor in db
            $nbcast = 10;
            if (count(get_object_vars($Full_Info["casts"])["cast"]) < 10) {
                $nbcast = count(get_object_vars($Full_Info["casts"])["cast"]);
            }
            $id_role = getrollebyid("Actor", $pdo);
            for ($i = 0; $i < $nbcast; $i++) {
                if (($idPeople = getidPeople(get_object_vars(get_object_vars($Full_Info["casts"])["cast"][$i])["name"], $pdo)) === false) {
                    $idPeople = insert_people(get_object_vars(get_object_vars($Full_Info["casts"])["cast"][$i])["name"], $pdo);
                }
                insert_people_role_movies($idPeople, $id_role, $id_movie_db, $pdo);
            }
            // insert crew, director, writer and producer.
            foreach (get_object_vars($Full_Info["casts"])["crew"] as $crew) {
                $crew = get_object_vars($crew);
                switch ($crew["job"]) {
                    case 'Producer':
                    case 'Director':
                    case 'Writer':
                        if ($id_crew = getidPeople($crew["name"], $pdo) === false) {
                            $id_crew = insert_people($crew["name"], $pdo);
                        }
                        $id_role = getrollebyid($crew["job"], $pdo);
                        insert_people_role_movies($id_crew, $id_role, $id_movie_db, $pdo);
                        break;
                }
            }
        } else {
            $id_movie_db = getIdMovie($Full_Info["original_title"], $pdo);
        }
        // update table files
        Update_files($id_movie_db, $data[FILES_ID], $pdo);
    }
    return;
}
コード例 #2
0
ファイル: lib_final.php プロジェクト: CPNV-ES/movies
function Word($var)
{
    $pdo = connectdb();
    foreach ($var as $data) {
        // Recherche de l'id du film dans theMovieDB
        $id_movies_tmdb = Search_id_movie($data[FILES_TITLE]);
        // Si l'id du film n'est pas trouvé dans theMovieDb alor on continue
        if ($id_movies_tmdb === false) {
            //log("[Not Found] Movie is not found in tmbd, ".$data["FILES_TITLE"]);
            continue;
        }
        // on va rechercher toutes les informations dans TheMovieDb
        $Full_Info = Search_info_movie($id_movies_tmdb);
        if (verif_movie($Full_Info, $pdo) === false) {
            // On insert les information du films (Title, Year, tagline, Description, poster)
            $id_movie_db = Insert_Movie($Full_Info, $pdo);
            // la boucle suivant insert si il n'existe pas dans la bdd, le genre et le lie avec l'id du film
            foreach ($Full_Info["genres"] as $row) {
                if (($id_genres = getidGenre(get_object_vars($row)["name"], $pdo)) === false) {
                    $id_genres = Insert_Genre(get_object_vars($row)["name"], $pdo);
                }
                insert_genres_Movie($id_genres, $id_movie_db, $pdo);
            }
            // meme boucle que ci-dessus mais pour les countries
            foreach ($Full_Info["production_countries"] as $row) {
                if (($id_countrie = getidCountries(get_object_vars($row)["name"], $pdo)) === false) {
                    $id_countrie = Insert_Countries(get_object_vars($row)["name"], $pdo);
                }
                insert_countrie_movie($id_countrie, $id_movie_db, $pdo);
            }
            foreach ($Full_Info["production_companies"] as $row) {
                if (($id_studios = getidstudios(get_object_vars($row)["name"], $pdo)) === false) {
                    $id_studios = Insert_studios(get_object_vars($row)["name"], $pdo);
                }
                insert_studios_Movie($id_studios, $id_movie_db, $pdo);
            }
            // ci dessous je vais inserer les acteurs du film, mais pas tous, je prend que les 10 principaux
            $id_role = getrollebyid("Acteur", $pdo);
            for ($i = 0; $i < 10; $i++) {
                if (($idPeople = getidPeople(get_object_vars(get_object_vars($Full_Info["casts"])["cast"][$i])["name"], $pdo)) === false) {
                    $idPeople = insert_people(get_object_vars(get_object_vars($Full_Info["casts"])["cast"][$i])["name"], $pdo);
                }
                insert_people_role_movies($idPeople, $id_role, $id_movie_db, $pdo);
            }
            // insert crew, director, writer and producer.
            foreach (get_object_vars($Full_Info["casts"])["crew"] as $data) {
                $data = get_object_vars($data);
                switch ($data["job"]) {
                    case 'Producer':
                    case 'Director':
                    case 'Writer':
                        if ($id_crew = getidPeople($data["name"], $pdo) === false) {
                            $id_crew = insert_people($data["name"], $pdo);
                        }
                        $id_role = getrollebyid($data["job"], $pdo);
                        insert_people_role_movies($id_crew, $id_role, $id_movie_db, $pdo);
                        break;
                }
            }
        }
        // On update dans la table files le fkmovie pour correspondre à ce que jonathan à inseré
        if (isset($data[FILES_ID]) && isset($id_movie_db)) {
            Update_files($id_movie_db, $data[FILES_ID], $pdo);
        }
        //var_dump($id_movie_db);
        //var_dump($Full_Info);
        print_r($Full_Info);
    }
    return;
}