|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass Spara. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Moduler\TT; |
|
11
|
|
|
|
|
12
|
|
|
use PDO; |
|
13
|
|
|
use Tips\Moduler\TT; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Klass Spara. |
|
17
|
|
|
* Spara aktuell omgång för Topptipset i databas. |
|
18
|
|
|
*/ |
|
19
|
|
|
class Spara { |
|
20
|
20 |
|
public function __construct(private TT $tt) { |
|
21
|
20 |
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Spara topptips. |
|
25
|
|
|
* För närvarande sparas bara aktuell omgång. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function spara_data(): void { |
|
28
|
|
|
$this->tt->utdelning->spel->db->instans->exec("DELETE FROM `TT`"); |
|
29
|
|
|
$sats = $this->tt->utdelning->spel->db->instans->prepare("REPLACE INTO `TT` |
|
30
|
|
|
(`omgång`, `omsättning`, `spelstopp`, `överskjutande`, `extrapengar`, |
|
31
|
|
|
`hemmalag`, `bortalag`, `odds`, `streck`) VALUES |
|
32
|
|
|
(:omgang, :omsattning, :spelstopp, :overskjutande, :extrapengar, |
|
33
|
|
|
:hemmalag, :bortalag, :odds, :streck)"); |
|
34
|
|
|
$sats->bindValue(':omgang', $this->tt->omgång, PDO::PARAM_INT); |
|
35
|
|
|
$sats->bindValue(':omsattning', $this->tt->omsättning, PDO::PARAM_INT); |
|
36
|
|
|
$sats->bindValue(':spelstopp', $this->tt->spelstopp, PDO::PARAM_STR); |
|
37
|
|
|
$sats->bindValue(':overskjutande', $this->tt->överskjutande, PDO::PARAM_STR); |
|
38
|
|
|
$sats->bindValue(':extrapengar', $this->tt->extrapengar, PDO::PARAM_STR); |
|
39
|
|
|
$sats->bindValue(':hemmalag', implode('|', $this->tt->hemmalag), PDO::PARAM_STR); |
|
40
|
|
|
$sats->bindValue(':bortalag', implode('|', $this->tt->bortalag), PDO::PARAM_STR); |
|
41
|
|
|
$sats->bindValue(':odds', implode(',', array_merge(...$this->tt->tt_odds)), PDO::PARAM_STR); |
|
42
|
|
|
$sats->bindValue(':streck', implode(',', array_merge(...$this->tt->tt_streck)), PDO::PARAM_STR); |
|
43
|
|
|
|
|
44
|
|
|
$kommentar = match ($sats->execute()) { |
|
45
|
|
|
true => ": ✅ Sparade TT-data.", |
|
46
|
|
|
false => ": ❌ Kunde inte spara TT-data." |
|
47
|
|
|
}; |
|
48
|
|
|
|
|
49
|
|
|
$this->tt->utdelning->spel->db->logg->logga(self::class . "$kommentar ({$this->tt->omgång})"); |
|
50
|
|
|
$this->tt->historik->historiskt_utfall(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|