|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass Scheman. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Klasser; |
|
11
|
|
|
|
|
12
|
|
|
use Tips\Klasser\Scheman\Hamta; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Klass Scheman. |
|
16
|
|
|
* Förinställda konfigurationer för olika moduler med värden. |
|
17
|
|
|
*/ |
|
18
|
|
|
final class Scheman extends Hamta { |
|
19
|
1 |
|
public function __construct(protected Tips $tips) { |
|
20
|
1 |
|
parent::__construct($this->tips); |
|
21
|
1 |
|
$this->hämta_scheman(); |
|
22
|
1 |
|
$this->visa_scheman(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Visa scheman. |
|
27
|
|
|
*/ |
|
28
|
1 |
|
public function visa_scheman(): void { |
|
29
|
1 |
|
$db_preferenser = new DBPreferenser($this->tips->spel->db); |
|
30
|
|
|
|
|
31
|
1 |
|
$aktiva_moduler = array_keys($this->tips->moduler->moduldata); |
|
32
|
|
|
|
|
33
|
1 |
|
$scheman = ''; |
|
34
|
1 |
|
foreach ($this->scheman as $id => $schema) { |
|
35
|
1 |
|
$schemarad = ''; |
|
36
|
1 |
|
$data = []; |
|
37
|
1 |
|
$schemamoduler = []; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Associativt fält $data[$namn]: |
|
41
|
|
|
* [schema_namn] => R_4_5_238_1 F2/4 |
|
42
|
|
|
* [schema_antal_rader] => 100 |
|
43
|
|
|
*/ |
|
44
|
1 |
|
foreach (explode(',', $schema['data']) as $dat) { |
|
45
|
1 |
|
[$namn, $data[$namn]] = explode(':', $dat); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Lägg till rader för aktiva moduler. |
|
50
|
|
|
*/ |
|
51
|
1 |
|
foreach (explode(',', $schema['faktorer']) as $faktor) { |
|
52
|
1 |
|
[$modul, $attraktionsfaktor] = explode(':', $faktor); |
|
53
|
1 |
|
$schemamoduler[] = $modul; |
|
54
|
|
|
|
|
55
|
1 |
|
[$klass, $radera] = match (in_array($modul, $aktiva_moduler)) { |
|
56
|
1 |
|
true => ['', ''], |
|
57
|
|
|
false => [' class="streck radera"', '❌ '] |
|
58
|
1 |
|
}; |
|
59
|
|
|
|
|
60
|
1 |
|
$schemarad .= $this->schemarad($modul, $attraktionsfaktor, $klass, $radera); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Lägg till rader för nyaktiverade moduler. |
|
65
|
|
|
*/ |
|
66
|
1 |
|
foreach ($aktiva_moduler as $modul) { |
|
67
|
1 |
|
if (!in_array($modul, $schemamoduler)) { |
|
68
|
|
|
$attraktionsfaktor = $db_preferenser->hämta_preferens(mb_strtolower($modul) . '.attraktionsfaktor'); |
|
69
|
|
|
$schemarad .= $this->schemarad($modul, $attraktionsfaktor); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Lägg samman rader. |
|
75
|
|
|
*/ |
|
76
|
1 |
|
$scheman .= $this->enskilt_schema($id, $data, $schemarad); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Eka ut tabeller. |
|
81
|
|
|
*/ |
|
82
|
1 |
|
echo $this->schema($scheman); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|