first()->value;
if($nextfilmid != 0 && !is_null($nextfilmid)) {
$feature = Film::where('id', $nextfilmid)->first();
$featuretype = 'next';
} else {
//lastfilm
$feature = Film::orderBy('seen', 'desc')->first();
$featuretype = 'last';
}
$client = TmdbProvider::getClient();
$repo = new MovieRepository($client);
/** @var \Tmdb\Model\Movie */
$tmdb = $repo->load($feature->tvdbid);
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
if($feature->poster === '') {
$feature->poster = $tmdb->getPosterPath();
$feature->save();
}
$popular = Film::popular()->limit(5)->get();
$new = Film::whereNull('seen')->whereNull('rejected')->orderBy('suggested', 'DESC')->limit(5)->get();
$seen = $filme = Film::whereNotNull('seen')->orderBy('seen', 'desc')->limit(5, $featuretype == 'next' ? 0 : 1)->get();
$news = News::orderBy('id', 'desc')->limit(5)->get();
return view('main', ['feature' => $feature, 'ftype' => $featuretype, 'ftmdb' => $tmdb, 'image' => $ihelp, 'popular' => $popular, 'new' => $new, 'seen' => $seen, 'news' => $news]);
})->name('home');
Route::get('/film/{id}', function ($id) {
$film = Film::where('id', $id)->first();
$client = TmdbProvider::getClient();
$repo = new MovieRepository($client);
/** @var \Tmdb\Model\Movie */
$tmdb = $repo->load($film->tvdbid);
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
if($film->poster === '') {
$film->poster = $tmdb->getPosterPath();
$film->save();
}
return view('film', ["film" => $film, "tmdb" => $tmdb, "image" => $ihelp]);
})->name('film');
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth'])->name('dashboard');
Route::get('/gesehen/{field?}/{order?}', function ($field = "seen", $order = "desc") {
$filme = Film::whereNotNull('seen')->orderBy($field, $order)->paginate(24);
$client = TmdbProvider::getClient();
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
return view('archiv', ['title' => 'Gesehene Filme', 'films' => $filme, 'ihelp' => $ihelp]);
})->name('gesehen')->where(['field' => '[a-z]+', 'order' => 'asc|desc']);
Route::get('/abgelehnt/{field?}/{order?}', function ($field = "seen", $order = "desc") {
$filme = Film::whereNotNull('rejected')->orderBy($field, $order)->paginate(24);
$client = TmdbProvider::getClient();
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
return view('archiv', ['title' => 'Abgelehnte Filme', 'films' => $filme, 'ihelp' => $ihelp]);
})->name('abgelehnt')->where(['field' => '[a-z]+', 'order' => 'asc|desc']);
Route::get('/vorschlaege/{order?}', function ($order = 'popular') {
if($order === "neu")
$films = Film::whereNull('seen')->whereNull('rejected')->orderBy('suggested', 'DESC')->paginate(24);
elseif($order === "popular")
$films = Film::popular()->paginate(24);
else
abort(404);
$client = TmdbProvider::getClient();
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
return view('vorschlaege', ["films" => $films, "title" => $order == 'popular' ? "nach Beliebtheit" : "nach Datum", "ihelp" => $ihelp]);
})->name('vorschlag');
Route::get('/neu', function () {
return view('suche', ['title' => 'Film vorschlagen']);
})->middleware(['auth'])->name('neu');
Route::get('/api/search/{term?}', function($term = null) {
if ($term == null || strlen($term) < 4) {
return response('
Bitte mindestens 4 Zeichen eingeben!
');
} else {
$filme = Film::whereRaw("LOWER(name) like LOWER('%{$term}%')")->limit(12)->get();
$count = Film::whereRaw("LOWER(name) like LOWER('%{$term}%')")->count();
$client = TmdbProvider::getClient();
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
return view('localsearch', ['filme' => $filme, 'count' => $count, 'ihelp' => $ihelp]);
}
});
Route::get('/api/remotesearch/{term?}', function($term = null) {
$client = TmdbProvider::getClient();
$query = new MovieSearchQuery();
$query->page(1);
$search = new SearchRepository($client);
$find = $search->searchMovie($term, $query);
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
return view('remotesearch', ['filme' => $find, 'image' => $ihelp]);
});
Route::get('/film/vote/{film}/{vote}', function($film, $vote) {
$vbool = (bool) $vote;
$vote = Vote::where('film', $film)->where('user', auth()->id())->first();
if(is_null($vote)) {
$vote = new Vote();
$vote->user = auth()->id();
$vote->film = $film;
}
$vote->vote = $vbool;
$vote->save();
return redirect("/film/{$film}#voting")->with('status', 'Du hast abgestimmt!');
})->middleware(['auth']);
Route::get('/film/mark/{id}/{type}', function($id, $type) {
if(!Auth::user()->isAdmin()) {
return redirect("/film/{$id}");
}
switch($type) {
case 'next':
$setting = Setting::nextFilm()->first();
$setting->value = $id;
$setting->save();
$message = "Als nächsten Film markiert!";
break;
case 'seen':
if(Setting::nextFilm()->first()->value == $id) {
$setting = Setting::nextFilm()->first();
$setting->value = 0;
$setting->save();
}
$film = Film::find($id);
$film->seen = now();
$film->save();
$message = "Film als gesehen markiert!";
break;
case 'deny':
if(Setting::nextFilm()->first()->value == $id) {
$setting = Setting::nextFilm()->first();
$setting->value = 0;
$setting->save();
}
$film = Film::find($id);
$film->rejected = now();
$film->save();
$message = "Film als abgelehnt markiert!";
break;
}
return redirect("/film/{$id}")->with('status', $message);
})->middleware(['auth']);
Route::get('/vorschlag/{id}', function($id) {
$films = Film::where('tvdbid', $id)->get();
$previous = ["seen" => [], "rejected" => [], "suggested" => []];
foreach($films as $film) {
if(!is_null($film->rejected)) {
$previous['rejected'][] = ["id" => $film->id, "date" => $film->rejected];
} elseif (!is_null($film->seen)) {
$previous['seen'][] = ["id" => $film->id, "date" => $film->seen];
} else {
$previous['suggested'][] = ["id" => $film->id, "date" => $film->created_at];
}
}
$client = TmdbProvider::getClient();
$repo = new MovieRepository($client);
/** @var \Tmdb\Model\Movie */
$tmdb = $repo->load($id);
$ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
return view('vorschlag', ["tmdb" => $tmdb, "image" => $ihelp, "previous" => $previous]);
})->middleware(['auth']);
Route::get('/vorschlag/{id}/vorschlagen', function($id) {
$client = TmdbProvider::getClient();
$repo = new MovieRepository($client);
/** @var \Tmdb\Model\Movie */
$tmdb = $repo->load($id);
$film = new Film();
$film->name = $tmdb->getTitle();
$film->tvdbid = $id;
$film->suggested = now();
$film->user = auth()->user()->id;
$film->poster = $tmdb->getPosterPath();
$film->save();
return redirect("/film/" . $film->id)->with('status', auth()->user()->name . ', Film "' . $film->name . '" vorgeschlagen.');
})->middleware(['auth']);
require __DIR__.'/auth.php';