WKVS v 1.0.0
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
function generateIntersectCache($mysqli, $baseDir) {
|
||||
global $db_tabelle_kategorien;
|
||||
global $db_tabelle_disziplinen;
|
||||
global $db_tabelle_wertungstypen;
|
||||
global $db_tabelle_tabellen_konfiguration;
|
||||
global $db_tabelle_var;
|
||||
|
||||
// 1. Fetch all unique IDs you need to loop through
|
||||
$all_programms = array_column(db_select($mysqli, $db_tabelle_kategorien, '`id`', '`aktiv` = ?', [1]) ?? [], 'id');
|
||||
$all_geraete = array_column(db_select($mysqli, $db_tabelle_disziplinen, 'id') ?? [], 'id');
|
||||
|
||||
// 2. Fetch the static DB configs ONCE before starting the massive loop
|
||||
$rang_note_id = db_get_variable($mysqli, $db_tabelle_var, ['rangNote']);
|
||||
|
||||
$json_geraet = db_get_var($mysqli, "SELECT `all_noten_json` FROM $db_tabelle_tabellen_konfiguration WHERE `type_slug` = ?", ["rankLive-geraet"]) ?: '';
|
||||
$json_overview = db_get_var($mysqli, "SELECT `all_noten_json` FROM $db_tabelle_tabellen_konfiguration WHERE `type_slug` = ?", ["rankLive-overview"]) ?: '';
|
||||
$noten_rank_live_geraet = json_decode($json_geraet, true) ?? [];
|
||||
$noten_rank_live_overview = json_decode($json_overview, true) ?? [];
|
||||
|
||||
$notenConfig_db = db_select($mysqli, $db_tabelle_wertungstypen, '`berechnung_json`, `id`, `type`, `anzahl_laeufe_json`');
|
||||
$noten_config = array_column($notenConfig_db, null, 'id');
|
||||
$following_config_array = array_column($notenConfig_db, 'berechnung_json', 'id');
|
||||
$all_inputs_noten_ids = array_filter(array_column($notenConfig_db, 'type', 'id'), fn($type) => $type === 'input');
|
||||
|
||||
$masterCache = [];
|
||||
|
||||
// 2. Extract ALL possible unique IDs dynamically from your JSON configurations
|
||||
$max_runs = 1; // Default fallback to at least 1 run
|
||||
|
||||
foreach ($noten_config as $n_id => $data) {
|
||||
$config = json_decode($data['anzahl_laeufe_json'], true);
|
||||
foreach ($config as $geraetKey => $value) {
|
||||
if ($geraetKey === 'default') {
|
||||
$max_runs = max($max_runs, (int)$value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $progKey => $runsCount) {
|
||||
$max_runs = max($max_runs, (int)$runsCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure we have array lists instead of associative maps
|
||||
$all_programms = array_values($all_programms);
|
||||
$all_geraete = array_values($all_geraete);
|
||||
|
||||
// Generate standard run sequences (e.g., if max_runs is 2, creates [1, 2])
|
||||
$all_runs = range(1, $max_runs);
|
||||
|
||||
$masterCache = [];
|
||||
|
||||
// 3. The Grand Loop
|
||||
foreach ($all_programms as $programm_id) {
|
||||
|
||||
foreach ($all_geraete as $geraetId) {
|
||||
foreach ($all_runs as $initNoteRun) {
|
||||
|
||||
$all_needed_noten = [];
|
||||
|
||||
foreach ($noten_rank_live_geraet as $ind => $s_note) {
|
||||
|
||||
$n_id = $s_note['n_id'];
|
||||
|
||||
$anzahl_laeufe_json = $noten_config[$n_id]['anzahl_laeufe_json'] ?? '';
|
||||
|
||||
$anzahl_laeufe = json_decode($anzahl_laeufe_json, true);
|
||||
|
||||
$g_id = ($s_note['g_id'] === 'A') ? (int) $geraetId : (int) $s_note['g_id'];
|
||||
|
||||
$run = (int) $s_note['r'];
|
||||
|
||||
$runs = $anzahl_laeufe[$g_id][(int) $programm_id] ?? $anzahl_laeufe[$g_id]['all'] ?? $anzahl_laeufe['default'] ?? 0;
|
||||
|
||||
if (((int) $runs) < $run) {
|
||||
unset($noten_rank_live_geraet[$ind]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = "$n_id|$g_id|$run";
|
||||
|
||||
if (!isset($all_needed_noten[$key])) {
|
||||
$all_needed_noten[$key] = [
|
||||
"r" => $run,
|
||||
"g_id" => $g_id,
|
||||
"n_id" => $n_id
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($noten_rank_live_overview as $s_note) {
|
||||
|
||||
$n_id = $s_note['n_id'];
|
||||
$g_id = $s_note['g_id'];
|
||||
$run = $s_note['r'];
|
||||
|
||||
$key = "$n_id|$g_id|$run";
|
||||
|
||||
if (!isset($all_needed_noten[$key])) {
|
||||
$all_needed_noten[$key] = [
|
||||
"r" => $run,
|
||||
"g_id" => $g_id,
|
||||
"n_id" => $n_id
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$all_updating_noten = [];
|
||||
|
||||
foreach ($following_config_array as $this_note_id => $s_note_abhaenige_rechnungen_json) {
|
||||
$s_note_abhaenige_rechnungen = json_decode($s_note_abhaenige_rechnungen_json ?? '') ?? [];
|
||||
foreach ($s_note_abhaenige_rechnungen as $s_rechnung) {
|
||||
$this_note_geraet_id = $s_rechnung[1];
|
||||
|
||||
if ($this_note_geraet_id !== 'A' && (int) $this_note_geraet_id !== (int) $geraetId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$target_note_id = $s_rechnung[0];
|
||||
$target_run_raw = $s_rechnung[2][0] ?? 'A';
|
||||
$target_geraet_id_raw = $s_rechnung[2][1] ?? 'A';
|
||||
|
||||
$target_run = ($target_run_raw === 'A') ? $initNoteRun : (int) $target_run_raw;
|
||||
$target_geraet_id = ($target_geraet_id_raw === 'A') ? $geraetId : (int) $target_geraet_id_raw;
|
||||
|
||||
$key = "$target_note_id|$target_geraet_id|$target_run";
|
||||
|
||||
if (!isset($all_updating_noten[$key])) {
|
||||
$all_updating_noten[$key] = [
|
||||
"r" => $target_run,
|
||||
"g_id" => $target_geraet_id,
|
||||
"n_id" => $target_note_id
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($all_inputs_noten_ids as $n_id => $_) {
|
||||
|
||||
$anzahl_laeufe_json = $noten_config[$n_id]['anzahl_laeufe_json'] ?? '';
|
||||
|
||||
$anzahl_laeufe = json_decode($anzahl_laeufe_json, true);
|
||||
|
||||
$runs = $anzahl_laeufe[$geraetId][(int) $programm_id] ?? $anzahl_laeufe[$geraetId]['all'] ?? $anzahl_laeufe['default'] ?? 0;
|
||||
|
||||
if ($initNoteRun > $runs) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = "$n_id|$geraetId|$initNoteRun";
|
||||
|
||||
if (!isset($all_updating_noten[$key])) {
|
||||
$all_updating_noten[$key] = [
|
||||
"r" => $initNoteRun,
|
||||
"g_id" => $geraetId,
|
||||
"n_id" => $n_id
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$intersect_noten = array_intersect_key($all_updating_noten, $all_needed_noten);
|
||||
|
||||
$key = "$rang_note_id|0|1";
|
||||
|
||||
if (!isset($all_updating_noten[$key])) {
|
||||
$all_updating_noten[$key] = [
|
||||
"r" => 1,
|
||||
"g_id" => 0,
|
||||
"n_id" => $rang_note_id
|
||||
];
|
||||
}
|
||||
|
||||
$sql_where_array = [];
|
||||
$sql_where_values = [];
|
||||
|
||||
$i = 1;
|
||||
|
||||
foreach ($intersect_noten as $s_note) {
|
||||
$sql_where_values[] = $s_note['n_id'];
|
||||
$sql_where_values[] = $s_note['g_id'];
|
||||
$sql_where_values[] = $s_note['r'];
|
||||
|
||||
$sql_where_array[] = '(`note_bezeichnung_id` = ? AND `geraet_id` = ? AND `run_number` = ?)';
|
||||
}
|
||||
|
||||
$sql_where_string = '';
|
||||
|
||||
if (!empty($sql_where_values)) {
|
||||
$sql_where_string = implode(' OR ', $sql_where_array);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($intersect_noten)) {
|
||||
$masterCache[$programm_id][$geraetId][$initNoteRun] = ["SQL" => $sql_where_string, "values" => $sql_where_values, "intersect_noten" => $intersect_noten];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Save to file
|
||||
$fileContent = "<?php\nreturn " . var_export($masterCache, true) . ";";
|
||||
file_put_contents($baseDir . '/../scripts/cache/display-dependencies.php', $fileContent);
|
||||
}
|
||||
Reference in New Issue
Block a user