SchemanAjax   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 94
ccs 0
cts 43
cp 0
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A tillämpa_schema() 0 47 4
A nytt_schema() 0 21 2
1
<?php
2
3
/**
4
 * Klass SchemanAjax.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Ajax;
11
12
use Tips\Klasser\Preludium;
13
use Tips\Klasser\Spel;
14
use Tips\Klasser\Tips;
15
use Tips\Egenskaper\Ajax;
16
17
/**
18
 * Ajaxanrop ligger utanför ordinarie ordning.
19
 */
20
require_once dirname(__FILE__) . '/../../vendor/autoload.php';
21
new Preludium();
22
23
/**
24
 * Klass SchemanAjax.
25
 * Hantera förinställda konfigurationer för moduler och värden.
26
 * @SuppressWarnings("PHPMD.UnusedPrivateMethod")
27
 */
28
final class SchemanAjax extends Schemamall {
29
	use Ajax;
0 ignored issues
show
Bug introduced by
The trait Tips\Egenskaper\Ajax requires the property $logg which is not provided by Tips\Ajax\SchemanAjax.
Loading history...
30
31
	private Spel $spel;
32
	private Tips $tips;
33
34
	/**
35
	 * Inititiera.
36
	 */
37
	public function __construct() {
38
		$this->spel = new Spel();
39
		$this->tips = new Tips($this->spel);
40
		$this->tips->moduler->annonsera_moduler();
41
		$this->förgrena();
42
	}
43
44
	/**
45
	 * Lägg till nytt schema.
46
	 * js/funktioner.js: nytt_schema
47
	 */
48
	private function nytt_schema(): void {
0 ignored issues
show
Unused Code introduced by
The method nytt_schema() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
49
		$modulsträng = '';
50
		/**
51
		 * Iterera över moduler.
52
		 */
53
		foreach (array_keys($this->tips->moduler->moduldata) as $modul) {
54
			$attraktionsfaktor = $this->db_preferenser->hämta_preferens(mb_strtolower($modul) . '.attraktionsfaktor');
55
			$modulsträng .= <<< EOT
56
							<tr>
57
								<td>$modul</td>
58
								<td class="höger"><input name="modul[$modul]" class="nummer" type="number" min="1" max="1594323" autocomplete="off" value="$attraktionsfaktor"></td>
59
							</tr>
60
61
EOT;
62
		}
63
64
		/**
65
		 * Eka ut mall för nytt schema.
66
		 */
67
		$pref_max_rader = $this->db_preferenser->hämta_preferens("preferenser.max_rader");
68
		$this->schemamall($pref_max_rader, $modulsträng);
69
	}
70
71
	/**
72
	 * Tillämpa schema.
73
	 * js/funktioner.js: tillämpa_schema, id
74
	 */
75
	private function tillämpa_schema(): void {
0 ignored issues
show
Unused Code introduced by
The method tillämpa_schema() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
76
		if (!is_string($_REQUEST['tillämpa_schema'])) {
77
			return;
78
		}
79
80
		/**
81
		 * Kontroll av indata.
82
		 */
83
		parse_str($_REQUEST['tillämpa_schema'], $sdata);
84
		$parsedata = (array) filter_var_array((array) $sdata['modul'], FILTER_SANITIZE_SPECIAL_CHARS);
85
86
		/**
87
		 * Hantera indata, iterera över modul.
88
		 */
89
		foreach ($parsedata as $modul => $attraktionsfaktor) {
90
			$preferensnamn = mb_strtolower($modul . '.attraktionsfaktor');
91
			$this->db_preferenser->spara_preferens($preferensnamn, (string) $attraktionsfaktor);
92
93
			/**
94
			 * Säkerställ tillåtna intervall.
95
			 */
96
			$attraktionsfaktor = (int) $attraktionsfaktor;
97
			$this->db_preferenser->preferens_i_intervall(
98
				$attraktionsfaktor,
99
				AF_MIN,
100
				AF_MAX,
101
				AF_STD,
102
				$preferensnamn
103
			);
104
		}
105
		unset($sdata['modul']);
106
107
		$data = [];
108
		foreach ($sdata as $k => $värde) {
109
			$data[$k] = (int) $värde;
110
		}
111
112
		/**
113
		 * Spara värden.
114
		 */
115
		$this->db_preferenser->spara_preferens('preferenser.max_rader', (string) $data['schema_antal_rader']);
116
		$this->db_preferenser->preferens_i_intervall(
117
			$data['schema_antal_rader'],
118
			MIN_RADER,
119
			MAX_RADER,
120
			MIN_RADER,
121
			'preferenser.max_rader'
122
		);
123
	}
124
}
125
126
new SchemanAjax();
127