Browse Source

+Bewertungen, Meistgewünschter Film, Sortierung nach Votes

Daniel Müllers 10 years ago
parent
commit
fb74d68046

+ 55 - 0
app/database/migrations/2013_09_26_022825_comments_settings.php

@@ -0,0 +1,55 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+
+class CommentsSettings extends Migration {
+
+	/**
+	 * Run the migrations.
+	 *
+	 * @return void
+	 */
+	public function up()
+	{
+		Schema::table('comments', function($table) {
+			$table->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');
+	}
+
+}

+ 0 - 5
app/models/Event.php

@@ -1,5 +0,0 @@
-<?php
-
-class Event extends Eloquent {
-	protected $table = "events";
-}

+ 2 - 2
app/models/Film.php

@@ -20,7 +20,7 @@ class Film extends Eloquent {
 	}
 
 	public function scopeNeuesteVorschlage($query) {
-		return $query->whereNull('gesehen')->orderBy('updated_at')->take(5);
+		return $query->whereNull('gesehen')->orderBy('updated_at', 'DESC')->take(5);
 	}
-	
+
 }

+ 14 - 0
app/models/News.php

@@ -0,0 +1,14 @@
+<?php
+
+class News extends Eloquent {
+	protected $table = "news";
+
+	public function ersteller() {
+		return $this->belongsTo('User', 'author');
+	}
+
+	public function scopeAktuell($query) {
+		return $query->orderBy('updated_at', 'DESC')->take(5);
+	}
+	
+}

+ 4 - 0
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');
+	}
 }

+ 73 - 3
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!');
+	}
+}));

+ 39 - 2
app/views/film.blade.php

@@ -52,8 +52,17 @@
 					@endforeach
 				</dd>
 				<dt>Bewertung</dt>
-				<dd>{{ $tfilm['vote_average']}} von 10 
-				</dd>
+				<dd>{{ $tfilm['vote_average']}} von 10 </dd>
+				@if(!is_null($film->gesehen) && Comment::where('film', $film->id)->where('bewertung', '>', 0)->count() > 0)
+					<dt>Eigene Bewertung</dt>
+					<dd>
+						<?php
+							$count = Comment::where('film', $film->id)->where('bewertung', '>', 0)->count();
+							$avg = Comment::where('film', $film->id)->where('bewertung', '>', 0)->sum('bewertung') / $count;
+						?>
+						<div class="label label-{{$labels[round($avg)]}}">{{$avg}}</div>
+					</dd>
+				@endif
 				@for($i = 0; $i < 3 && $i < count($cast['crew']); $i++)
 					<dt>{{$cast['crew'][$i]['job']}}</dt>
 					<dd>{{$cast['crew'][$i]['name']}}</dd>
@@ -132,6 +141,17 @@
 	<div class="media-body">
 		<h4 class="media-heading">Neuer Kommentar</h4>
 		{{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 )
+				<p><div class="pull-left" style="margin-right: 5px">Bewerten:</div>
+					<div class="btn-group btn-group-xs" data-toggle="buttons">
+						@for($i = 1; $i < 11; $i++)
+						<label class="btn btn-{{ $labels[$i] }}">
+							<input type="radio" name="rate" id="rate{{ $i }}" value="{{ $i }}"> {{ $i }}
+						</label>
+						@endfor
+					</div>
+				</p>
+			@endif
 			<input type="hidden" name="user" value="{{Auth::user()->id}}">
 			<input type="hidden" name="film" value="{{$film->id}}">
 			<div class="form-group"><textarea class="form-control" rows="1" name="text"></textarea></div>
@@ -155,11 +175,25 @@
 		</small></h5>
 		@if(!is_null(Auth::user()) && Auth::user()->id === $comment->autor->id)
 		<div class="collapse in" data-parent="#comment{{$comment->id}}" id="comment{{$comment->id}}comment">
+			@if($comment->bewertung > 0)
+			<div class="pull-left label label-{{ $labels[$comment->bewertung] }}"  style="margin-right: 5px;">{{$comment->bewertung}}</div>
+			@endif
 			<p>{{$comment->text}}</p>
 			<button type="button" class="btn btn-xs" onclick="toggleComment('#comment{{$comment->id}}')">Bearbeiten</button>
 		</div>
 		<div class="collapse" id="comment{{$comment->id}}edit">
 			{{Form::open(array('route' => 'modcomment'))}}
+				@if($comment->bewertung > 0)
+					<p><div class="pull-left" style="margin-right: 5px">Bewerten:</div>
+						<div class="btn-group btn-group-xs" data-toggle="buttons">
+							@for($i = 1; $i < 11; $i++)
+							<label class="btn btn-{{ $labels[$i] }}">
+								<input type="radio" name="rate" id="rate{{ $i }}" value="{{ $i }}"> {{ $i }}
+							</label>
+							@endfor
+						</div>
+					</p>
+				@endif
 				<input type="hidden" name="id" value="{{$comment->id}}">
 				<div class="form-group"><textarea class="form-control" rows="1" name="text">{{$comment->text}}</textarea></div>
 				<div class="form-group">
@@ -169,6 +203,9 @@
 			{{Form::close()}}
 		</div>
 		@else
+		@if($comment->bewertung > 0)
+			<div class="pull-left label label-{{ $labels[$comment->bewertung] }}" style="margin-right: 5px;">{{$comment->bewertung}}</div>
+		@endif
 		<p>{{$comment->text}}</p>
 		@endif
 	</div>

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

@@ -36,6 +36,7 @@
 							<li>{{ HTML::link('settings', 'Passwort &amp; Email &auml;ndern')}}</li>
 							@if(Auth::user()->admin)
 							<li>{{ HTML::link('users', 'Benutzerverwaltung')}}</li>
+							<li>{{ HTML::link('news', 'News erstellen')}}</li>
 							@endif
 							<li class="divider"></li>
 							<li>{{ HTML::link('logout', "Logout")}}

+ 33 - 4
app/views/index.blade.php

@@ -1,10 +1,39 @@
 @extends('hello');
 
 @section('content')
-<div class="jumbotron">
-	<div class="container">
-		<h1>Willkommen zu Dumbo</h1>
-		<p>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 <a href="http://laravel.com">Laravel 4</a> und <a href="http://getbootstrap.com">Twitter Bootstrap 3</a> auf. Die Filmdetails werden von <a href="http://themoviedb.org">themoviedb.org</a> bezogen.</p>
+<div class="row">
+	<div class="col-md-6">
+		<div class="panel panel-default">
+			<div class="panel-heading">Meistgew&uuml;nschter Film</div>
+			<div class="panel-body">
+				<img src="{{$image}}" class="pull-left thumbnail" style="max-height: 100px; margin-right: 15px;">
+				<h4>{{$topfilm->name}}</h4>
+				<p><span class="glyphicon glyphicon-thumbs-up"></span>&nbsp;{{$topfilm->upvotes}} 
+					<span class="glyphicon glyphicon-thumbs-down"></span>&nbsp;{{$topfilm->downvotes}}</p>
+			</div>
+
+			<div class="list-group">
+				{{ link_to_route('film', "Filmdetails", array($topfilm->id), array('class' => 'list-group-item'))}}
+			</div>
+		</div>
+	</div>
+
+	<div class="col-md-6">
+		<div class="panel-group" id="accordion">
+			@foreach ($news as $new)
+				<div class="panel panel-warning">
+					<div class="panel-heading">
+						<h4 class="panel-title">
+							<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#news{{$new->id}}">{{$new->headline}}</a>
+							<small>{{$new->ersteller->name}} - {{\Carbon\Carbon::parse($new->updated_at)->format('d.m.Y')}}</small>
+						</h5>
+					</div>
+					<div id="news{{$new->id}}" class="panel-collapse collapse">
+						<div class="panel-body">{{nl2br(htmlentities($new->body))}}</div>
+					</div>
+				</div>					
+			@endforeach	
+		</div>
 	</div>
 </div>
 

+ 39 - 0
app/views/news.blade.php

@@ -0,0 +1,39 @@
+@extends('hello')
+
+@section('content')
+<div class="container" style="margin-top: 40px;">
+	<div class="row">
+		<div class="col-md-8 col-md-offset-2">
+			<div class="panel panel-default">
+				<div class="panel-heading"><h2 class="panel-title">News erstellen</h2></div>
+				<div class="panel-body">
+					{{Form::open(array('url' => 'news'))}}
+						@if(count($errors->all()) > 0)
+							<div class="alert alert-danger alert-dismissable">
+								<button type="button" class="close" data-dismiss="alert">&times;</button>
+								Es müssen beide Felder ausgefüllt werden!
+							</div>
+						@endif
+						<div class="input-group form-group <?php if($errors->has('headline')) echo "has-error" ?>">
+							<span class="input-group-addon">
+								<span class="glyphicon glyphicon-paperclip"></span>
+							</span>
+							<input type="text" class="form-control" name="headline" placeholder="&Uuml;berschrift" <?php if(!is_null(Input::get('headline'))) echo "value='" . Input::get('headline') . "'"; ?>>
+						</div>
+						<div class="form-group  <?php if($errors->has('email')) echo "has-error" ?>">
+							<textarea class="form-control" name="body" placeholder="Nachricht"><?php if(!is_null(Input::get('body'))) echo Input::get('body') . "'"; ?></textarea>
+						</div>
+						<div class="form-group">
+							<button type="submit" class="btn btn-primary">Absenden</button>
+						</div>
+					{{ Form::close() }}
+				</div>
+			</div>
+		</div>
+	</div>
+</div>
+@stop
+
+@section('title')
+News erstellen ~ 
+@stop

+ 4 - 4
app/views/suggest.blade.php

@@ -17,20 +17,20 @@
 		<td>{{ HTML::link('film/' . $film->id, $film->name) }}</td>
 		<td>
 			<?php 
-				$vp = $film->votes()->where('stimme', true)->count(); 
-				$np = $film->votes()->where('stimme', false)->count();
+				$vp = $film->upvotes; 
+				$np = $film->downvotes;
 			?>
 			<div class="progress tooltip-enable" data-toggle="tooltip" title="{{ $vp }}/{{ $np }}">
   				<div class="progress-bar progress-bar-success" style="width: <?php if(($vp + $np) > 0) echo ($vp / ($vp + $np)  * 100); else echo 0; ?>%">
     				<span class="sr-only">{{$vp}} von {{$vp + $np}} (daf&uuml;r)</span>
   				</div>
-  				<div class="progress-bar progress-bar-danger" style="width: <?php if(($vp + $np) > 0) echo ($vp / ($vp + $np)  * 100); else echo 0; ?>%">
+  				<div class="progress-bar progress-bar-danger" style="width: <?php if(($vp + $np) > 0) echo ($np / ($vp + $np)  * 100); else echo 0; ?>%">
     				<span class="sr-only">{{$np}} von {{$vp + $np}} (dagegen)</span>
   				</div>
 			</div>
 		</td>
 		<td>{{ \Carbon\Carbon::parse($film->vorgeschlagen)->format('d.m.Y')}}</td>
-		<td>{{ $film->besitzer->name }}</td>
+		<td>{{ Film::find($film->id)->besitzer->name }}</td>
 	</tr>
 @endforeach
 </table>