Пример #1
0
 /**
  *
  * Check if name exists, if not add to the database
  * @param string $name
  * @return Response
  *
  */
 private function createNewStudio($name)
 {
     $existing = Studios::where('studio_name', $name)->first();
     if (count($existing) == 0) {
         $values = ['studio_name' => $name];
         $update = Studios::create($values);
         return $update->studio_id;
     } else {
         return $existing->studio_id;
     }
 }
Пример #2
0
 public function index()
 {
     $studios = Studios::all();
     $user = $this->checkUserDetails();
     return view('admin.studios', compact('studios', 'user'));
 }
Пример #3
0
 /**
  *
  * Return search result from API call
  * @return Response
  *
  */
 public function searchForMovie()
 {
     $data = Request::all();
     $title = $data['title'];
     if ($title) {
         $rating = isset($data['rating']) ? $data['rating'] : null;
         $year = isset($data['year']) ? $data['year'] : null;
         $client = new \GuzzleHttp\Client();
         $my_token = env('IMDB_KEY');
         $app = app();
         $values = $app->make('stdClass');
         $type = substr($title, 0, 2) === 'tt' ? 'idIMDB' : 'title';
         $url = 'http://api.myapifilms.com/imdb/idIMDB?' . $type . '=' . $title . '&token=' . $my_token;
         if ($year != null && $year != "null") {
             $url .= '&year=' . $year . '&limit=2';
         }
         $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];
             $values->name = trim($imdb->title);
             $values->imdb_id = trim($imdb->idIMDB);
             $values->bio = trim($imdb->plot);
             $values->purchased = "01-01-2015";
             $values->rating = $rating;
             $values->released = trim($imdb->year);
             $values->image = $imdb->urlPoster;
             $tmdb_response = $client->get('http://api.myapifilms.com/tmdb/movieInfoImdb?idIMDB=' . $imdb->idIMDB . '&token=' . $my_token . '&format=json&language=en&casts=1&releases=1');
             $tmdb_body = $tmdb_response->getBody();
             $tmdb_api = json_decode($tmdb_body);
             if (!isset($tmdb_api->error->message)) {
                 $tmdb = $tmdb_api->data;
                 $values->running_time = $tmdb->runtime;
                 $certification = '';
                 foreach ($tmdb->releases as $rel) {
                     if ($rel->iso_3166_1 == "GB") {
                         $certification = $rel->certification;
                     }
                 }
                 switch ($certification) {
                     case "U":
                         $certificate_id = 2;
                         break;
                     case "PG":
                         $certificate_id = 3;
                         break;
                     case "12":
                         $certificate_id = 4;
                         break;
                     case "12A":
                         $certificate_id = 5;
                         break;
                     case "15":
                         $certificate_id = 6;
                         break;
                     case "18":
                         $certificate_id = 7;
                         break;
                     default:
                         $certificate_id = '';
                 }
                 $values->certificate_id = $certificate_id;
                 $app = app();
                 $infos = $app->make('stdClass');
                 $studio_info = null;
                 if (count($tmdb->production_companies)) {
                     foreach ($tmdb->production_companies as $studio) {
                         $studio_names[] = $studio->name;
                     }
                     $studio_info .= implode(", ", $studio_names);
                 }
                 $infos->studio_id = $studio_info;
             }
         } else {
             $message = "Movie not found on IMDb";
         }
     } else {
         $message = "Enter a title to search for";
     }
     $app = app();
     $options = $app->make('stdClass');
     $options->certificates = Certificates::lists('title', 'certificate_id')->toArray();
     $options->studios = Studios::orderBy('name', 'asc')->lists('name', 'studio_id')->toArray();
     $options->formats = Formats::lists('type', 'format_id')->toArray();
     $fields = Forms::getFormFields('create_movie', true);
     $user = $this->isAdmin;
     return view('movies.create_content', compact('fields', 'options', 'values', 'infos', 'user', 'message'));
 }