diff --git a/app/database/migrations/2013_09_26_022825_comments_settings.php b/app/database/migrations/2013_09_26_022825_comments_settings.php new file mode 100644 index 0000000..d26b9f2 --- /dev/null +++ b/app/database/migrations/2013_09_26_022825_comments_settings.php @@ -0,0 +1,55 @@ +integer('bewertung'); + $table->dropColumn('event'); + + }); + + Schema::create('news', function($table) { + $table->increments('id'); + $table->integer('author'); + $table->string('headline'); + $table->text('body'); + $table->timestamps(); + }); + + Schema::drop('events'); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('comments', function($table) { + $table->dropColumn('bewertung'); + $table->integer('event'); + }); + + Schema::create('events', function($table) { + $table->increments('id'); + $table->string('name'); + $table->date('datum'); + $table->text('beschreibung'); + $table->timestamps(); + }); + + Schema::drop('news'); + } + +} \ No newline at end of file diff --git a/app/models/Event.php b/app/models/Event.php deleted file mode 100644 index ff04865..0000000 --- a/app/models/Event.php +++ /dev/null @@ -1,5 +0,0 @@ -whereNull('gesehen')->orderBy('updated_at')->take(5); + return $query->whereNull('gesehen')->orderBy('updated_at', 'DESC')->take(5); } - + } \ No newline at end of file diff --git a/app/models/News.php b/app/models/News.php new file mode 100644 index 0000000..fcc1297 --- /dev/null +++ b/app/models/News.php @@ -0,0 +1,14 @@ +belongsTo('User', 'author'); + } + + public function scopeAktuell($query) { + return $query->orderBy('updated_at', 'DESC')->take(5); + } + +} \ No newline at end of file diff --git a/app/models/User.php b/app/models/User.php index cf043ed..330d0a8 100644 --- a/app/models/User.php +++ b/app/models/User.php @@ -63,4 +63,8 @@ class User extends Eloquent implements UserInterface, RemindableInterface { public function votes() { return $this->hasMany('Vote', 'user'); } + + public function news() { + return $this->hasMany('News', 'author'); + } } \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index 95e1407..c9e5db5 100644 --- a/app/routes.php +++ b/app/routes.php @@ -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!'); + } +})); \ No newline at end of file diff --git a/app/views/film.blade.php b/app/views/film.blade.php index fbecdc1..2b42ab7 100644 --- a/app/views/film.blade.php +++ b/app/views/film.blade.php @@ -52,8 +52,17 @@ @endforeach
{{$comment->text}}
{{$comment->text}}
@endifDumbo ist der Arbeitstitel für eine kleine Software, die helfen soll Filme für den Filmabend auszuwählen. Um den Programmieraufwand klein zu halten, baut Dumbo auf Laravel 4 und Twitter Bootstrap 3 auf. Die Filmdetails werden von themoviedb.org bezogen.
+{{$topfilm->upvotes}} + {{$topfilm->downvotes}}
+