|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass HamtaSpikar. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Moduler\TT; |
|
11
|
|
|
|
|
12
|
|
|
use Tips\Moduler\TT\Konstanter; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Klass HamtaSpikar. |
|
16
|
|
|
*/ |
|
17
|
|
|
class HamtaSpikar extends HamtaData { |
|
18
|
|
|
use Konstanter; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var int[] $antal_spikar |
|
22
|
|
|
*/ |
|
23
|
|
|
public array $antal_spikar; |
|
24
|
|
|
/** |
|
25
|
|
|
* @var int[] $andel_spikar |
|
26
|
|
|
*/ |
|
27
|
|
|
public array $andel_spikar; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var array<int, array<int, array<int, string>>> $spikar |
|
30
|
|
|
*/ |
|
31
|
|
|
public array $spikar; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var array<int, string[]> $reduktion |
|
34
|
|
|
*/ |
|
35
|
|
|
public array $reduktion; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Hämta spikar. |
|
39
|
|
|
*/ |
|
40
|
20 |
|
protected function hämta_spikar(): void { |
|
41
|
20 |
|
$this->spikar = array_fill( |
|
42
|
20 |
|
0, |
|
43
|
20 |
|
self::TT_MAX_SPIKFÄLT, |
|
|
|
|
|
|
44
|
20 |
|
array_fill(0, self::TT_MATCHANTAL, TOM_STRÄNGVEKTOR) |
|
|
|
|
|
|
45
|
20 |
|
); |
|
46
|
20 |
|
$spikar = $this->db_preferenser->hämta_preferens("topptips.spikar"); |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Spara tom struktur om spikar inte redan sparade. |
|
50
|
|
|
* Packa annars upp spikar i fält och ersätt tom struktur. |
|
51
|
|
|
*/ |
|
52
|
|
|
match ($spikar) { |
|
53
|
20 |
|
'' => $this->db_preferenser->spara_preferens( |
|
|
|
|
|
|
54
|
20 |
|
"topptips.spikar", |
|
55
|
20 |
|
implode(',', array_merge([], ...array_merge([], ...$this->spikar))) |
|
56
|
20 |
|
), |
|
57
|
20 |
|
default => $this->spikar = array_chunk( |
|
58
|
20 |
|
array_chunk(explode(',', $spikar), 3), |
|
59
|
20 |
|
self::TT_MATCHANTAL |
|
60
|
20 |
|
) |
|
61
|
|
|
}; |
|
62
|
|
|
|
|
63
|
20 |
|
$this->antal_spikar = array_fill(0, self::TT_MAX_SPIKFÄLT, 0); |
|
64
|
20 |
|
$this->andel_spikar = $this->antal_spikar; |
|
65
|
20 |
|
$andel_spikar = $this->db_preferenser->hämta_preferens("topptips.andel_spikar"); |
|
66
|
|
|
|
|
67
|
20 |
|
if ($andel_spikar !== '') { |
|
68
|
20 |
|
$this->andel_spikar = array_map('intval', explode(',', $andel_spikar)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
20 |
|
foreach ($this->spikar as $index => $gardering) { |
|
72
|
20 |
|
foreach ($gardering as $match) { |
|
73
|
|
|
// Halvgardering = en ruta tom. |
|
74
|
20 |
|
if (count(array_unique($match)) > 1) { |
|
75
|
20 |
|
$this->antal_spikar[$index]++; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
20 |
|
$this->antal_spikar[$index] = max($this->antal_spikar[$index], $this->andel_spikar[$index]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
20 |
|
$this->reduktion = array_fill(0, self::TT_MATCHANTAL, TOM_STRÄNGVEKTOR); |
|
83
|
20 |
|
$reduktion = $this->db_preferenser->hämta_preferens("topptips.reduktion"); |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Finns reduktion i preferenser är allt väl. |
|
87
|
|
|
*/ |
|
88
|
20 |
|
match ($reduktion !== '') { |
|
89
|
20 |
|
true => $this->reduktion = array_chunk(explode(',', $reduktion), 3), |
|
90
|
|
|
false => $this->db_preferenser->spara_preferens( |
|
91
|
|
|
"topptips.reduktion", |
|
92
|
|
|
implode(',', array_merge([], ...$this->reduktion)) |
|
93
|
|
|
) |
|
94
|
20 |
|
}; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|