public static function getColumn($column) { $array = Formats::all(); $result = array(); foreach ($array as $item) { $result += array($item['id'] => $item[$column]); } if (count($result) > 0) { return $result; } else { return array('-1' => 'Chưa có Format nào được tạo. Liên hệ Webmaster'); } }
/** * * Show form to edit existing movie * @param integer $movie_id * @return Response * */ public function edit($movie_id) { if (!$this->isAdmin) { return view('auth.login'); } Session::put('movie_id', $movie_id); $movie = Movies::findorfail($movie_id); $movie->genres; $movie->purchased = date("d-m-Y", strtotime($movie->purchased)); $movie->cover = $this->checkImageExists($movie->image, $movie->sort_name, 'covers'); $movie->cover_count = strlen($movie->cover); $values = json_decode($movie); $movie->genres = DB::table('categories')->where('movie_id', $movie_id)->lists('genre_id'); $movie->tags = DB::table('tags')->where('movie_id', $movie_id)->lists('keyword_id'); $fields = Forms::getFormFields('create_movie', true); $app = app(); $options = $app->make('stdClass'); $options->movies = Movies::orderBy('sort_name')->lists('name', 'movie_id')->toArray(); $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(); $options->actors = Persons::select(DB::raw("CONCAT(forename, ' ', surname) AS full_name"), 'person_id')->whereNotIn('person_id', function ($query) use($movie_id) { $query->select('person_id')->from('cast')->where('movie_id', $movie_id); })->orderBy('forename')->lists('full_name', 'person_id')->all(); $options->crew = Persons::select(DB::raw("CONCAT(forename, ' ', surname) AS full_name"), 'person_id')->orderBy('forename')->lists('full_name', 'person_id')->all(); $options->keywords = Keywords::orderBy('word')->get(); foreach ($options->keywords as $keyword) { $keyword->selected = in_array($keyword->keyword_id, $movie->tags) ? true : false; } $options->genres = Genres::all(); foreach ($options->genres as $genre) { $genre->selected = in_array($genre->genre_id, $movie->genres) ? true : false; } $user = $this->isAdmin; return view('movies.edit', compact('movie', 'fields', 'values', 'options', 'user')); }
/** * * 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')); }