summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Http/Controllers/CinemaController.php233
-rw-r--r--app/Libraries/Helper.php4
2 files changed, 2 insertions, 235 deletions
diff --git a/app/Http/Controllers/CinemaController.php b/app/Http/Controllers/CinemaController.php
deleted file mode 100644
index 75c93aa..0000000
--- a/app/Http/Controllers/CinemaController.php
+++ /dev/null
@@ -1,233 +0,0 @@
-<?php
-
-namespace App\Http\Controllers;
-
-use Illuminate\Support\Facades\DB;
-use Illuminate\Http\Request;
-
-class CinemaController extends Controller
-{
- public function cinema(Request $request)
- {
- $order = $request->input('order', 'ref_count');
- $direction = $request->input('direction', 'desc');
- $validOrders = ['ref_count', 'score', 'num_votes', 'num_accolades', 'start_year'];
- $validDirections = ['asc', 'desc'];
- if (! in_array($order, $validOrders)) {
- $order = 'ref_count';
- }
- if (! in_array($direction, $validDirections)) {
- $direction = 'desc';
- }
-
- $refCounts = DB::connection('cinema')
- ->table('links')
- ->select('links.param', DB::raw('COUNT(*) as ref_count'))
- ->where('links.host', 'www.imdb.com')
- ->where('links.field', 1)
- ->groupBy('links.param');
-
- $movies = DB::connection('cinema')
- ->table('imdb')
- ->select(
- 'imdb.id',
- 'imdb.imdb_id',
- 'imdb.primary_title',
- 'imdb.original_title',
- 'imdb.start_year',
- 'imdb.average_rating',
- 'imdb.num_votes',
- 'imdb.synopsis',
- 'imdb.poster_url',
- 'imdb.title_type',
- 'imdb.runtime_minutes',
- 'imdb.has_people',
- 'imdb.average_rating as score',
- 'imdb.num_accolades',
- DB::raw('COALESCE(ref.ref_count, 0) as ref_count')
- )
- ->leftJoinSub($refCounts, 'ref', function ($join) {
- $join->on('ref.param', '=', 'imdb.imdb_id');
- })
- ->whereNotNull('imdb.primary_title')
- ->whereNotNull('imdb.wiki_article')
- ->where('imdb.title_type', 'movie')
- ->orderBy($order, $direction)
- ->simplePaginate(12);
-
- $total = DB::connection('cinema')
- ->table('imdb')
- ->whereNotNull('primary_title')
- ->whereNotNull('wiki_article')
- ->where('title_type', 'movie')
- ->count();
-
- return view('cinema', ['movies' => $movies, 'count' => $total, 'order' => $order, 'direction' => $direction]);
- }
-
- public function show($id)
- {
- $movie = DB::connection('cinema')
- ->table('imdb')
- ->where('imdb.imdb_id', $id)
- ->first();
-
- if (! $movie) {
- abort(404);
- }
-
- $genres = DB::connection('cinema')
- ->table('imdb_genre')
- ->join('genre', 'genre.id', '=', 'imdb_genre.genre_id')
- ->where('imdb_genre.imdb_id', $movie->id)
- ->pluck('genre.name');
-
- $casts = DB::connection('cinema')
- ->table('who')
- ->join('people', 'people.id', '=', 'who.people_id')
- ->join('profession', 'profession.id', '=', 'who.profession_id')
- ->where('who.imdb_id', $movie->id)
- ->select('people.name', 'profession.name as profession')
- ->get();
-
- $actors = $casts->where('profession', 'actor')->take(8);
- $directors = $casts->where('profession', 'director');
- $screenwriters = $casts->where('profession', 'screenwriter')->take(3);
-
- $hnStories = DB::connection('cinema')
- ->table('links')
- ->join('story', 'story.id', '=', 'links.story_id')
- ->select(
- 'story.story_id',
- 'story.title',
- 'story.type',
- 'story.text',
- 'story.score',
- 'story.descendants',
- 'story.time'
- )
- ->where('links.host', 'www.imdb.com')
- ->where('links.field', 1)
- ->where('links.param', $id)
- ->orderBy('story.time', 'desc')
- ->get();
-
- return view('cinema_show', [
- 'movie' => $movie,
- 'genres' => $genres,
- 'actors' => $actors,
- 'directors' => $directors,
- 'screenwriters' => $screenwriters,
- 'hnStories' => $hnStories,
- ]);
- }
-
- public function genres()
- {
- $genres = DB::connection('cinema')
- ->table('genre')
- ->select('genre.name', DB::raw('COUNT(imdb_genre.imdb_id) as count'))
- ->join('imdb_genre', 'imdb_genre.genre_id', '=', 'genre.id')
- ->join('imdb', 'imdb.id', '=', 'imdb_genre.imdb_id')
- ->whereNotNull('imdb.primary_title')
- ->whereNotNull('imdb.wiki_article')
- ->where('imdb.title_type', 'movie')
- ->groupBy('genre.name')
- ->orderBy('count', 'desc')
- ->get();
-
- return view('genres', ['genres' => $genres]);
- }
-
- public function genre($name)
- {
- $genre = DB::connection('cinema')
- ->table('genre')
- ->where('name', $name)
- ->first();
-
- if (! $genre) {
- abort(404);
- }
-
- $movies = DB::connection('cinema')
- ->table('imdb')
- ->select(
- 'imdb.id',
- 'imdb.imdb_id',
- 'imdb.primary_title',
- 'imdb.original_title',
- 'imdb.start_year',
- 'imdb.average_rating',
- 'imdb.num_votes',
- 'imdb.synopsis',
- 'imdb.poster_url',
- 'imdb.title_type',
- 'imdb.runtime_minutes'
- )
- ->join('imdb_genre', 'imdb_genre.imdb_id', '=', 'imdb.id')
- ->join('genre', 'genre.id', '=', 'imdb_genre.genre_id')
- ->where('genre.name', $name)
- ->whereNotNull('imdb.primary_title')
- ->whereNotNull('imdb.wiki_article')
- ->where('imdb.title_type', 'movie')
- ->orderBy('imdb.average_rating', 'desc')
- ->simplePaginate(12);
-
- $count = DB::connection('cinema')
- ->table('imdb')
- ->join('imdb_genre', 'imdb_genre.imdb_id', '=', 'imdb.id')
- ->join('genre', 'genre.id', '=', 'imdb_genre.genre_id')
- ->where('genre.name', $name)
- ->whereNotNull('imdb.primary_title')
- ->whereNotNull('imdb.wiki_article')
- ->where('imdb.title_type', 'movie')
- ->count();
-
- return view('genre_movies', ['movies' => $movies, 'count' => $count, 'genre_name' => $name]);
- }
-
- public function search(Request $request)
- {
- $query = $request->input('q', '');
-
- $movies = DB::connection('cinema')
- ->table('imdb')
- ->select(
- 'imdb.id',
- 'imdb.imdb_id',
- 'imdb.primary_title',
- 'imdb.original_title',
- 'imdb.start_year',
- 'imdb.average_rating',
- 'imdb.num_votes',
- 'imdb.synopsis',
- 'imdb.poster_url',
- 'imdb.title_type',
- 'imdb.runtime_minutes'
- )
- ->whereNotNull('imdb.primary_title')
- ->whereNotNull('imdb.wiki_article')
- ->where('imdb.title_type', 'movie')
- ->where(function ($q) use ($query) {
- $q->where('imdb.primary_title', 'like', '%' . $query . '%')
- ->orWhere('imdb.original_title', 'like', '%' . $query . '%')
- ->orWhere('imdb.synopsis', 'like', '%' . $query . '%');
- })
- ->simplePaginate(12);
-
- $total = DB::connection('cinema')
- ->table('imdb')
- ->whereNotNull('primary_title')
- ->whereNotNull('wiki_article')
- ->where('title_type', 'movie')
- ->where(function ($q) use ($query) {
- $q->where('primary_title', 'like', '%' . $query . '%')
- ->orWhere('original_title', 'like', '%' . $query . '%')
- ->orWhere('synopsis', 'like', '%' . $query . '%');
- })
- ->count();
-
- return view('cinema', ['movies' => $movies, 'count' => $total, 'search_query' => $query]);
- }
-}
diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php
index 5029a1c..fcf7e5b 100644
--- a/app/Libraries/Helper.php
+++ b/app/Libraries/Helper.php
@@ -152,8 +152,8 @@ class Helper {
$discussions = "<br>";
foreach( $post->getDiscussions()->orderBy('comments', 'desc')->get() as $dis ) {
- $discussions .= "<a href='" . $dis->source_url . "'>" . $dis->title . "</a> | ";
- $discussions .= Helper::formatTimestamp($dis->posted_on) . " | " . $dis->upvotes . " Upvotes | " . $dis->comments . " Comments<br>";
+ $discussions .= "<a href='" . $dis->source_url . "'>" . $dis->title . "</a> ";
+ $discussions .= $dis->upvotes . " Upvotes | " . $dis->comments . " Comments<br>";
}
$desc .= "<br><br>Discussions:";
$desc .= $discussions;