+Bewertungen, Meistgewünschter Film, Sortierung nach Votes
This commit is contained in:
@@ -15,9 +15,31 @@ Route::get('/', function()
|
||||
{
|
||||
$gesehen = Film::zuletztGesehen()->get();
|
||||
$vorgeschlagen = Film::neuesteVorschlage()->get();
|
||||
$news = News::aktuell()->get();
|
||||
|
||||
$topfilm = DB::table(DB::raw('film_films'))
|
||||
->select(DB::raw('film_films.*, COUNT(film_u.id) as upvotes, COUNT(film_d.id) as downvotes, COUNT(film_u.id) - COUNT(film_d.id) as vcount'))
|
||||
->leftJoin('votes as film_u', function($join) {
|
||||
$join->on('u.film', '=', 'films.id')->on('u.stimme', 'IS', DB::raw('TRUE'));
|
||||
})
|
||||
->leftJoin('votes as film_d', function($join) {
|
||||
$join->on('d.film', '=', 'films.id')->on('d.stimme', 'IS', DB::raw('FALSE'));
|
||||
})
|
||||
->whereNull('films.gesehen')
|
||||
->groupBy('id')
|
||||
->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC')
|
||||
->first();
|
||||
|
||||
$tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
|
||||
$tmovie = $tmdb->getMovie($topfilm->tvdbid);
|
||||
$image = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
|
||||
|
||||
return View::make('index')
|
||||
->with('gesehen', $gesehen)
|
||||
->with('vorgeschlagen', $vorgeschlagen);
|
||||
->with('vorgeschlagen', $vorgeschlagen)
|
||||
->with('image', $image)
|
||||
->with('news', $news)
|
||||
->with('topfilm', $topfilm);
|
||||
});
|
||||
|
||||
Route::get('film/{id}', array('as' => 'film', function($id) {
|
||||
@@ -51,6 +73,9 @@ Route::get('film/{id}', array('as' => 'film', function($id) {
|
||||
|
||||
$comments = $film->comments()->orderBy('id', 'DESC')->get();
|
||||
|
||||
|
||||
$labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success");
|
||||
|
||||
return View::make('film')
|
||||
->with('film', $film)
|
||||
->with('tfilm', $tmovie)
|
||||
@@ -63,6 +88,7 @@ Route::get('film/{id}', array('as' => 'film', function($id) {
|
||||
->with('pv', $pv)
|
||||
->with('nv', $nv)
|
||||
->with('vposi', $vposi)
|
||||
->with('labels', $labels)
|
||||
->with('tmdb', $tmdb);
|
||||
}));
|
||||
|
||||
@@ -88,6 +114,7 @@ Route::post('comment', array('as' => 'comment', function() {
|
||||
$c->film = Input::get('film');
|
||||
$c->user = Input::get('user');
|
||||
$c->text = Input::get('text');
|
||||
$c->bewertung = Input::get('rate');
|
||||
$c->save();
|
||||
return Redirect::to('film/' . Input::get('film'));
|
||||
}));
|
||||
@@ -95,6 +122,7 @@ Route::post('comment', array('as' => 'comment', function() {
|
||||
Route::post('comment/edit', array('as'=> 'modcomment', function () {
|
||||
$c = Comment::findOrFail(Input::get('id'));
|
||||
$c->text = Input::get('text');
|
||||
$c->bewertung = Input::get('rate');
|
||||
$c->save();
|
||||
return Redirect::to('film/' . $c->film);
|
||||
}));
|
||||
@@ -122,8 +150,20 @@ Route::get('logout', array('as' => 'logout', function() {
|
||||
return Redirect::to('/');
|
||||
}));
|
||||
|
||||
Route::get('vorgeschlagen/{field?}/{order?}', function($field = "vorgeschlagen", $order = "desc") {
|
||||
$filme = Film::whereNull('gesehen')->orderBy($field, $order)->paginate();
|
||||
Route::get('vorgeschlagen', function() {
|
||||
|
||||
$filme = DB::table(DB::raw('film_films'))
|
||||
->select(DB::raw('film_films.*, COUNT(film_u.id) as upvotes, COUNT(film_d.id) as downvotes, COUNT(film_u.id) - COUNT(film_d.id) as vcount'))
|
||||
->leftJoin('votes as film_u', function($join) {
|
||||
$join->on('u.film', '=', 'films.id')->on('u.stimme', 'IS', DB::raw('TRUE'));
|
||||
})
|
||||
->leftJoin('votes as film_d', function($join) {
|
||||
$join->on('d.film', '=', 'films.id')->on('d.stimme', 'IS', DB::raw('FALSE'));
|
||||
})
|
||||
->whereNull('films.gesehen')
|
||||
->groupBy('id')
|
||||
->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC')
|
||||
->paginate();
|
||||
|
||||
return View::make('suggest')
|
||||
->with('filme', $filme);
|
||||
@@ -274,3 +314,33 @@ Route::get('users/{operation}/{id}', array('before' => 'auth', function($operati
|
||||
|
||||
return Redirect::to('users')->with('message', $msg);
|
||||
}));
|
||||
|
||||
|
||||
Route::get('news', array('before' => 'auth', function() {
|
||||
return View::make('news');
|
||||
}));
|
||||
|
||||
Route::post('news', array('before' => 'auth', function() {
|
||||
$vrules = array(
|
||||
'headline' => 'required',
|
||||
'body' => 'required'
|
||||
);
|
||||
|
||||
$vfields = array(
|
||||
'headline' => Input::get('headline'),
|
||||
'body' => Input::get('body')
|
||||
);
|
||||
|
||||
$val = Validator::make($vfields, $vrules);
|
||||
|
||||
if($val->fails()) {
|
||||
return View::make('news')->with('errors', $val->messages());
|
||||
} else {
|
||||
$n = new News();
|
||||
$n->author = Auth::user()->id;
|
||||
$n->headline = Input::get('headline');
|
||||
$n->body = Input::get('body');
|
||||
$n->save();
|
||||
return Redirect::to('/')->with('message', 'News erstellt!');
|
||||
}
|
||||
}));
|
Reference in New Issue
Block a user