123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- use App\Models\Film;
- use Illuminate\Support\Facades\Route;
- use Tmdb\Repository\MovieRepository;
- use App\Http\Helpers\TmdbProvider;
- use App\Models\Setting;
- use Tmdb\Helper\ImageHelper;
- use Tmdb\Repository\ConfigurationRepository;
- use Tmdb\Repository\SearchRepository;
- use App\Models\News;
- use App\Models\Vote;
- use Hamcrest\Core\Set;
- use Symfony\Component\EventDispatcher\EventDispatcher;
- use Tmdb\Event\Listener\HydrationListener;
- use Tmdb\Model\Search\SearchQuery\MovieSearchQuery;
- /*
- |--------------------------------------------------------------------------
- | Web Routes
- |--------------------------------------------------------------------------
- |
- | Here is where you can register web routes for your application. These
- | routes are loaded by the RouteServiceProvider within a group which
- | contains the "web" middleware group. Now create something great!
- |
- */
- Route::get('/', function () {
- $nextfilmid = Setting::nextFilm()->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('<div class="w-full text-center italic mt-2">Bitte mindestens 4 Zeichen eingeben!</div>');
- } 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';
|