First version almost done
This commit is contained in:
parent
b5c1f40a45
commit
7a33f5f889
14 changed files with 274 additions and 28 deletions
|
|
@ -3,8 +3,47 @@
|
|||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use DB;
|
||||
|
||||
class Tipp extends Model
|
||||
{
|
||||
//
|
||||
protected $fillable = [
|
||||
'id', 'user_id', 'game_id','score1','score2','joker'
|
||||
];
|
||||
|
||||
public static function getTipp($game_id, $user_id) {
|
||||
return DB::table('tipps')->where([
|
||||
['user_id','=',$user_id],
|
||||
['game_id','=',$game_id]
|
||||
])->first();
|
||||
}
|
||||
|
||||
public static function getScore($tipp_id) {
|
||||
$tipp = Tipp::where('id',$tipp_id)->first();
|
||||
$game = Game::where('id',$tipp->game_id)->first();
|
||||
|
||||
$tippTendenz = $tipp->score1 - $tipp->score2;
|
||||
if ($tippTendenz > 0) {$tippTendenz=1;}
|
||||
if ($tippTendenz < 0) {$tippTendenz=-1;}
|
||||
|
||||
$gameTendenz = $game->score1 - $game->score2;
|
||||
if ($gameTendenz<0) {$gameTendenz=-1;}
|
||||
if ($gameTendenz>0) {$gameTendenz=1;}
|
||||
|
||||
$score=0;
|
||||
|
||||
if ($tippTendenz == $gameTendenz) { $score=1; }
|
||||
|
||||
if ( ($tipp->score1 == $game->score1) && ($tipp->score2 == $game->score2) ) {
|
||||
$score=2;
|
||||
}
|
||||
|
||||
if ($tipp->joker==true) {
|
||||
$score = $score *2;
|
||||
}
|
||||
|
||||
if ($game->score1 == -1) { $score=0; }
|
||||
|
||||
return $score;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue