Browse Source

Added abgelehnt feature, fixed counting up/downvotes on landing page and movies by date page

Sebastian Uharek 3 years ago
parent
commit
b03397d1dc

+ 35 - 0
app/database/migrations/2021_02_22_232450_add_abgelehnt_to_film.php

@@ -0,0 +1,35 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddAbgelehntToFilm extends Migration {
+
+	/**
+	 * Run the migrations.
+	 *
+	 * @return void
+	 */
+	public function up()
+	{
+		Schema::table('films', function(Blueprint $table)
+		{
+			$table->date('abgelehnt')->nullable();
+		});
+	}
+
+	/**
+	 * Reverse the migrations.
+	 *
+	 * @return void
+	 */
+	public function down()
+	{
+		Schema::table('films', function(Blueprint $table)
+		{
+			$table->dropColumn('abgelehnt');
+			//
+		});
+	}
+
+}

+ 16 - 4
app/models/Film.php

@@ -16,11 +16,15 @@ class Film extends Eloquent {
 	}
 
 	public function scopeZuletztGesehen($query) {
-		return $query->whereNotNull('gesehen')->orderBy('gesehen', 'DESC')->take(5);
+		return $query->whereNull('abgelehnt')->whereNotNull('gesehen')->orderBy('gesehen', 'DESC')->take(5);
+	}
+
+	public function scopeZuletztAbgelehnt($query) {
+		return $query->whereNull('gesehen')->whereNotNull('abgelehnt')->orderBy('abgelehnt', 'DESC')->take(5);
 	}
 
 	public function scopeNeuesteVorschlage($query) {
-		return $query->whereNull('gesehen')->orderBy('updated_at', 'DESC')->take(5);
+		return $query->whereNull('gesehen')->whereNull('abgelehnt')->orderBy('updated_at', 'DESC')->take(5);
 	}
 
     public function scopeMeistgewunschteVorschlage($query) {
@@ -30,6 +34,7 @@ class Film extends Eloquent {
             ->leftJoin('votes', 'votes.film', '=', 'films.id')
             ->leftJoin('users', 'users.id', '=', 'votes.user')
             ->whereNull('gesehen')
+            ->whereNull('abgelehnt')
             ->where('films.id', "!=", is_object($nextfilm) ? $nextfilm->id : 0)
             ->where('users.settings', 'NOT LIKE', '%disabled":true%')
             ->groupBy('films.id')
@@ -38,11 +43,18 @@ class Film extends Eloquent {
     }
 
 	public function getVotes() {
-        return Vote::where('film', '=', $this->id)->count();
+        return Vote::where('film', '=', $this->id)
+                                             ->where('users.settings', 'NOT LIKE', '%disabled":true%')
+                                             ->leftJoin('users', 'users.id', '=', 'votes.user')
+                                             ->count();
     }
 
     public function getUpvotes() {
-        return Vote::where('film', '=', $this->id)->whereRaw('stimme IS TRUE')->count();
+        return Vote::where('film', '=', $this->id)
+                                             ->whereRaw('stimme IS TRUE')
+                                             ->where('users.settings', 'NOT LIKE', '%disabled":true%')
+                                             ->leftJoin('users', 'users.id', '=', 'votes.user')
+                                             ->count();
     }
 
     public function getBewertung() {

+ 43 - 4
app/routes.php

@@ -15,6 +15,7 @@
 Route::get('/', function()
 {
     $gesehen = Film::zuletztGesehen()->get();
+    $abgelehnt = Film::zuletztAbgelehnt()->get();
     $vorgeschlagen = Film::neuesteVorschlage()->get();
     $mg = Film::meistgewunschteVorschlage()->take(5)->get();
     //$x = DB::getQueryLog();
@@ -24,7 +25,7 @@ Route::get('/', function()
     $nextfilm = Dumbo::find(1)->film;
 
     $tmdb = new TMDb(Config::get('constants.tvdb.apikey'), 'de', TRUE, TMDb::API_SCHEME_SSL);
-    foreach(array("top" => $mg[0], "neu" => $vorgeschlagen[0], "alt" => $gesehen[0]) as $key => $val) {
+    foreach(array("top" => $mg[0], "neu" => $vorgeschlagen[0], "alt" => $gesehen[0], "declined" => $abgelehnt[0]) as $key => $val) {
         $tmovie = $tmdb->getMovie($val->tvdbid);
         $images[$key] = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
     }
@@ -42,6 +43,7 @@ Route::get('/', function()
 
     return View::make('index')
         ->with('gesehen', $gesehen)
+        ->with('abgelehnt', $abgelehnt)
         ->with('vorgeschlagen', $vorgeschlagen)
         ->with('meistgw', $mg)
         ->with('images', $images)
@@ -177,7 +179,10 @@ Route::get('vorgeschlagen', function() {
 		COUNT(case when film_votes.stimme IS FALSE then 1 end) as downvotes,
 		COUNT(case when film_votes.stimme IS TRUE then 1 end) as vcount'))
         ->leftJoin('votes', 'votes.film', '=', 'films.id')
+        ->leftJoin('users', 'users.id', '=', 'votes.user')
         ->whereNull('films.gesehen')
+        ->whereNull('films.abgelehnt')
+        ->where('users.settings', 'NOT LIKE', '%disabled":true%')
         ->groupBy('id')
         ->orderBy('vorgeschlagen', 'DESC')
         ->paginate(25);
@@ -188,6 +193,16 @@ Route::get('vorgeschlagen', function() {
 
 });
 
+Route::get('abgelehnt/{field?}/{order?}', function($field = "abgelehnt", $order = "desc") {
+    $filme = Film::whereNotNull('abgelehnt')->orderBy($field, $order)->paginate(25);
+    $labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success");
+
+    return View::make('abgelehnt')
+        ->with('labels', $labels)
+        ->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(25);
     $labels = array("", "danger", "danger", "warning", "warning", "info", "info", "primary", "primary", "success", "success");
@@ -212,7 +227,7 @@ Route::post('neu', array('before' => 'auth', function() {
 }));
 
 Route::get('vorschlag/{id}', array('before' => 'auth', function($id) {
-    $ef = Film::where('tvdbid', '=', $id)->whereNull('gesehen')->first();
+    $ef = Film::where('tvdbid', '=', $id)->whereNull('gesehen')->whereNull('abgelehnt')->first();
     if(is_null($ef)) {
         $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
         $f = $tmdb->getMovie($id);
@@ -225,11 +240,27 @@ Route::get('vorschlag/{id}', array('before' => 'auth', function($id) {
         Session::put('message', 'Film hinzugefügt.');
         return Redirect::to('film/' . $film->id);
     } else {
-        Session::put('message', 'Film bereits vorgeschlagen von ' . $ef->besitzer->name . '.');
+        if(is_null($ef->abgelehnt)) {
+            Session::put('message', 'Film bereits vorgeschlagen von ' . $ef->besitzer->name . '.');
+        } else {
+            Session::put('message', 'Film bereits abgelehmt.'); 
+        }
         return Redirect::to('film/' . $ef->id);
     }
 }));
 
+Route::get('mark-declined/{id}', array('before' => 'auth', function($id) {
+    $film = Film::findOrFail($id);
+    $film->abgelehnt = \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('mark-read/{id}', array('before' => 'auth', function($id) {
     $film = Film::findOrFail($id);
     $film->gesehen = \Carbon\Carbon::today();
@@ -485,6 +516,14 @@ Route::get('stats', function() {
             'prop' => 'besitzer',
             'type' => 'User'
         ),
+        array(
+            'name' => 'Meiste abgelehnte Vorschl&auml;ge',
+            'entr' => array('Vorschlag', 'Vorschl&auml;ge'),
+            'vals' => Film::addSelect(DB::raw("film_films.*, COUNT(`id`) as count"))
+                ->whereNotNull('abgelehnt')->groupBy('user')->orderBy('count', 'DESC')->take(3)->get(),
+            'prop' => 'besitzer',
+            'type' => 'User'
+        ),
 
         array(
             'name' => 'Meiste Kommentare',
@@ -563,4 +602,4 @@ Route::get('stats', function() {
     ];
 
     return View::make('stats')->with('stats', $stats);
-});
+});

+ 56 - 0
app/views/abgelehnt.blade.php

@@ -0,0 +1,56 @@
+@extends('hello')
+
+@section('content')
+<div class="page-header"><h1>Abgelehnt</h1></div>
+
+{{ $filme->links() }}
+
+<table class="table">
+	<tr>
+		<th>Titel</th>
+        <th></th>
+		<th>Abgelehnt am</th>
+		<th>Vorgeschlagen von</th>
+    </tr>
+@foreach($filme as $film)
+        <?php
+        $stimme = 2;
+        if(!is_null(Auth::user()) && Vote::where('film', $film->id)->where('user', Auth::user()->id)->count())
+            $stimme = Vote::where('film', $film->id)->where('user', Auth::user()->id)->first()->stimme;
+        ?>
+	<tr>
+		<td>{{ HTML::link('film/' . $film->id, $film->name) }}</td>
+        <td>
+            <span class="glyphicon glyphicon-comment"></span> {{ $film->comments()->count()}}
+            @if($film->getBewertung() > 0)
+                &nbsp;<span class="label label-{{$labels[round($film->getBewertung())]}}">{{$film->getBewertung()}}</span>
+            @endif
+            @if($stimme == 1)
+                &nbsp;<span class="label label-success tooltip-enable" data-toggle="tooltip" title="Daf&uuml;r gestimmt."><span class="glyphicon glyphicon-thumbs-up"></span></span>
+            @elseif($stimme == 0)
+                &nbsp;<span class="label label-default tooltip-enable"  data-toggle="tooltip" title="Nicht daf&uuml;r gestimmt."><span class="glyphicon glyphicon-hand-right"></span></span>
+            @endif
+        </td>
+		<td>{{ \Carbon\Carbon::parse($film->abgelehnt)->format('d.m.Y')}}</td>
+		<td><span class="badge">
+						<img class="img-circle pull-left" src="{{ $film->besitzer->getAvatar() }}" width="20"> {{$film->besitzer->name}}
+					</span></td>
+	</tr>
+@endforeach
+</table>
+
+{{ $filme->links() }}
+
+@stop
+
+@section('title')
+Gesehen ~
+@stop
+
+@section('script')
+<script type="text/javascript">
+	$(function() {
+		$('.tooltip-enable').tooltip({ html: true, placement: "bottom" });
+	});
+</script>
+@stop

+ 5 - 3
app/views/film.blade.php

@@ -9,6 +9,8 @@
 	<div class="col-md-3">
 		@if(!is_null($film->gesehen))
 			<div class="label label-success"><span class="glyphicon glyphicon-check"></span> Gesehen am {{ \Carbon\Carbon::parse($film->gesehen)->format('d.m.Y') }}</div>
+		@elseif(!is_null($film->abgelehnt))
+			<div class="label label-warning"><span class="glyphicon glyphicon-remove"></span> Abgelehnt am {{ \Carbon\Carbon::parse($film->abgelehnt)->format('d.m.Y') }}</div>
 		@else
 			<div class="label label-danger" <?php if(!is_null(Auth::user()) && Auth::user()->admin) { echo "id='gesehen'"; } ?> style="cursor: pointer;"><span class="glyphicon glyphicon-unchecked"></span> Nicht gesehen</div>
 		@endif
@@ -98,7 +100,7 @@
 
 <div class="clearfix"></div>
 <hr>
-@if($votes > 0 || is_null($film->gesehen))
+@if($votes > 0 || is_null($film->gesehen) || is_null($film->abgelehnt))
 @if($votes > 0)
 <h2>Abstimmung</h2>
 <p>Insgesamt haben <b>{{$votes}}</b> Personen abgestimmt. <b>{{$vposi}}</b> davon waren <i>daf&uuml;r</i>. @if($uvote[0])
@@ -127,7 +129,7 @@
 
 
 @endif
-@if(is_null($film->gesehen) && !is_null(Auth::user()))
+@if(is_null($film->gesehen) && is_null($film->abgelehnt) && !is_null(Auth::user()))
 <div class="container" style="text-align: center">
 	<div class="btn-group">
 		<a class="btn btn-lg btn-success <?php echo $uvote[0] && $uvote[1] ? "disabled" : ""; ?>" href="{{ url('vote', array('yes', Auth::user()->id, $film->id)) }}">
@@ -245,7 +247,7 @@
 			placement: "right",
 			trigger: "click",
 			title: "Als gesehen markieren",
-			content: "<div class='container'><a href='{{ url('mark-read/' . $film->id) }}' class='btn btn-success'>Gesehen</a><a href='{{ url('view-next/' . $film->id) }}' class='btn btn-warning'>Als n&auml;chstes sehen</a></div>"
+			content: "<div class='container'><a href='{{ url('mark-read/' . $film->id) }}' class='btn btn-success'>Gesehen</a><a href='{{ url('view-next/' . $film->id) }}' class='btn btn-warning'>Als n&auml;chstes sehen</a><a href='{{ url('mark-declined/' . $film->id) }}' class='btn btn-danger'>Ablehnen</a></div>"
 		});
 	});
 </script>

+ 1 - 0
app/views/hello.blade.php

@@ -22,6 +22,7 @@
 					<li>{{ HTML::link('beliebt', 'Beliebt (Wertung)') }}</li>
 					<li>{{ HTML::link('vorgeschlagen', 'Vorgeschlagen (Datum)') }}</li>
 					<li>{{ HTML::link('gesehen', 'Gesehen') }}</li>
+					<li>{{ HTML::link('abgelehnt', 'Abgelehnt') }}</li>
 					<li>{{ HTML::link('neu', 'Film vorschlagen')}}</li>
 					<li>{{ HTML::link('stats', 'Statistiken') }}</li>
 				</ul>

+ 28 - 0
app/views/index.blade.php

@@ -105,6 +105,34 @@
 				<i>{{ link_to('gesehen', 'Mehr...', array('class' => 'list-group-item')); }}</i>
 			</div>
 		</div>
+		<div class="panel panel-warning">
+			<div class="panel-heading">Abgelehnte Filme</div>
+			<div class="panel-body">
+				<?php $topfilm = $abgelehnt->shift(); ?>
+				<img src="{{$images["declined"]}}" class="pull-left thumbnail" style="max-height: 100px; margin-right: 15px;">
+				<h4>{{$topfilm->name}}
+					<small><span class="badge">
+						<img class="img-circle" src="{{ $topfilm->besitzer->getAvatar() }}" width="20"> {{$topfilm->besitzer->name}}
+					</span></small></h4>
+				<p>Bewertung:
+					@if($topfilm->getBewertung() > 0)
+						<span class="label label-{{$labels[round($topfilm->getBewertung())]}}">{{$topfilm->getBewertung()}}</span>
+						@else
+						&mdash;
+					@endif
+				</p>
+				<p>{{ link_to_route('film', "Filmdetails", array($topfilm->id), array('class' => 'btn btn-info btn-xs'))}}</p>
+			</div>
+
+			<div class="list-group">
+				@foreach ($abgelehnt as $film)
+					<a href="{{ route('film', array($film->id)); }}" class="list-group-item">{{$film->name}} <small><span class="badge">
+						<img class="img-circle" src="{{ $film->besitzer->getAvatar() }}" width="16"> {{$film->besitzer->name}}
+					</span></small></a>
+				@endforeach
+				<i>{{ link_to('abgelehnt', 'Mehr...', array('class' => 'list-group-item')); }}</i>
+			</div>
+		</div>
 	</div>
 
 	<div class="col-md-6">