|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass Tipsresultat. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Klasser; |
|
11
|
|
|
|
|
12
|
|
|
use Tips\Egenskaper\Varden; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Klass Tipsresultat. |
|
16
|
|
|
*/ |
|
17
|
|
|
class Tipsresultat { |
|
18
|
|
|
use Varden; |
|
19
|
|
|
|
|
20
|
|
|
protected string $site; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Sätt sajt. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(private Spel $spel) { |
|
26
|
|
|
$this->hämta_värden($this->spel->db); |
|
27
|
|
|
$this->site = SVENSKA_SPEL_API_URL . "{$this->spel->speltyp->produktnamn()}"; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Hämta tipsresultat. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function hämta_tipsresultat(Tips &$tips): bool { |
|
34
|
|
|
$url = "{$this->site}/draws/{$tips->spel->omgång}/result?accesskey={$this->api}"; |
|
35
|
|
|
$objekt = hämta_objekt($url); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Säkerställ att data från Svenska spel finns, eller återvänd. |
|
39
|
|
|
*/ |
|
40
|
|
|
if ($objekt === null || !isset($objekt->result)) { // Inga data. |
|
41
|
|
|
$tips->spel->db->logg->logga(self::class . ": ❌ Inget tipsresultat. ({$tips->spel->omgång})"); |
|
42
|
|
|
return false; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Vi har tipsdata från Svenska spel. Extrahera och returnera. |
|
47
|
|
|
*/ |
|
48
|
|
|
$tips->utdelning->utdelning = array_map(fn (int $index): int => |
|
49
|
|
|
(int) flyttal($objekt->result->distribution[$index]->amount), array_keys($tips->utdelning->utdelning)); |
|
50
|
|
|
|
|
51
|
|
|
$tips->utdelning->vinnare = array_map(fn (int $index): int => |
|
52
|
|
|
$objekt->result->distribution[$index]->winners, array_keys($tips->utdelning->vinnare)); |
|
53
|
|
|
|
|
54
|
|
|
$tips->utdelning->tipsrad = ''; |
|
55
|
|
|
foreach ($objekt->result->events as $index => $event) { |
|
56
|
|
|
$tips->matcher->match[$index] = $event->description; |
|
57
|
|
|
$tips->matcher->resultat[$index] = $event->outcomeScore; |
|
58
|
|
|
$tips->matcher->matchstatus[$index] = ($event->cancelled) ? 0 : 1; |
|
59
|
|
|
$tips->utdelning->tipsrad .= $event->outcome; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$tips->matcher->komplett = !in_array(0, $tips->matcher->matchstatus, true); |
|
63
|
|
|
$tips->utdelning->tipsrad_012 = symboler_till_siffror($tips->utdelning->tipsrad); |
|
64
|
|
|
$tips->spel->db->logg->logga(self::class . ": ✅ Hämtade tipsresultat. ({$tips->spel->omgång})"); |
|
65
|
|
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|