예제 #1
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'));
 }
예제 #2
0
 /**
  * List JSON listing of all Movies.
  *
  * @return Response
  */
 public function all()
 {
     //
     $movies = Movies::all();
     return response()->json(['data' => $movies], 200);
 }
예제 #3
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");
 }