From fb74d6804679bf80dc59df51611061446b5b843a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCllers?= Date: Fri, 27 Sep 2013 04:06:12 +0200 Subject: [PATCH] =?UTF-8?q?+Bewertungen,=20Meistgew=C3=BCnschter=20Film,?= =?UTF-8?q?=20Sortierung=20nach=20Votes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2013_09_26_022825_comments_settings.php | 55 ++++++++++++++ app/models/Event.php | 5 -- app/models/Film.php | 4 +- app/models/News.php | 14 ++++ app/models/User.php | 4 + app/routes.php | 76 ++++++++++++++++++- app/views/film.blade.php | 41 +++++++++- app/views/hello.blade.php | 1 + app/views/index.blade.php | 37 ++++++++- app/views/news.blade.php | 39 ++++++++++ app/views/suggest.blade.php | 8 +- 11 files changed, 264 insertions(+), 20 deletions(-) create mode 100644 app/database/migrations/2013_09_26_022825_comments_settings.php delete mode 100644 app/models/Event.php create mode 100644 app/models/News.php create mode 100644 app/views/news.blade.php 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
Bewertung
-
{{ $tfilm['vote_average']}} von 10 -
+
{{ $tfilm['vote_average']}} von 10
+ @if(!is_null($film->gesehen) && Comment::where('film', $film->id)->where('bewertung', '>', 0)->count() > 0) +
Eigene Bewertung
+
+ id)->where('bewertung', '>', 0)->count(); + $avg = Comment::where('film', $film->id)->where('bewertung', '>', 0)->sum('bewertung') / $count; + ?> +
{{$avg}}
+
+ @endif @for($i = 0; $i < 3 && $i < count($cast['crew']); $i++)
{{$cast['crew'][$i]['job']}}
{{$cast['crew'][$i]['name']}}
@@ -132,6 +141,17 @@

Neuer Kommentar

{{Form::open(array('route' => 'comment'))}} + @if(!is_null(Auth::user()) && !is_null($film->gesehen) && Comment::where('user', Auth::user()->id)->where('film', $film->id)->where('bewertung', '>', 0)->count() < 1 ) +

Bewerten:
+
+ @for($i = 1; $i < 11; $i++) + + @endfor +
+

+ @endif
@@ -155,11 +175,25 @@ @if(!is_null(Auth::user()) && Auth::user()->id === $comment->autor->id)
+ @if($comment->bewertung > 0) +
{{$comment->bewertung}}
+ @endif

{{$comment->text}}

{{Form::open(array('route' => 'modcomment'))}} + @if($comment->bewertung > 0) +

Bewerten:
+
+ @for($i = 1; $i < 11; $i++) + + @endfor +
+

+ @endif
@@ -169,6 +203,9 @@ {{Form::close()}}
@else + @if($comment->bewertung > 0) +
{{$comment->bewertung}}
+ @endif

{{$comment->text}}

@endif
diff --git a/app/views/hello.blade.php b/app/views/hello.blade.php index c9766bd..9a49b5a 100644 --- a/app/views/hello.blade.php +++ b/app/views/hello.blade.php @@ -36,6 +36,7 @@
  • {{ HTML::link('settings', 'Passwort & Email ändern')}}
  • @if(Auth::user()->admin)
  • {{ HTML::link('users', 'Benutzerverwaltung')}}
  • +
  • {{ HTML::link('news', 'News erstellen')}}
  • @endif
  • {{ HTML::link('logout', "Logout")}} diff --git a/app/views/index.blade.php b/app/views/index.blade.php index 3c58bc5..5c4b230 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -1,10 +1,39 @@ @extends('hello'); @section('content') -
    -
    -

    Willkommen zu Dumbo

    -

    Dumbo 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.

    +
    +
    +
    +
    Meistgewünschter Film
    +
    + +

    {{$topfilm->name}}

    +

     {{$topfilm->upvotes}} +  {{$topfilm->downvotes}}

    +
    + +
    + {{ link_to_route('film', "Filmdetails", array($topfilm->id), array('class' => 'list-group-item'))}} +
    +
    +
    + +
    +
    + @foreach ($news as $new) +
    +
    +

    + {{$new->headline}} + {{$new->ersteller->name}} - {{\Carbon\Carbon::parse($new->updated_at)->format('d.m.Y')}} +

    +
    +
    +
    {{nl2br(htmlentities($new->body))}}
    +
    +
    + @endforeach +
    diff --git a/app/views/news.blade.php b/app/views/news.blade.php new file mode 100644 index 0000000..c301c18 --- /dev/null +++ b/app/views/news.blade.php @@ -0,0 +1,39 @@ +@extends('hello') + +@section('content') +
    +
    +
    +
    +

    News erstellen

    +
    + {{Form::open(array('url' => 'news'))}} + @if(count($errors->all()) > 0) +
    + + Es müssen beide Felder ausgefüllt werden! +
    + @endif +
    "> + + + + > +
    +
    "> + +
    +
    + +
    + {{ Form::close() }} +
    +
    +
    +
    +
    +@stop + +@section('title') +News erstellen ~ +@stop \ No newline at end of file diff --git a/app/views/suggest.blade.php b/app/views/suggest.blade.php index 36b2d97..6243cf2 100644 --- a/app/views/suggest.blade.php +++ b/app/views/suggest.blade.php @@ -17,20 +17,20 @@ {{ HTML::link('film/' . $film->id, $film->name) }} votes()->where('stimme', true)->count(); - $np = $film->votes()->where('stimme', false)->count(); + $vp = $film->upvotes; + $np = $film->downvotes; ?>
    {{$vp}} von {{$vp + $np}} (dafür)
    -
    +
    {{$np}} von {{$vp + $np}} (dagegen)
    {{ \Carbon\Carbon::parse($film->vorgeschlagen)->format('d.m.Y')}} - {{ $film->besitzer->name }} + {{ Film::find($film->id)->besitzer->name }} @endforeach