This commit is contained in:
torsten 2026-10-03 16:27:22 +02:00
parent 366935846c
commit 4bf3bbb978
8 changed files with 348 additions and 2 deletions

83
src/Models/Tipp.php Normal file
View file

@ -0,0 +1,83 @@
<?php
namespace App\Models;
class Tipp {
/**
* Berechnet die Punkte für einen Tipp im Vergleich zum echten Ergebnis.
* Portiert aus der alten Laravel-Anwendung.
*
* @param int $goals1 Tore Team 1
* @param int $goals2 Tore Team 2
* @param int $tipp1 Getippte Tore Team 1
* @param int $tipp2 Getippte Tore Team 2
* @param bool $joker Ob der Joker für diesen Tipp gesetzt wurde
* @return int Die erreichten Punkte
*/
public static function getScoreLocal($goals1, $goals2, $tipp1, $tipp2, $joker) {
$score = 0;
// Wenn noch kein Ergebnis vorliegt (-1 bedeutet in der DB meistens noch nicht gespielt)
if ($tipp1 == -1 || $tipp2 == -1 || $goals1 == -1 || $goals2 == -1) {
return 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; }
// Tendenz richtig
if ($tippTendenz == $gameTendenz) {
$score = 1;
}
// Genaues Ergebnis richtig (gibt 2 Grundpunkte + Bonus)
if (($tipp1 == $goals1) && ($tipp2 == $goals2)) {
$bonus = max(0, $goals1 + $goals2 - 3);
$score = 2 + $bonus;
}
// Joker verdoppelt die Punktzahl
if ($joker == true) {
$score = $score * 2;
}
return $score;
}
/**
* Gibt das Styling/die Farbe für die Tendenz zurück (fürs Frontend)
*/
public static function getCol($goals1, $goals2, $tipp1, $tipp2, $joker) {
if ($tipp1 == -1 || $tipp2 == -1 || $goals1 == -1 || $goals2 == -1) {
return "";
}
$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) {
return "";
}
$styling = 'background-color:grey;';
if (($tipp1 == $goals1) && ($tipp2 == $goals2)) {
$styling = 'background-color:orange;';
if ($joker) {
$styling = 'background-color:red';
}
}
return $styling;
}
}