get();
$vorgeschlagen = Film::neuesteVorschlage()->get();
$news = News::aktuell()->get();
$nextfilm = Dumbo::find(1)->film;
$topfilm = DB::table(DB::raw('film_films'))
->select(DB::raw('film_films.*, COUNT(case when film_votes.stimme IS TRUE then 1 end) as upvotes,
COUNT(case when film_votes.stimme IS FALSE then 1 end) as downvotes,
COUNT(case when film_votes.stimme IS TRUE then 1 end) - COUNT(case when film_votes.stimme IS FALSE then 1 end) as vcount'))
->leftJoin('votes', 'votes.film', '=', 'films.id')
->whereNull('films.gesehen')
->where('films.id', "!=", is_object($nextfilm) ? $nextfilm->id : 0)
->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');
if(is_object($nextfilm)) {
$tmovie = $tmdb->getMovie($nextfilm->tvdbid);
$nimage = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
} else {
$nimage = "http://d3a8mw37cqal2z.cloudfront.net/assets/7ea4ac6f271e37d/images/no-poster-w130.jpg";
}
$kommentare = Comment::neueste()->get();
return View::make('index')
->with('gesehen', $gesehen)
->with('vorgeschlagen', $vorgeschlagen)
->with('image', $image)
->with('nimage', $nimage)
->with('news', $news)
->with('kommentare', $kommentare)
->with('nextfilm', $nextfilm)
->with('topfilm', $topfilm);
});
Route::get('film/{id}', array('as' => 'film', function($id) {
$film = Film::findOrFail($id);
$tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
$tmovie = $tmdb->getMovie($film->tvdbid);
$tcast = $tmdb->getMovieCast($film->tvdbid);
$ttrail = $tmdb->getMovieTrailers($film->tvdbid);
$image = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
$votes = $film->votes()->count();
$vposi = $film->votes()->where('stimme', true)->count();
$pv = "";
foreach($film->votes()->where('stimme', true)->get() as $v) {
$pv .= $v->voter->name . "
";
}
$nv = "";
foreach($film->votes()->where('stimme', false)->get() as $v) {
$nv .= $v->voter->name . "
";
}
if(!is_null(Auth::user()) && $film->votes()->where('user', Auth::user()->id)->count() > 0) {
$uvote[0] = true;
$uvote[1] = $film->votes()->where('user', Auth::user()->id)->first()->stimme;
} else {
$uvote[0] = false;
}
$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)
->with('poster', $image)
->with('comments', $comments)
->with('cast', $tcast)
->with('trail', $ttrail)
->with('votes', $votes)
->with('uvote', $uvote)
->with('pv', $pv)
->with('nv', $nv)
->with('vposi', $vposi)
->with('labels', $labels)
->with('tmdb', $tmdb);
}));
Route::get('vote/{stimme}/{user}/{film}', function($stimme, $user, $film) {
$v = Vote::where('user', $user)->where('film', $film)->first();
if(!is_null($v)) {
$v->stimme = $stimme == "yes" ? true : false;
} else {
$v = new Vote();
$v->user = $user;
$v->film = $film;
$v->stimme = $stimme == "yes" ? true : false;
}
$v->save();
return Redirect::to('film/' . $film);
});
Route::post('comment', array('as' => 'comment', function() {
$c = new Comment();
$c->film = Input::get('film');
$c->user = Input::get('user');
$c->text = Input::get('text');
$c->bewertung = !is_null(Input::get('rate')) ? Input::get('rate') : 0;
$c->save();
return Redirect::to('film/' . Input::get('film'));
}));
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);
}));
Route::get('login', array('as' => 'login', function() {
return View::make('login');
}));
Route::post('login', function() {
$userdata = array(
'name' => Input::get('user'),
'password' => Input::get('password'));
if(Auth::attempt($userdata)) {
return Redirect::intended('/');
} else {
echo "Login gescheitert.";
var_dump($userdata);
return Redirect::to('login')
->with('login_errors', true);
}
});
Route::get('logout', array('as' => 'logout', function() {
Auth::logout();
return Redirect::to('/');
}));
Route::get('vorgeschlagen', function() {
$filme = DB::table(DB::raw('film_films'))
->select(DB::raw('film_films.*, COUNT(case when film_votes.stimme IS TRUE then 1 end) as upvotes,
COUNT(case when film_votes.stimme IS FALSE then 1 end) as downvotes,
COUNT(case when film_votes.stimme IS TRUE then 1 end) - COUNT(case when film_votes.stimme IS FALSE then 1 end) as vcount'))
->leftJoin('votes', 'votes.film', '=', 'films.id')
->whereNull('films.gesehen')
->groupBy('id')
->orderBy('vcount', 'DESC')->orderBy('vorgeschlagen', 'ASC')
->paginate();
return View::make('suggest')
->with('filme', $filme);
})->where(array('field' => '[a-z]+', 'order' => 'asc|desc'));
Route::get('gesehen/{field?}/{order?}', function($field = "gesehen", $order = "desc") {
$filme = Film::whereNotNull('gesehen')->orderBy($field, $order)->paginate();
return View::make('seen')
->with('filme', $filme);
})->where(array('field' => '[a-z]+', 'order' => 'asc|desc'));
Route::get('neu', array('before' => 'auth', function() {
return View::make('new');
}));
Route::post('neu', array('before' => 'auth', function() {
$tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
$r = $tmdb->searchMovie(Input::get('search'));
return View::make('new')->with('result', $r)->with('tmdb', $tmdb);
}));
Route::get('vorschlag/{id}', array('before' => 'auth', function($id) {
$tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
$f = $tmdb->getMovie($id);
$film = new Film();
$film ->name = $f['title'];
$film->tvdbid = $id;
$film->vorgeschlagen = \Carbon\Carbon::today();
$film->user = Auth::user()->id;
$film->save();
return Redirect::to('film/' . $film->id);
}));
Route::get('mark-read/{id}', array('before' => 'auth', function($id) {
$film = Film::findOrFail($id);
$film->gesehen = \Carbon\Carbon::today();
$film->save();
if(Dumbo::find(1)->nextfilm == $film->id) {
$system = Dumbo::findOrFail(1);
$system->nextfilm = 0;
$system->save();
}
return Redirect::to('film/' . $film->id);
}));
Route::get('view-next/{id}', array('before' => 'auth', function($id) {
$system = Dumbo::findOrFail(1);
$system->nextfilm = $id;
$system->save();
return Redirect::to('film/' . $id);
}));
Route::get('register', function() {
return View::make('register');
});
Route::post('register', function() {
$vrules = array(
'name' => 'required|unique:users',
'email' => 'required|email',
'password' => 'required|confirmed',
'fire' => array('required', 'regex:/^Kreis$/i')
);
$vfields = array(
'name' => Input::get('user'),
'email' => Input::get('email'),
'password' => Input::get('password'),
'password_confirmation' => Input::get('pw-confirm'),
'fire' => Input::get('fire')
);
$val = Validator::make($vfields, $vrules);
if($val->fails()) {
return View::make('register')->with('errors', $val->messages());
} else {
$u = new User();
$u->name = Input::get('user');
$u->email = Input::get('email');
$u->password = Hash::make(Input::get('password'));
$u->save();
return Redirect::to('/')->with('message', 'Registriert!');
}
});
Route::get('settings', array('before' => 'auth', function() {
return View::make('settings');
}));
Route::post('settings/{mode}', array('before' => 'auth', function($mode) {
Validator::extend('pass', function($attribute, $value, $parameters) {
return Hash::check($value, Auth::user()->password);
});
if($mode == 'password') {
var_dump(Hash::check(Input::get('oldpw'), Auth::user()->password));
$vfields = array('oldpw' => Input::get('oldpw'), 'newpw' => Input::get('newpw'), 'newpw_confirmation' => Input::get('newpw2'));
$vrules = array( 'oldpw' => 'required|pass', 'newpw' => 'required|confirmed' );
$val = Validator::make($vfields, $vrules);
if($val->passes()) {
$u = Auth::user();
$u->password = Hash::make(Input::get('newpw'));
$u->save();
return View::make('settings')->with('message', 'Passwort geändert.');
} else {
return View::make('settings')->with('errors', $val->messages());
}
}
if($mode == 'email') {
$vfields = array('pw' => Input::get('pw'), 'email' => Input::get('email'), 'email_confirmation' => Input::get('email2'));
$vrules = array('pw' => 'required|pass', 'email' => 'required|confirmed');
$val = Validator::make($vfields, $vrules);
if($val->passes()) {
$u = Auth::user();
$u->email = Input::get('email');
$u->save();
return View::make('settings')->with('message', 'Email geändert.');
} else {
return View::make('settings')->with('errors', $val->messages());
}
}
}));
Route::get('users', array('before' => 'auth', function() {
if(Auth::user()->admin) {
$u = User::orderBy('name')->paginate();
return View::make('users')->with('users', $u);
} else {
App::abort(401, 'Diese Seite ist nicht für Dich.');
}
}));
Route::get('users/{operation}/{id}', array('before' => 'auth', function($operation, $id) {
if(!Auth::user()->admin) App::abort(401, 'Diese Seite ist nicht für Dich.');
$u = User::findOrFail($id);
switch($operation) {
case 'mkadm':
$u->admin = true;
$u->save();
$msg = $u->name . " ist jetzt ein Admin.";
break;
case 'rmadm':
$u->admin = false;
$u->save();
$msg = $u->name . " ist kein Admin mehr.";
break;
case 'rmusr':
$msg = $u->name . " wurde gelöscht.";
$u->delete();
break;
}
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!');
}
}));