web.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <?php
  2. use App\Models\Film;
  3. use Illuminate\Support\Facades\Route;
  4. use Tmdb\Repository\MovieRepository;
  5. use App\Http\Helpers\TmdbProvider;
  6. use App\Models\Comment;
  7. use App\Models\Setting;
  8. use Tmdb\Helper\ImageHelper;
  9. use Tmdb\Repository\ConfigurationRepository;
  10. use Tmdb\Repository\SearchRepository;
  11. use App\Models\News;
  12. use App\Models\Vote;
  13. use Tmdb\Model\Search\SearchQuery\MovieSearchQuery;
  14. use Illuminate\Http\Request;
  15. use Illuminate\Support\Facades\Auth;
  16. /*
  17. |--------------------------------------------------------------------------
  18. | Web Routes
  19. |--------------------------------------------------------------------------
  20. |
  21. | Here is where you can register web routes for your application. These
  22. | routes are loaded by the RouteServiceProvider within a group which
  23. | contains the "web" middleware group. Now create something great!
  24. |
  25. */
  26. Route::get('/', function () {
  27. $nextfilmid = Setting::nextFilm()->first()->value;
  28. if($nextfilmid != 0 && !is_null($nextfilmid)) {
  29. $feature = Film::where('id', $nextfilmid)->first();
  30. $featuretype = 'next';
  31. } else {
  32. //lastfilm
  33. $feature = Film::orderBy('seen', 'desc')->first();
  34. $featuretype = 'last';
  35. }
  36. $client = TmdbProvider::getClient();
  37. $repo = new MovieRepository($client);
  38. /** @var \Tmdb\Model\Movie */
  39. $tmdb = $repo->load($feature->tvdbid);
  40. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  41. if($feature->poster === '') {
  42. $feature->poster = $tmdb->getPosterPath();
  43. $feature->save();
  44. }
  45. $popular = Film::popular()->limit(5)->get();
  46. $new = Film::whereNull('seen')->whereNull('rejected')->orderBy('suggested', 'DESC')->limit(5)->get();
  47. $seen = $filme = Film::whereNotNull('seen')->orderBy('seen', 'desc')->limit(5, $featuretype == 'next' ? 0 : 1)->get();
  48. $news = News::orderBy('id', 'desc')->limit(5)->get();
  49. return view('main', ['feature' => $feature, 'ftype' => $featuretype, 'ftmdb' => $tmdb, 'image' => $ihelp, 'popular' => $popular, 'new' => $new, 'seen' => $seen, 'news' => $news]);
  50. })->name('home');
  51. Route::get('/film/{id}', function ($id) {
  52. $film = Film::where('id', $id)->first();
  53. $client = TmdbProvider::getClient();
  54. $repo = new MovieRepository($client);
  55. /** @var \Tmdb\Model\Movie */
  56. $tmdb = $repo->load($film->tvdbid);
  57. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  58. if($film->poster === '') {
  59. $film->poster = $tmdb->getPosterPath();
  60. $film->save();
  61. }
  62. return view('film', ["film" => $film, "tmdb" => $tmdb, "image" => $ihelp]);
  63. })->name('film');
  64. Route::get('/dashboard', function () {
  65. return view('dashboard');
  66. })->middleware(['auth'])->name('dashboard');
  67. Route::get('/gesehen/{field?}/{order?}', function ($field = "seen", $order = "desc") {
  68. $filme = Film::whereNotNull('seen')->orderBy($field, $order)->paginate(24);
  69. $client = TmdbProvider::getClient();
  70. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  71. return view('archiv', ['title' => 'Gesehene Filme', 'films' => $filme, 'ihelp' => $ihelp]);
  72. })->name('gesehen')->where(['field' => '[a-z]+', 'order' => 'asc|desc']);
  73. Route::get('/abgelehnt/{field?}/{order?}', function ($field = "seen", $order = "desc") {
  74. $filme = Film::whereNotNull('rejected')->orderBy($field, $order)->paginate(24);
  75. $client = TmdbProvider::getClient();
  76. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  77. return view('archiv', ['title' => 'Abgelehnte Filme', 'films' => $filme, 'ihelp' => $ihelp]);
  78. })->name('abgelehnt')->where(['field' => '[a-z]+', 'order' => 'asc|desc']);
  79. Route::get('/vorschlaege/{order?}', function ($order = 'popular') {
  80. if($order === "neu")
  81. $films = Film::whereNull('seen')->whereNull('rejected')->orderBy('suggested', 'DESC')->paginate(24);
  82. elseif($order === "popular")
  83. $films = Film::popular()->paginate(24);
  84. else
  85. abort(404);
  86. $client = TmdbProvider::getClient();
  87. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  88. return view('vorschlaege', ["films" => $films, "title" => $order == 'popular' ? "nach Beliebtheit" : "nach Datum", "ihelp" => $ihelp]);
  89. })->name('vorschlag');
  90. Route::get('/neu', function () {
  91. return view('suche', ['title' => 'Film vorschlagen']);
  92. })->middleware(['auth'])->name('neu');
  93. Route::get('/api/search/{term?}', function($term = null) {
  94. if ($term == null || strlen($term) < 4) {
  95. return response('<div class="w-full text-center italic mt-2">Bitte mindestens 4 Zeichen eingeben!</div>');
  96. } else {
  97. $filme = Film::whereRaw("LOWER(name) like LOWER('%{$term}%')")->limit(12)->get();
  98. $count = Film::whereRaw("LOWER(name) like LOWER('%{$term}%')")->count();
  99. $client = TmdbProvider::getClient();
  100. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  101. return view('localsearch', ['filme' => $filme, 'count' => $count, 'ihelp' => $ihelp]);
  102. }
  103. });
  104. Route::get('/api/remotesearch/{term?}', function($term = null) {
  105. $client = TmdbProvider::getClient();
  106. $query = new MovieSearchQuery();
  107. $query->page(1);
  108. $search = new SearchRepository($client);
  109. $find = $search->searchMovie($term, $query);
  110. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  111. return view('remotesearch', ['filme' => $find, 'image' => $ihelp]);
  112. });
  113. Route::get('/film/vote/{film}/{vote}', function($film, $vote) {
  114. $vbool = (bool) $vote;
  115. $vote = Vote::where('film', $film)->where('user', auth()->id())->first();
  116. if(is_null($vote)) {
  117. $vote = new Vote();
  118. $vote->user = auth()->id();
  119. $vote->film = $film;
  120. }
  121. $vote->vote = $vbool;
  122. $vote->save();
  123. return redirect("/film/{$film}#voting")->with('status', 'Du hast abgestimmt!');
  124. })->middleware(['auth']);
  125. Route::get('/film/mark/{id}/{type}', function($id, $type) {
  126. if(!Auth::user()->isAdmin()) {
  127. return redirect("/film/{$id}");
  128. }
  129. switch($type) {
  130. case 'next':
  131. $setting = Setting::nextFilm()->first();
  132. $setting->value = $id;
  133. $setting->save();
  134. $message = "Als nächsten Film markiert!";
  135. break;
  136. case 'seen':
  137. if(Setting::nextFilm()->first()->value == $id) {
  138. $setting = Setting::nextFilm()->first();
  139. $setting->value = 0;
  140. $setting->save();
  141. }
  142. $film = Film::find($id);
  143. $film->seen = now();
  144. $film->save();
  145. $message = "Film als gesehen markiert!";
  146. break;
  147. case 'deny':
  148. if(Setting::nextFilm()->first()->value == $id) {
  149. $setting = Setting::nextFilm()->first();
  150. $setting->value = 0;
  151. $setting->save();
  152. }
  153. $film = Film::find($id);
  154. $film->rejected = now();
  155. $film->save();
  156. $message = "Film als abgelehnt markiert!";
  157. break;
  158. }
  159. return redirect("/film/{$id}")->with('status', $message);
  160. })->middleware(['auth']);
  161. Route::get('/vorschlag/{id}', function($id) {
  162. $films = Film::where('tvdbid', $id)->get();
  163. $previous = ["seen" => [], "rejected" => [], "suggested" => []];
  164. foreach($films as $film) {
  165. if(!is_null($film->rejected)) {
  166. $previous['rejected'][] = ["id" => $film->id, "date" => $film->rejected];
  167. } elseif (!is_null($film->seen)) {
  168. $previous['seen'][] = ["id" => $film->id, "date" => $film->seen];
  169. } else {
  170. $previous['suggested'][] = ["id" => $film->id, "date" => $film->created_at];
  171. }
  172. }
  173. $client = TmdbProvider::getClient();
  174. $repo = new MovieRepository($client);
  175. /** @var \Tmdb\Model\Movie */
  176. $tmdb = $repo->load($id);
  177. $ihelp = new ImageHelper((new ConfigurationRepository($client))->load());
  178. return view('vorschlag', ["tmdb" => $tmdb, "image" => $ihelp, "previous" => $previous]);
  179. })->middleware(['auth']);
  180. Route::get('/vorschlag/{id}/vorschlagen', function($id) {
  181. $client = TmdbProvider::getClient();
  182. $repo = new MovieRepository($client);
  183. /** @var \Tmdb\Model\Movie */
  184. $tmdb = $repo->load($id);
  185. $film = new Film();
  186. $film->name = $tmdb->getTitle();
  187. $film->tvdbid = $id;
  188. $film->suggested = now();
  189. $film->user = auth()->user()->id;
  190. $film->poster = $tmdb->getPosterPath();
  191. $film->save();
  192. return redirect("/film/" . $film->id)->with('status', auth()->user()->name . ', Film "' . $film->name . '" vorgeschlagen.');
  193. })->middleware(['auth']);
  194. Route::post('/comment/new/{film}', function($film, Request $request) {
  195. $c = new Comment();
  196. $c->film = $film;
  197. $c->user = Auth::user()->id;
  198. $c->body = $request->input('body', '');
  199. if(is_null($c->body)) $c->body = "";
  200. $c->evaluation = $request->input('vote', 0);
  201. $c->save();
  202. return redirect("/film/" . $film)->with('status', auth()->user()->name . ', Kommentar/Bewertung hinzugefügt.');
  203. })->middleware(['auth']);
  204. Route::post('/comment/edit/{comment}', function($comment, Request $request) {
  205. $c = Comment::findOrFail($comment);
  206. $c->body = $request->input('body', '');
  207. if(is_null($c->body)) $c->body = "";
  208. $c->evaluation = $request->input('vote', $c->evaluation);
  209. $c->save();
  210. return redirect("/film/" . $c->film)->with('status', auth()->user()->name . ', Kommentar/Bewertung hinzugefügt.');
  211. })->middleware(['auth']);
  212. require __DIR__.'/auth.php';