예제 #1
0
 public static function store(array $movie)
 {
     $movie = array_only($movie, array('id', 'title', 'duration', 'originalTitle', 'productionYear', 'genres', 'images', 'rating', 'poster', 'ageRestriction'));
     $movie['original_title'] = $movie['originalTitle'];
     unset($movie['originalTitle']);
     $movie['production_year'] = $movie['productionYear'];
     unset($movie['productionYear']);
     $movie['age_restriction'] = $movie['ageRestriction'];
     unset($movie['ageRestriction']);
     if ($movie['genres'] != null) {
         $genre = [];
         foreach ($movie['genres'] as $key => $value) {
             $genre['genre_id'] = $value['id'];
             $genre['movie_id'] = $movie['id'];
             $mGenre = MoviesGenres::firstOrNew($genre);
             $mGenre->save();
         }
     }
     unset($movie['genres']);
     $images = json_encode($movie['images']);
     $movie['images'] = $images;
     $poster = json_encode($movie['poster']);
     $movie['poster'] = $poster;
     foreach ($movie as $key => $value) {
         if ($value == null) {
             unset($movie[$key]);
         }
     }
     if (Movies::find($movie['id']) == null) {
         $movies = Movies::updateOrCreate($movie);
     }
     //$movies->save();
 }
예제 #2
0
 public function index()
 {
     $app = app();
     $details = $app->make('stdClass');
     // most recent purchases
     $details->most_recent = Movies::getMovieRecords('purchased', 'DESC', 10);
     // top rated movies
     $details->top_rated = Movies::getTopRated();
     foreach ($details->top_rated as $movie) {
         $movie->rating_display = $this->makeRatingStars($movie->rating);
     }
     // get most popular actors
     $details->actors = Persons::getActorCount(24);
     // get most popular directors
     $details->directors = Persons::getDirectorCount(24);
     $details->birthdays = Persons::getTodaysBirthdays();
     foreach ($details->birthdays as $birthday) {
         $birthday->age = $this->calculateAge($birthday->birthday, $birthday->deceased);
     }
     // highlight randomly selected movie
     $random_id = Movies::selectRandomFilm();
     $details->highlight = Movies::findorfail($random_id);
     $details->highlight->cast = $details->highlight->cast->take(3);
     $details->highlight->crew = Crew::where('movie_id', $random_id)->select(DB::raw('GROUP_CONCAT(CONCAT(persons.forename, " ", persons.surname) SEPARATOR ", ") as list'))->join('persons', 'persons.person_id', '=', 'crew.person_id')->groupBy('movie_id')->where('position', 'Director')->take(1)->get();
     $details->highlight->cover_count = strlen($details->highlight->cover);
     $details->highlight->rating_display = $this->makeRatingStars($details->highlight->rating);
     $details->decades = $this->makeDecades();
     $user = $this->isAdmin;
     return view('welcome', compact('details', 'user'));
 }
예제 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $movie = Movies::findOrFail($id);
     $movie->delete();
     \Session::flash('message', 'Movie "' . $movie->Title . '" has been Deleted');
     return redirect()->route('movies.index');
 }
예제 #4
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $cinemas = Cinemas::lists('Name', 'id');
     $movies = Movies::lists('Title', 'id');
     $sessions = SessionTimes::findOrFail($id);
     return view('sessions.edit', compact('sessions'))->with('cinemas', $cinemas)->with('movies', $movies);
 }
예제 #5
0
 /**
  * La méthode très simple qui envoie à la vue d'affichage
  * d'un film toutes les données correspondantes au film.
  * @param $id L'id du film à afficher
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function show($id)
 {
     /*Le tout début est une petite astuce qui permet d'obtenir l'url réel d'une vidéo.
       En effet, dans la base de données, les url des vidéos sont des liens de redirection vers un lien
       (qui j'imagine doit être temporaire) réel de la vidéo
       Si l'on donne l'url de redirection au lecteur vidéo, tout marche bien SAUF si l'on souhaite avancer plus loin dans
       la vidéo (et uniquement sur les vidéos de plus de 10 min environ).
       L'astuce consiste donc à faire une requête via curl sur le lien pour obtenir le vrai url de la vidéo (qui
       lui marche sans soucis) ! */
     $curl = new cURL();
     $movie = Movies::find($id);
     $movie->ogv = $curl->get($movie->ogv)->getHeader('location');
     $topics = $movie->topics;
     // Le if qui suit est une personnalisation des recommandations pour les utilisateurs connectés
     if (Auth::guest()) {
         // SI l'utilisateur est un guest (non enregistré) on lui suggére des films du même auteur aléatoirement
         $suggestions = Movies::where('creator', 'LIKE', $movie->creator)->where('title', 'not like', $movie->title)->orderByRaw('RAND()')->take(5)->get();
     } else {
         $currentId = Auth::id();
         // On ajoute un à count pour chaque topic du film
         foreach ($topics as $topic) {
             $truc = UsersTopics::firstOrCreate(['user_id' => $currentId, 'topic_id' => $topic->id]);
             $truc->where('topic_id', '=', $topic->id)->increment('count', 1);
         }
         // On renvoie une liste de films qui sont parmis les genres préférés
         $maxTopic = User::find($currentId)->topics()->max('count');
         $suggestions = User::find($currentId)->topics()->where('count', $maxTopic)->first()->movies()->where('title', 'not like', $movie->title)->orderByRaw('RAND()')->take(5)->get();
     }
     return view('movies', compact('movie', 'topics', 'suggestions'));
 }
예제 #6
0
 public function run()
 {
     Movies::create(['title' => 'Spy']);
     Movies::create(['title' => 'Mad Max: Fury Road']);
     Movies::create(['title' => 'Woman in Gold']);
     Movies::create(['title' => 'Cloud Sils of Maria']);
     Movies::create(['title' => 'Avengers: Age of Ultron']);
 }
예제 #7
0
 /**
  * Get a JSON Movie instance by the specified title
  *
  * @return Response
  */
 public function get($title)
 {
     //
     $movie = Movies::where('title', $title)->first();
     if (!$movie) {
         return response()->json(['message' => 'Could not find movie with this title', 'code' => 404], 404);
     }
     return response()->json(['data' => $movie], 200);
 }
예제 #8
0
 public function index()
 {
     if (!$this->isAdmin) {
         return redirect()->action('WelcomeController@index');
     }
     $app = app();
     $data = $app->make('stdClass');
     $data->movie_total = Movies::all()->count();
     $data->person_total = Persons::all()->count();
     $data->running_total = Movies::all()->sum('running_time');
     $total_days = floor($data->running_total / 1440) == 1 ? floor($data->running_total / 1440) . " day, " : floor($data->running_total / 1440) . " days, ";
     $total_hours = floor($data->running_total % 1440 / 60) == 1 ? floor($data->running_total % 1440 / 60) . " hour and " : floor($data->running_total % 1440 / 60) . " hours and ";
     $total_minutes = $data->running_total % 1440 % 60 == 1 ? $data->running_total % 1440 % 60 . " minute" : $data->running_total % 1440 % 60 . " minutes";
     $data->watching_time = $total_days . $total_hours . $total_minutes;
     $user = $this->isAdmin;
     return view('admin.index', compact('data', 'user'));
 }
예제 #9
0
 public function filterMovies()
 {
     if (Request::ajax()) {
         $data = Request::all();
         $type = $data['type'];
         $search_string = trim($data['val']);
         if ($search_string != "") {
             $query = Movies::select('movies.*');
             switch ($type) {
                 case "all":
                     $query->where('name', 'LIKE', '%' . $search_string . '%');
                     break;
                 case "studio":
                     $query->where('studios.name', 'LIKE', '%' . $search_string . '%')->join('studios', 'movies.studio_id', '=', 'studios.studio_id');
                     break;
                 case "format":
                     $query->where('formats.type', 'LIKE', '%' . $search_string . '%')->join('formats', 'movies.format_id', '=', 'formats.format_id');
                     break;
                 case "certificate":
                     $query->where('certificate_id', $search_string);
                     break;
                 case "year":
                     $query->where('released', $search_string);
                     break;
                 case "rating":
                     $query->where('rating', $search_string);
                     break;
                 case "tag":
                     $query->where('keywords.word', 'LIKE', '%' . $search_string . '%')->join('tags', 'movies.movie_id', '=', 'tags.movie_id')->join('keywords', 'keywords.keyword_id', '=', 'tags.keyword_id');
                     break;
             }
             $query->orderBy('sort_name');
             $movies = $query->get();
             if ($type == "all") {
                 $people = Persons::where(DB::raw("CONCAT(`forename`, ' ', `surname`)"), 'LIKE', '%' . $search_string . '%')->orderBy('forename')->get();
             } else {
                 $people = [];
             }
             $user = $this->isAdmin;
             $quote = count($movies) ? "" : $this->getRandomQuote();
             return (string) view('ajax.movie_filter', compact('movies', 'people', 'quote', 'user'));
         } else {
             return "blank";
         }
     }
 }
예제 #10
0
파일: Movies.php 프로젝트: briantweed/MyMdb
 public static function selectRandomFilm()
 {
     $movie_ids = Movies::select('movie_id')->where('bio', '!=', '')->has('cast')->get()->toArray();
     $selected_movie = array_rand($movie_ids, 1);
     return $selected_movie;
 }
예제 #11
0
 public function getMovieInfo($id)
 {
     $movie = Movies::where('id', $id)->with('getGenres')->first();
     $genres = $movie->getGenres;
     $movie_genres = [];
     foreach ($genres as $genre) {
         $movie_genres[] = $genre->getGenre->name;
     }
     $poster = json_decode($movie->poster)->name;
     $movie->poster = $poster;
     $images = json_decode($movie->images);
     $movie_images = [];
     foreach ($images as $image) {
         if ($image->name != null) {
             $movie_images[] = $image->name;
         }
     }
     return view()->make('search.movie', ['movie' => $movie, 'genres' => $movie_genres, 'images' => $movie_images]);
 }
예제 #12
0
 /**
  * Cette fonction très simple sert à créer la page "API" qui soutient l'auto complétion
  * de la barre de recherche via Typeahead.js
  * C'est simplement la liste de tous les films encodée en JSON.
  * @return \Illuminate\Http\JsonResponse
  */
 public function query()
 {
     $query = Input::get('movie');
     $res = Movies::where('title', 'LIKE', "%{$query}%")->get();
     return Response::json($res);
 }
예제 #13
0
 public function getGenres()
 {
     echo "Started " . date("H:i:s") . "...... <br/><br/>";
     $movie_count = Movies::all()->count();
     echo $movie_count . " movies<br/>";
     flush();
     ob_flush();
     for ($x = $this->counter; $x < 1000; $x += 10) {
         $movies = Movies::take(10)->offset($x)->get();
         foreach ($movies as $movie) {
             if ($movie->imdb_id) {
                 $client = new \GuzzleHttp\Client();
                 $my_token = env('IMDB_KEY');
                 $url = 'http://api.myapifilms.com/imdb/idIMDB?idIMDB=' . $movie->imdb_id . '&token=' . $my_token . '&format=json&language=en-us';
                 $imdb_response = $client->get($url);
                 $imdb_body = $imdb_response->getBody();
                 $imdb_api = json_decode($imdb_body);
                 if (count($imdb_api->data->movies)) {
                     $imdb = $imdb_api->data->movies[0];
                     echo $movie->name . " : ";
                     if ($imdb->genres) {
                         $data = [];
                         foreach ($imdb->genres as $genre) {
                             $genre_id = Genres::where('type', $genre)->value('genre_id');
                             if ($genre_id) {
                                 $data[] = $genre_id;
                             }
                         }
                         $movie->genres()->sync($data);
                         echo " genres added<br/>";
                     } else {
                         echo "no genres<br/>";
                     }
                     flush();
                     ob_flush();
                 }
             }
         }
     }
     echo "<br/><br/>Finished " . date("H:i:s");
 }
예제 #14
0
 public static function getDynamicValues($type)
 {
     ini_set('memory_limit', '512M');
     ini_set("max_execution_time", "600");
     $file = public_path("upload/Tmp" . $type . ".json.gz");
     if ($type == "Cinemas") {
         $link = "https://api.kinohod.ru/api/data/1/eed7c723-0b90-3fc9-a3bc-bf235e907b35/cinemas.json.gz";
     } elseif ($type == "Seances") {
         $link = "https://api.kinohod.ru/api/data/1/eed7c723-0b90-3fc9-a3bc-bf235e907b35/seances/week.json.gz";
     } else {
         $link = "https://api.kinohod.ru/api/data/1/eed7c723-0b90-3fc9-a3bc-bf235e907b35/running/week.json.gz";
     }
     //dd($link);
     file_put_contents($file, fopen($link, 'r'));
     $fp = gzopen($file, "r");
     if ($fp != false) {
         $contents = gzread($fp, 134217720);
         $jsonArray = json_decode($contents, true);
         foreach ($jsonArray as $key => $value) {
             if ($type == "Cinemas") {
                 Cinemas::store($value);
             } elseif ($type == "Seances") {
                 Seances::store($value);
             } else {
                 Movies::store($value);
             }
         }
         gzclose($fp);
         unlink($file);
     } else {
         echo "404 not found";
     }
 }
예제 #15
0
 /**
  *
  * For duplicate titles, show year as well
  * @param string $name
  * @return Response
  *
  */
 private function checkForDuplicateTitle($name)
 {
     return Movies::where('name', $name)->count() > 0 ? true : false;
 }
예제 #16
0
 /**
  *
  * Check for existing movies with the same title
  * Usually to detech if a movie is a remake
  * If true, release year displayed
  * @param string $text
  * @return Response
  *
  */
 private function checkForMovies($text)
 {
     $output = preg_replace_callback('/\\{{(.*?)}}/', function ($m) {
         $crumbs = explode("(", $m[1]);
         $query_name = trim($crumbs[0]);
         $query = Movies::where('name', $query_name);
         if (isset($crumbs[1])) {
             $query_year = rtrim($crumbs[1], ")");
             if (is_integer($query_year)) {
                 $query->where('released', $query_year);
             }
         }
         $movie = $query->first();
         if ($movie) {
             return "<a href='/movies/" . $movie->movie_id . "'><b>" . $movie->name . " (" . $movie->released . ")</b></a>";
         } else {
             return $m[1];
         }
     }, $text);
     return nl2br($output);
 }
예제 #17
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $randomSuggestions = Movies::orderByRaw('RAND()')->take(5)->get();
     $staffPicks = array(Movies::find(1), Movies::find(89), Movies::find(183), Movies::find(176), Movies::find(72));
     return view('welcome', compact('randomSuggestions', 'staffPicks'));
 }
예제 #18
0
 public function movieRatingCount()
 {
     $movies = [];
     $ratings = [];
     $query = Movies::select('rating', DB::raw('count(*) as count'), 'rating as id')->groupBy('rating')->get();
     foreach ($query as $result) {
         $movies[$result->rating] = $result->count;
     }
     for ($x = 1; $x <= 10; $x++) {
         $rating = [];
         $rating['label'] = $x;
         $rating['y'] = isset($movies[$x]) ? $movies[$x] : 0;
         $ratings[] = $rating;
     }
     return $ratings;
 }