214 lines
6.5 KiB
PHP
Executable file
214 lines
6.5 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use DB;
|
|
use Carbon;
|
|
use Log;
|
|
|
|
class Tipp extends Model
|
|
{
|
|
protected $fillable = [
|
|
'id', 'user_id', 'game_id','score1','score2','joker'
|
|
];
|
|
|
|
public static function trendCol($score1, $score2, $tipp1, $tipp2, $joker) {
|
|
$tippTendenz = $tipp1 - $tipp2;
|
|
|
|
if ($tippTendenz > 0) {$tippTendenz=1;}
|
|
if ($tippTendenz < 0) {$tippTendenz=-1;}
|
|
|
|
$gameTendenz = $score1 - $score2;
|
|
if ($gameTendenz<0) {$gameTendenz=-1;}
|
|
if ($gameTendenz>0) {$gameTendenz=1;}
|
|
|
|
if ($tippTendenz!=$gameTendenz || $score1 ==-1 || $score2==-1 || $tipp1 == -1 || $tipp2==-1) {
|
|
return "";
|
|
}
|
|
|
|
$styling='background-color:grey;';
|
|
|
|
if ( ($tipp1 == $score1) && ($tipp2 == $score2) ) {
|
|
$styling='background-color:orange;';
|
|
if ($joker) {
|
|
$styling='background-color:red';
|
|
}
|
|
}
|
|
return $styling;
|
|
}
|
|
|
|
|
|
// get tendency Color
|
|
public static function getCol($user_id,$game_id) {
|
|
$tipp = Tipp::getTipp($user_id,$game_id);
|
|
$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;}
|
|
|
|
if ($tippTendenz!=$gameTendenz || $game->score1 ==-1 || $game->score2==-1 || $tipp->score1 == -1 || $tipp->score2==-1) {
|
|
return "";
|
|
}
|
|
|
|
$styling='background-color:grey;';
|
|
|
|
if ( ($tipp->score1 == $game->score1) && ($tipp->score2 == $game->score2) ) {
|
|
$styling='background-color:orange;';
|
|
if ($tipp->joker==true) {
|
|
$styling='background-color:red';
|
|
}
|
|
}
|
|
return $styling;
|
|
|
|
}
|
|
|
|
public static function getTipp( $user_id,$game_id) {
|
|
//Log::info("getTipp for game_id, user_id = ".$game_id.",".$user_id);
|
|
return DB::table('tipps')->where([
|
|
['user_id','=',$user_id],
|
|
['game_id','=',$game_id]
|
|
])->first();
|
|
}
|
|
|
|
public static function getScoreLocal($goals1, $goals2, $tipp1, $tipp2, $joker) {
|
|
$score=0;
|
|
$tippTendenz = $tipp1 - $tipp2;
|
|
if ($tippTendenz > 0) {$tippTendenz=1;}
|
|
if ($tippTendenz < 0) {$tippTendenz=-1;}
|
|
|
|
$gameTendenz = $goals1 - $goals2;
|
|
if ($gameTendenz<0) {$gameTendenz=-1;}
|
|
if ($gameTendenz>0) {$gameTendenz=1;}
|
|
|
|
if ($tippTendenz==$gameTendenz) { $score=1; }
|
|
|
|
if ( ($tipp1 == $goals1) && ($tipp2 == $goals2) ) {
|
|
$bonus = max(0,$goals1 + $goals2 - 3);
|
|
$score= 2 + $bonus;
|
|
}
|
|
|
|
if ($joker==true) {
|
|
$score = $score * 2;
|
|
}
|
|
|
|
if ($tipp1==-1||$tipp2==-1||$goals1==-1||$goals2==-1) { $score=0; }
|
|
|
|
return $score;
|
|
}
|
|
|
|
// Bei Tagessieg gilt nur wer am meisten genau richtig getippt hat,
|
|
// Bei Gleichstand wer den höchsten Jokersieg hat ( Jokersieg mit mehr Toren zählt mehr)
|
|
|
|
|
|
public static function getDayScoreLocal($goals1, $goals2, $tipp1, $tipp2, $joker) {
|
|
if ($tipp1==-1||$tipp2==-1||$goals1==-1||$goals2==-1) { return 0; } // Ungetippt oder Spiel hat noch kein Ergebnis
|
|
if ( ($tipp1 != $goals1) || ($tipp2 != $goals2) ) return 0;
|
|
|
|
$jokerValue=0;
|
|
if ($joker) {
|
|
$jokerValue = max(0, $goals1 + $goals2 - 3) + 1;
|
|
}
|
|
return 100 + $jokerValue;
|
|
}
|
|
|
|
|
|
public static function getTippScore($user_id,$game_id, $team=0) {
|
|
//Log::info("Getting tippstring for game_id=". $game_id .", user_id=" . $user_id.", $team=".$team);
|
|
|
|
$tipp=Tipp::getTipp($user_id,$game_id);
|
|
if (!$tipp) {
|
|
//Log::info("not found !");
|
|
return "x";
|
|
}
|
|
|
|
$tippScore="";
|
|
if ($team==0) { $tippScore= $tipp->score1;}
|
|
else { $tippScore=$tipp->score2; }
|
|
if ($tippScore==-1) { /*Log::info("untipped!");*/$tippScore="x";}
|
|
|
|
//Log::info("Returning: ". $tippScore);
|
|
return $tippScore;
|
|
}
|
|
|
|
public static function getScore($tipp_id) {
|
|
$tipp = Tipp::where('id',$tipp_id)->first();
|
|
$game = Game::where('id',$tipp->game_id)->first();
|
|
|
|
$bonus = max(0,$game->score1 + $game->score2 - 3);
|
|
|
|
$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 + $bonus;
|
|
}
|
|
|
|
if ($tipp->joker==true) {
|
|
$score = $score *2;
|
|
}
|
|
|
|
if ($game->score1 == -1) { $score=0; }
|
|
if ($tipp->score1==-1 || $tipp->score2==-1) {$score=0;}
|
|
|
|
return $score;
|
|
}
|
|
|
|
public static function resultString($tipp_id) {
|
|
$tipp = Tipp::where('id',$tipp_id)->first();
|
|
$rStr="Ungetippt";
|
|
if ($tipp->score1 > -1) $rStr= $tipp->score1 . " : " . $tipp->score2;
|
|
|
|
return $rStr;
|
|
}
|
|
|
|
public static function createTipps($user_id) {
|
|
$activeSeason = Season::getCurrent();
|
|
|
|
$rounds = Round::all()->where('season_id', '=', $activeSeason->id);
|
|
foreach($rounds as $round) {
|
|
|
|
$games=Game::all()->where('round_id','=',$round->id);
|
|
foreach($games as $game) {
|
|
|
|
// Tipp erzeugen wenn noch nicht vorhanden
|
|
$tipp = DB::table('tipps')->where([
|
|
['game_id','=',$game->id],
|
|
['user_id','=',$user_id]]
|
|
)->first();
|
|
if (! $tipp) {
|
|
Log::info('Creating missing tip: game_id=' . $game->id . ", user_id=" . $user->id);
|
|
$tipp=Tipp::create([
|
|
'user_id' => $user_id,
|
|
'game_id'=> $game->id,
|
|
'score1'=> -1,
|
|
'score2'=> -1,
|
|
'joker'=> false
|
|
]);
|
|
$tipp->save();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function createAllTips(){
|
|
$users = DB::table('users')->where('deleted',null)->get();
|
|
foreach($users as $user) {
|
|
Tipp::createTipps($user->id);
|
|
}
|
|
}
|
|
}
|