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) // Bei Gleichstand gilt die Summe aller Rankscores, deshalb wird sie auch im Ergebnis gespeichert // Fürs Dayscore-Bewerten ist rankscore allerdings irrelevant. Mit Rank nur fürs Sortieren, um die Auswahl einzugrenzen. public static function getDayScoreLocal($goals1, $goals2, $tipp1, $tipp2, $joker, $rankScore=0) { 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 1000 + $jokerValue * 100 + $rankScore; } 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) { $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); } } // Struktur: gameval * 1000 + jokerValue * 100 + rankscore public static function addDayScoreValues($val1, $val2) { $gameVal1 = intdiv($val1 , 1000); $gameVal2 = intdiv( $val2, 1000); $jokerVal1 = intdiv(($val1 - $gameVal1*1000),100); $jokerVal2 = intdiv(($val2 - $gameVal2*1000),100); if ( $gameVal1 ==0 ) { $jokerVal1=0; $rankVal1=0; } if ( $gameVal2 ==0 ) { $jokerVal2=0; $rankVal2=0; } $rankVal1 = $val1 - $gameVal1*1000 - $jokerVal1*100; $rankVal2 = $val2 - $gameVal2*1000 - $jokerVal2*100; // Minimaler Brainfuck, da $rankVal1 und $rankVal2 immer gleich sein sollten $result = ($gameVal1 + $gameVal2) * 1000 + max($jokerVal1, $jokerVal2) * 100 + max ($rankVal1, $rankVal2); return $result; } public static function getDayScoreWithoutRankScore($val) { $gameVal = intdiv($val , 1000); $jokerVal = intdiv(($val - $gameVal*1000),100); if ($gameVal==0) return 0; return $gameVal * 1000 + $jokerVal * 100; } }