2017-06-20 08:43:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-06-22 17:00:09 +02:00
|
|
|
use DB;
|
2017-06-20 08:43:36 +02:00
|
|
|
|
|
|
|
|
class Tipp extends Model
|
|
|
|
|
{
|
2017-06-22 17:00:09 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2017-06-20 08:43:36 +02:00
|
|
|
}
|