routes.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Application Routes
  5. |--------------------------------------------------------------------------
  6. |
  7. | Here is where you can register all of the routes for an application.
  8. | It's a breeze. Simply tell Laravel the URIs it should respond to
  9. | and give it the Closure to execute when that URI is requested.
  10. |
  11. */
  12. Route::get('/', function()
  13. {
  14. $gesehen = Film::zuletztGesehen()->get();
  15. $abgelehnt = Film::zuletztAbgelehnt()->get();
  16. $vorgeschlagen = Film::neuesteVorschlage()->get();
  17. $mg = Film::meistgewunschteVorschlage()->take(5)->get();
  18. //$x = DB::getQueryLog();
  19. //dd(end($x));
  20. $news = News::aktuell()->get();
  21. $nextfilm = Dumbo::find(1)->film;
  22. $tmdb = new TMDb(Config::get('constants.tvdb.apikey'), 'de', TRUE, TMDb::API_SCHEME_SSL);
  23. foreach(array("top" => $mg[0], "neu" => $vorgeschlagen[0], "alt" => $gesehen[0], "declined" => $abgelehnt[0]) as $key => $val) {
  24. $tmovie = $tmdb->getMovie($val->tvdbid);
  25. $images[$key] = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
  26. }
  27. if(is_object($nextfilm)) {
  28. $tmovie = $tmdb->getMovie($nextfilm->tvdbid);
  29. $images["next"] = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
  30. } else {
  31. $images["next"] = "img/no-poster-w92.jpg";
  32. }
  33. $kommentare = Comment::neueste()->get();
  34. $labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success");
  35. return View::make('index')
  36. ->with('gesehen', $gesehen)
  37. ->with('abgelehnt', $abgelehnt)
  38. ->with('vorgeschlagen', $vorgeschlagen)
  39. ->with('meistgw', $mg)
  40. ->with('images', $images)
  41. ->with('news', $news)
  42. ->with('kommentare', $kommentare)
  43. ->with('labels', $labels)
  44. ->with('nextfilm', $nextfilm);
  45. });
  46. Route::get('film/{id}', array('as' => 'film', function($id) {
  47. $film = Film::findOrFail($id);
  48. $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
  49. $tmovie = $tmdb->getMovie($film->tvdbid);
  50. $tcast = $tmdb->getMovieCast($film->tvdbid);
  51. $ttrail = $tmdb->getMovieTrailers($film->tvdbid);
  52. $image = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
  53. $votes = $film->votes()->count();
  54. $vposi = $film->votes()->where('stimme', true)->count();
  55. $pv = array();
  56. foreach($film->votes()->where('stimme', true)->get() as $v) {
  57. $pv[] = $v->voter;
  58. }
  59. $nv = array();
  60. foreach($film->votes()->where('stimme', false)->get() as $v) {
  61. $nv[] = $v->voter;
  62. }
  63. if(!is_null(Auth::user()) && $film->votes()->where('user', Auth::user()->id)->count() > 0) {
  64. $uvote[0] = true;
  65. $uvote[1] = $film->votes()->where('user', Auth::user()->id)->first()->stimme;
  66. } else {
  67. $uvote[0] = false;
  68. }
  69. $comments = $film->comments()->orderBy('id', 'DESC')->get();
  70. $labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success");
  71. return View::make('film')
  72. ->with('film', $film)
  73. ->with('tfilm', $tmovie)
  74. ->with('poster', $image)
  75. ->with('comments', $comments)
  76. ->with('cast', $tcast)
  77. ->with('trail', $ttrail)
  78. ->with('votes', $votes)
  79. ->with('uvote', $uvote)
  80. ->with('pv', $pv)
  81. ->with('nv', $nv)
  82. ->with('vposi', $vposi)
  83. ->with('labels', $labels)
  84. ->with('tmdb', $tmdb);
  85. }));
  86. Route::get('vote/{stimme}/{user}/{film}', function($stimme, $user, $film) {
  87. $v = Vote::where('user', $user)->where('film', $film)->first();
  88. if(!is_null($v)) {
  89. $v->stimme = $stimme == "yes" ? true : false;
  90. } else {
  91. $v = new Vote();
  92. $v->user = $user;
  93. $v->film = $film;
  94. $v->stimme = $stimme == "yes" ? true : false;
  95. }
  96. $v->save();
  97. return Redirect::to('film/' . $film);
  98. });
  99. Route::post('comment', array('as' => 'comment', function() {
  100. $c = new Comment();
  101. $c->film = Input::get('film');
  102. $c->user = Input::get('user');
  103. $c->text = Input::get('text');
  104. $c->bewertung = !is_null(Input::get('rate')) ? Input::get('rate') : 0;
  105. $c->save();
  106. return Redirect::to('film/' . Input::get('film'));
  107. }));
  108. Route::post('comment/edit', array('as'=> 'modcomment', function () {
  109. $c = Comment::findOrFail(Input::get('id'));
  110. $c->text = Input::get('text');
  111. $c->bewertung = Input::get('rate');
  112. $c->save();
  113. return Redirect::to('film/' . $c->film);
  114. }));
  115. Route::get('login', array('as' => 'login', function() {
  116. return View::make('login');
  117. }));
  118. Route::post('login', function() {
  119. $userdata = array(
  120. 'name' => Input::get('user'),
  121. 'password' => Input::get('password'));
  122. if(Auth::attempt($userdata, true)) {
  123. return Redirect::intended('/');
  124. } else {
  125. echo "Login gescheitert.";
  126. var_dump($userdata);
  127. return Redirect::to('login')
  128. ->with('login_errors', true);
  129. }
  130. });
  131. Route::get('logout', array('as' => 'logout', function() {
  132. Auth::logout();
  133. return Redirect::to('/');
  134. }));
  135. Route::get('beliebt', function() {
  136. $filme = Film::meistgewunschteVorschlage()->paginate(25);
  137. return View::make('suggest')
  138. ->with('filme', $filme)
  139. ->with('titel', 'Vorschl&auml;ge nach Wertung');
  140. });
  141. Route::get('vorgeschlagen', function() {
  142. $filme = DB::table(DB::raw('film_films'))
  143. ->select(DB::raw('film_films.*, COUNT(case when film_votes.stimme IS TRUE then 1 end) as upvotes,
  144. COUNT(case when film_votes.stimme IS FALSE then 1 end) as downvotes,
  145. COUNT(case when film_votes.stimme IS TRUE then 1 end) as vcount'))
  146. ->leftJoin('votes', 'votes.film', '=', 'films.id')
  147. ->leftJoin('users', 'users.id', '=', 'votes.user')
  148. ->whereNull('films.gesehen')
  149. ->whereNull('films.abgelehnt')
  150. ->where('users.settings', 'NOT LIKE', '%disabled":true%')
  151. ->groupBy('id')
  152. ->orderBy('vorgeschlagen', 'DESC')
  153. ->paginate(25);
  154. return View::make('suggest')
  155. ->with('filme', $filme)
  156. ->with('titel', 'Vorschl&auml;ge nach Datum');
  157. });
  158. Route::get('abgelehnt/{field?}/{order?}', function($field = "abgelehnt", $order = "desc") {
  159. $filme = Film::whereNotNull('abgelehnt')->orderBy($field, $order)->paginate(25);
  160. $labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success");
  161. return View::make('abgelehnt')
  162. ->with('labels', $labels)
  163. ->with('filme', $filme);
  164. })->where(array('field' => '[a-z]+', 'order' => 'asc|desc'));
  165. Route::get('gesehen/{field?}/{order?}', function($field = "gesehen", $order = "desc") {
  166. $filme = Film::whereNotNull('gesehen')->orderBy($field, $order)->paginate(25);
  167. $labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success");
  168. return View::make('seen')
  169. ->with('labels', $labels)
  170. ->with('filme', $filme);
  171. })->where(array('field' => '[a-z]+', 'order' => 'asc|desc'));
  172. Route::get('neu', array('before' => 'auth', function() {
  173. return View::make('new');
  174. }));
  175. Route::post('neu', array('before' => 'auth', function() {
  176. $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
  177. $r = $tmdb->searchMovie(Input::get('search'));
  178. return View::make('new')->with('result', $r)->with('tmdb', $tmdb);
  179. }));
  180. Route::get('vorschlag/{id}', array('before' => 'auth', function($id) {
  181. $ef = Film::where('tvdbid', '=', $id)->whereNull('gesehen')->whereNull('abgelehnt')->first();
  182. if(is_null($ef)) {
  183. $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
  184. $f = $tmdb->getMovie($id);
  185. $film = new Film();
  186. $film->name = $f['title'];
  187. $film->tvdbid = $id;
  188. $film->vorgeschlagen = \Carbon\Carbon::today();
  189. $film->user = Auth::user()->id;
  190. $film->save();
  191. Session::put('message', 'Film hinzugefügt.');
  192. return Redirect::to('film/' . $film->id);
  193. } else {
  194. if(is_null($ef->abgelehnt)) {
  195. Session::put('message', 'Film bereits vorgeschlagen von ' . $ef->besitzer->name . '.');
  196. } else {
  197. Session::put('message', 'Film bereits abgelehmt.');
  198. }
  199. return Redirect::to('film/' . $ef->id);
  200. }
  201. }));
  202. Route::get('mark-declined/{id}', array('before' => 'auth', function($id) {
  203. $film = Film::findOrFail($id);
  204. $film->abgelehnt = \Carbon\Carbon::today();
  205. $film->save();
  206. if(Dumbo::find(1)->nextfilm == $film->id) {
  207. $system = Dumbo::findOrFail(1);
  208. $system->nextfilm = 0;
  209. $system->save();
  210. }
  211. return Redirect::to('film/' . $film->id);
  212. }));
  213. Route::get('mark-read/{id}', array('before' => 'auth', function($id) {
  214. $film = Film::findOrFail($id);
  215. $film->gesehen = \Carbon\Carbon::today();
  216. $film->save();
  217. if(Dumbo::find(1)->nextfilm == $film->id) {
  218. $system = Dumbo::findOrFail(1);
  219. $system->nextfilm = 0;
  220. $system->save();
  221. }
  222. return Redirect::to('film/' . $film->id);
  223. }));
  224. Route::get('view-next/{id}', array('before' => 'auth', function($id) {
  225. $system = Dumbo::findOrFail(1);
  226. $system->nextfilm = $id;
  227. $system->save();
  228. return Redirect::to('film/' . $id);
  229. }));
  230. Route::get('register', function() {
  231. return View::make('register');
  232. });
  233. Route::post('register', function() {
  234. $vrules = array(
  235. 'name' => 'required|unique:users',
  236. 'email' => 'required|email',
  237. 'password' => 'required|confirmed',
  238. 'fire' => array('required', 'regex:/^Kreis$/i')
  239. );
  240. $vfields = array(
  241. 'name' => Input::get('user'),
  242. 'email' => Input::get('email'),
  243. 'password' => Input::get('password'),
  244. 'password_confirmation' => Input::get('pw-confirm'),
  245. 'fire' => Input::get('fire')
  246. );
  247. $val = Validator::make($vfields, $vrules);
  248. if($val->fails()) {
  249. return View::make('register')->with('errors', $val->messages());
  250. } else {
  251. $u = new User();
  252. $u->name = Input::get('user');
  253. $u->email = Input::get('email');
  254. $u->password = Hash::make(Input::get('password'));
  255. $u->save();
  256. return Redirect::to('/')->with('message', 'Registriert!');
  257. }
  258. });
  259. Route::get('settings', array('before' => 'auth', function() {
  260. return View::make('settings');
  261. }));
  262. Route::post('settings/{mode}', array('before' => 'auth', function($mode) {
  263. Validator::extend('pass', function($attribute, $value, $parameters) {
  264. return Hash::check($value, Auth::user()->password);
  265. });
  266. if($mode == 'password') {
  267. var_dump(Hash::check(Input::get('oldpw'), Auth::user()->password));
  268. $vfields = array('oldpw' => Input::get('oldpw'), 'newpw' => Input::get('newpw'), 'newpw_confirmation' => Input::get('newpw2'));
  269. $vrules = array( 'oldpw' => 'required|pass', 'newpw' => 'required|confirmed' );
  270. $val = Validator::make($vfields, $vrules);
  271. if($val->passes()) {
  272. $u = Auth::user();
  273. $u->password = Hash::make(Input::get('newpw'));
  274. $u->save();
  275. return View::make('settings')->with('message', 'Passwort geändert.');
  276. } else {
  277. return View::make('settings')->with('errors', $val->messages());
  278. }
  279. }
  280. if($mode == 'email') {
  281. $vfields = array('pw' => Input::get('pw'), 'email' => Input::get('email'), 'email_confirmation' => Input::get('email2'));
  282. $vrules = array('pw' => 'required|pass', 'email' => 'required|confirmed');
  283. $val = Validator::make($vfields, $vrules);
  284. if($val->passes()) {
  285. $u = Auth::user();
  286. $u->email = Input::get('email');
  287. $u->save();
  288. return View::make('settings')->with('message', 'Email geändert.');
  289. } else {
  290. return View::make('settings')->with('errors', $val->messages());
  291. }
  292. }
  293. if($mode == 'avatar-reset') {
  294. /** @var User $u */
  295. $u = Auth::user();
  296. $u->setSetting('avatar', false);
  297. $u->save();
  298. /* Delete old Avatars */
  299. array_map('unlink', glob(public_path("img/avatars/". Auth::user()->id . "-*")));
  300. return View::make('settings')->with('message', 'Avatar gelöscht.');
  301. }
  302. if($mode == 'avatar-upload') {
  303. $vfields = array('avatar' => Input::file('avatar'));
  304. $vrules = array('avatar' => 'required|image|max:5000');
  305. $val = Validator::make($vfields, $vrules);
  306. if($val->passes()) {
  307. /* Delete old Avatars */
  308. //array_map('unlink', glob(public_path("img/avatars/". Auth::user()->id . "-*")));
  309. /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
  310. $file = Input::file('avatar');
  311. $file = $file->move( public_path("img/avatars/"), Auth::user()->id . "-". Str::slug($file->getFilename()) . "." . $file->guessExtension() );
  312. exec('/usr/bin/gm convert -size 100x100 ' . $file->getRealPath() . ' -thumbnail 100x100^ -gravity center -extent 100x100 +profile "*" ' . $file->getRealPath());
  313. //$i = new Imagick();
  314. //$i->readImage($file->getRealPath());
  315. //$i->cropThumbnailImage(100, 100);
  316. //$i->writeImage();
  317. /** @var User $u */
  318. $u = Auth::user();
  319. $u->setSetting('avatar', $file->getFilename());
  320. $u->save();
  321. return View::make('settings')->with('message', 'Avatar gespeichert.');
  322. } else {
  323. return View::make('settings')->with('errors', $val->messages());
  324. }
  325. }
  326. }));
  327. Route::get('users', array('before' => 'auth', function() {
  328. if(Auth::user()->admin) {
  329. $u = User::orderBy('name')->paginate();
  330. return View::make('users')->with('users', $u);
  331. } else {
  332. App::abort(401, 'Diese Seite ist nicht für Dich.');
  333. }
  334. }));
  335. Route::get('users/{operation}/{id}', array('before' => 'auth', function($operation, $id) {
  336. if(!Auth::user()->admin) App::abort(401, 'Diese Seite ist nicht für Dich.');
  337. /** @var User $u */
  338. $u = User::findOrFail($id);
  339. switch($operation) {
  340. case 'mkadm':
  341. $u->admin = true;
  342. $u->save();
  343. $msg = $u->name . " ist jetzt ein Admin.";
  344. break;
  345. case 'rmadm':
  346. $u->admin = false;
  347. $u->save();
  348. $msg = $u->name . " ist kein Admin mehr.";
  349. break;
  350. case 'rmusr':
  351. $msg = $u->name . " wurde gelöscht.";
  352. $u->delete();
  353. break;
  354. case 'inact':
  355. $msg = $u->name. " ist inaktiv.";
  356. $u->setSetting("disabled", true);
  357. $u->save();
  358. break;
  359. case 'act':
  360. $msg = $u->name. " ist aktiv.";
  361. $u->setSetting("disabled", false);
  362. $u->save();
  363. break;
  364. }
  365. return Redirect::to('users')->with('message', $msg);
  366. }));
  367. Route::get('news', array('before' => 'auth', function() {
  368. return View::make('news');
  369. }));
  370. Route::post('news', array('before' => 'auth', function() {
  371. $vrules = array(
  372. 'headline' => 'required',
  373. 'body' => 'required'
  374. );
  375. $vfields = array(
  376. 'headline' => Input::get('headline'),
  377. 'body' => Input::get('body')
  378. );
  379. $val = Validator::make($vfields, $vrules);
  380. if($val->fails()) {
  381. return View::make('news')->with('errors', $val->messages());
  382. } else {
  383. $n = new News();
  384. $n->author = Auth::user()->id;
  385. $n->headline = Input::get('headline');
  386. $n->body = Input::get('body');
  387. $n->save();
  388. return Redirect::to('/')->with('message', 'News erstellt!');
  389. }
  390. }));
  391. Route::get('passwort-vergessen', function() {
  392. return View::make('pwform');
  393. });
  394. Route::post('passwort-vergessen', function() {
  395. $credentials = array('email' => Input::get('email'));
  396. return Password::remind($credentials, function($message, $user) {
  397. $message->subject('Passwort für Dumbo zurücksetzen.');
  398. });
  399. });
  400. Route::get('passwort-reset/{token}', function($token) {
  401. return View::make('pwreset')->with('token', $token);
  402. });
  403. Route::post('passwort-reset', function() {
  404. $credentials = array(
  405. 'email' => Input::get('email'),
  406. 'password' => Input::get('password'),
  407. 'password_confirmation' => Input::get('password_confirmation')
  408. );
  409. return Password::reset($credentials, function($user, $password) {
  410. $user->password = Hash::make($password);
  411. $user->save();
  412. return Redirect::to('/');
  413. });
  414. });
  415. Route::get('stats', function() {
  416. $stats = [
  417. array(
  418. 'name' => 'Meiste Vorschl&auml;ge',
  419. 'entr' => array('Vorschlag', 'Vorschl&auml;ge'),
  420. 'vals' => Film::addSelect(DB::raw("film_films.*, COUNT(`id`) as count"))
  421. ->groupBy('user')->orderBy('count', 'DESC')->take(3)->get(),
  422. 'prop' => 'besitzer',
  423. 'type' => 'User'
  424. ),
  425. array(
  426. 'name' => 'Meiste angenommene Vorschl&auml;ge',
  427. 'entr' => array('Vorschlag', 'Vorschl&auml;ge'),
  428. 'vals' => Film::addSelect(DB::raw("film_films.*, COUNT(`id`) as count"))
  429. ->whereNotNull('gesehen')->groupBy('user')->orderBy('count', 'DESC')->take(3)->get(),
  430. 'prop' => 'besitzer',
  431. 'type' => 'User'
  432. ),
  433. array(
  434. 'name' => 'Meiste abgelehnte Vorschl&auml;ge',
  435. 'entr' => array('Vorschlag', 'Vorschl&auml;ge'),
  436. 'vals' => Film::addSelect(DB::raw("film_films.*, COUNT(`id`) as count"))
  437. ->whereNotNull('abgelehnt')->groupBy('user')->orderBy('count', 'DESC')->take(3)->get(),
  438. 'prop' => 'besitzer',
  439. 'type' => 'User'
  440. ),
  441. array(
  442. 'name' => 'Meiste Kommentare',
  443. 'entr' => array('Kommentar', 'Kommentare'),
  444. 'vals' => Comment::addselect(DB::raw('film_comments.*, COUNT(`id`) as count'))
  445. ->where('text', '!=', '')->groupBy('user')->orderBy('count', 'DESC')->take(3)->get(),
  446. 'prop' => 'autor',
  447. 'type' => 'User'
  448. ),
  449. array(
  450. 'name' => 'Meiste Bewertungen',
  451. 'entr' => array('Bewertung', 'Bewertungen'),
  452. 'vals' => Comment::addselect(DB::raw('film_comments.*, COUNT(`id`) as count'))
  453. ->where('bewertung', '!=', 0)->groupBy('user')->orderBy('count', 'DESC')->take(3)->get(),
  454. 'prop' => 'autor',
  455. 'type' => 'User'
  456. ),
  457. array(
  458. 'name' => 'Bewertet am besten',
  459. 'entr' => array('', ''),
  460. 'vals' => Comment::addselect(DB::raw('film_comments.*, ROUND(AVG(`bewertung`),1) as count, COUNT(*) as no'))
  461. ->where('bewertung', '!=', 0)->groupBy('user')->orderBy('count', 'DESC')->orderBy('no', 'DESC')->take(3)->get(),
  462. 'prop' => 'autor',
  463. 'type' => 'User'
  464. ),
  465. array(
  466. 'name' => 'Bewertet am schlechtesten',
  467. 'entr' => array('', ''),
  468. 'vals' => Comment::addselect(DB::raw('film_comments.*, ROUND(AVG(`bewertung`),1) as count, COUNT(*) as no'))
  469. ->where('bewertung', '!=', 0)->groupBy('user')->orderBy('count', 'ASC')->orderBy('no', 'ASC')->take(3)->get(),
  470. 'prop' => 'autor',
  471. 'type' => 'User'
  472. ),
  473. array(
  474. 'name' => 'Meiste Filme wider Willen gesehen',
  475. 'entr' => array('Film', 'Filme'),
  476. 'vals' => Vote::addSelect(DB::raw('film_films.*, film_votes.*, COUNT(*) as count'))
  477. ->leftJoin('films', 'films.id', '=', 'votes.film')->whereNotNull('gesehen')
  478. ->whereRaw('stimme IS FALSE')->groupBy('votes.user')->orderBy('count', 'DESC')
  479. ->take(3)->get(),
  480. 'prop' => 'voter',
  481. 'type' => 'User'
  482. ),
  483. array(
  484. 'name' => 'Unbeliebtester Film',
  485. 'entr' => array('Stimme', 'Stimmen'),
  486. 'prop' => 'oFilm',
  487. 'type' => 'Film',
  488. 'vals' => Vote::addSelect(DB::raw('film_votes.*, film_films.*, COUNT(*) as count'))
  489. ->leftJoin('films', 'films.id', '=', 'votes.film')
  490. ->whereRaw('stimme IS FALSE')->groupBy('film')->orderBy('count', 'DESC')
  491. ->take(3)->get()
  492. ),
  493. array(
  494. 'name' => 'Schlechtbewertetster Film',
  495. 'entr' => array('', ''),
  496. 'prop' => 'objekt',
  497. 'type' => 'Film',
  498. 'vals' => Comment::addSelect(DB::raw('film_comments.*, film_films.*, ROUND(AVG(`bewertung`),1) as count'))
  499. ->leftJoin('films', 'films.id', '=', 'comments.film')->whereNotNull('gesehen')
  500. ->where('bewertung', '>', 0)->groupBy('film')->orderBy('count', 'ASC')
  501. ->take(3)->get()
  502. ),
  503. array(
  504. 'name' => 'Bestbewertetster Film',
  505. 'entr' => array('', ''),
  506. 'prop' => 'objekt',
  507. 'type' => 'Film',
  508. 'vals' => Comment::addSelect(DB::raw('film_comments.*, film_films.*, ROUND(AVG(`bewertung`),1) as count'))
  509. ->leftJoin('films', 'films.id', '=', 'comments.film')->whereNotNull('gesehen')
  510. ->where('bewertung', '>', 0)->groupBy('film')->orderBy('count', 'DESC')
  511. ->take(3)->get()
  512. ),
  513. ];
  514. return View::make('stats')->with('stats', $stats);
  515. });