Exemple #1
0
 public function filterMovies()
 {
     $data = Request::all();
     $search_string = trim($data['filter-movie-text']);
     $type = trim($data['filter-movie-by']);
     if ($search_string != "") {
         $query = Movies::select('movies.*');
         switch ($type) {
             case "all":
             default:
                 $query->where('name', 'LIKE', '%' . $search_string . '%');
                 break;
             case "year":
                 $query->where('released', $search_string);
                 break;
         }
         $query->orderBy('sort_name');
         $movies = $query->get();
         $people = Persons::where(DB::raw("CONCAT(`forename`, ' ', `surname`)"), 'LIKE', '%' . $search_string . '%')->orderBy('forename')->get();
         $tags = Movies::where('keywords.word', 'LIKE', '%' . $search_string . '%')->join('tags', 'movies.movie_id', '=', 'tags.movie_id')->join('keywords', 'keywords.keyword_id', '=', 'tags.keyword_id')->orderBy('sort_name')->get();
         $user = $this->isAdmin;
         $quote = count($movies) ? "" : $this->getRandomQuote();
         return view('filter.results', compact('movies', 'people', 'tags', 'quote', 'user'));
     }
 }
 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";
         }
     }
 }
 /**
  *
  * Check the person does not already exist in the database
  * @param string $forename
  * @param string $surname
  * @return Response
  *
  */
 private function checkExistingPeople($forename, $surname)
 {
     $query = Persons::where('forename', $forename);
     if ($surname != "") {
         $query->where('surname', $surname);
     }
     $existing = $query->first();
     if (count($existing) == 0) {
         return false;
     } else {
         return $existing->person_id;
     }
 }
Exemple #4
0
 public function filterMovies($request)
 {
     $data = $request->all();
     $search_string = trim($data['val']);
     if ($search_string != "") {
         $movies = Movies::select('movies.*')->where('name', 'LIKE', '%' . $search_string . '%')->orderBy('sort_name')->get();
         $people = Persons::where(DB::raw("CONCAT(`forename`, ' ', `surname`)"), 'LIKE', '%' . $search_string . '%')->orderBy('forename')->get();
         $user = $this->isAdmin;
         $quote = count($movies) ? "" : $this->getRandomQuote();
         return view('ajax.movie_filter', compact('movies', 'people', 'quote', 'user'));
     }
 }
Exemple #5
0
 public function getDirectors()
 {
     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) {
                 $hasDirector = false;
                 foreach ($movie->crew as $person) {
                     if ($person->pivot->position == "Director") {
                         $hasDirector = true;
                     }
                 }
                 if (!$hasDirector) {
                     $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];
                         if ($imdb->directors) {
                             $director_name = $imdb->directors[0]->name;
                             $imdb_id = $imdb->directors[0]->nameId;
                             $person = Persons::where(DB::raw("CONCAT(`forename`, ' ', `surname`)"), htmlentities($director_name, ENT_QUOTES))->first();
                             if (!$person) {
                                 $client = new \GuzzleHttp\Client();
                                 $url = 'http://api.myapifilms.com/imdb/idIMDB?idName=' . $imdb_id . '&token=' . $my_token . '&format=json&language=en-us&bornDied=1';
                                 $imdb_response = $client->get($url);
                                 $imdb_body = $imdb_response->getBody();
                                 $imdb_api = json_decode($imdb_body);
                                 if (count($imdb_api->data->names)) {
                                     $data = [];
                                     $imdb = $imdb_api->data->names[0];
                                     $names = array_values(array_filter(explode(' ', $imdb->name)));
                                     $data['surname'] = count($names) ? $this->formatName(array_pop($names)) : "";
                                     $data['forename'] = count($names) ? $this->formatName(implode(" ", $names)) : "";
                                     $deceased = isset($imdb->died) ? $imdb->died . "<br/><br/>" : "";
                                     $data['bio'] = isset($imdb->bio) ? strlen($imdb->bio) > 1000 ? $deceased . substr($imdb->bio, 0, 1000) . " ...." : $deceased . $imdb->bio : "";
                                     $content = file_get_contents($imdb->urlPhoto);
                                     $image_name = $this->createImageName($data['forename'] . " " . $data['surname']);
                                     $fp = fopen('images/people/' . $image_name, "w");
                                     fwrite($fp, $content);
                                     fclose($fp);
                                     $img = Image::make('images/people/' . $image_name);
                                     $img->resize(300, 450);
                                     $img->save('images/people/' . $image_name);
                                     $data['image'] = $image_name;
                                     if (isset($imdb->dateOfBirth)) {
                                         $born = new DateTime(preg_replace("/[^a-zA-Z0-9]/", ' ', $imdb->dateOfBirth));
                                         $data['birthday'] = $born->format('Y-m-d');
                                     }
                                     $update = Persons::create($data);
                                     $inserted_id = $update->person_id;
                                     $movie->crew()->attach($inserted_id, array('position' => 'Director'));
                                     echo "NEW (" . $movie->movie_id . ") " . $movie->name . " : " . $director_name . " added<br/>";
                                 }
                             } else {
                                 $movie->crew()->attach($person->person_id, array('position' => 'Director'));
                                 echo "ADD (" . $movie->movie_id . ") " . $movie->name . " : " . $director_name . " added to movie<br/>";
                             }
                         } else {
                             echo "N/A (" . $movie->movie_id . ") " . $movie->name . " : no directors found<br/>";
                         }
                     } else {
                         echo "N/A (" . $movie->movie_id . ") " . $movie->name . " : no data found<br/>";
                     }
                 } else {
                     echo "EXT (" . $movie->movie_id . ") " . $movie->name . " : director exists<br/>";
                 }
             } else {
                 echo "nID (" . $movie->movie_id . ") " . $movie->name . " : no imdb id<br/>";
             }
             flush();
             ob_flush();
         }
     }
     echo "<br/><br/>Finished " . date("H:i:s");
 }