Sommer Style, Avatare, Duplikate

This commit is contained in:
2015-10-21 07:02:29 +02:00
parent 62d4c32d53
commit 0de0eefa37
10 changed files with 475 additions and 392 deletions

View File

@@ -23,4 +23,34 @@ class Film extends Eloquent {
return $query->whereNull('gesehen')->orderBy('updated_at', 'DESC')->take(5);
}
public function scopeMeistgewunschteVorschlage($query) {
$nextfilm = Dumbo::find(1)->film;
return $query
->addSelect(DB::raw('film_films.*, COUNT(case when film_votes.stimme IS TRUE then 1 end) as upvotes'))
->leftJoin('votes', 'votes.film', '=', 'films.id')
->whereNull('gesehen')
->where('films.id', "!=", is_object($nextfilm) ? $nextfilm->id : 0)
->groupBy('films.id')
->orderBy('upvotes', 'DESC')
->orderBy('vorgeschlagen', 'ASC')
->take(5);
}
public function getVotes() {
return Vote::where('film', '=', $this->id)->count();
}
public function getUpvotes() {
return Vote::where('film', '=', $this->id)->whereRaw('stimme IS TRUE')->count();
}
public function getBewertung() {
if(!is_null($this->gesehen)) {
$count = Comment::where('film', $this->id)->where('bewertung', '>', 0)->count();
return $count > 0 ? Comment::where('film', $this->id)->where('bewertung', '>', 0)->sum('bewertung') / $count : 0;
} else return (0);
}
}