feat: improve FCP filter with counts/sorting and update highlight conditions

This commit is contained in:
2026-02-27 12:23:32 +01:00
parent 259b542ae1
commit 315f85356c
2 changed files with 41 additions and 7 deletions

View File

@@ -973,7 +973,7 @@ $pagination_entity_name = "Vorbestellungen";
} }
} }
$requiredFlagIds = [1, 3, 4, 5]; $requiredFlagIds = [3, 4];
$allFlagsChecked = true; $allFlagsChecked = true;
foreach ($requiredFlagIds as $flagId) { foreach ($requiredFlagIds as $flagId) {
@@ -2509,11 +2509,24 @@ $pagination_entity_name = "Vorbestellungen";
let fcpData = []; let fcpData = [];
let opts = { data: [], placeholder: "Bitte Kampagne auswählen", allowClear: true }; let opts = { data: [], placeholder: "Bitte Kampagne auswählen", allowClear: true };
if (success?.status === "OK" && Array.isArray(success.result)) { if (success?.status === "OK" && Array.isArray(success.result)) {
fcpData = success.result; fcpData = success.result.map(fcp => {
if (fcp.id === "") return fcp;
return {
...fcp,
text: fcp.text + (fcp.preorder_count !== undefined ? " (" + fcp.preorder_count + ")" : "")
};
});
fcpData.unshift({ id: "", text: "" }); fcpData.unshift({ id: "", text: "" });
fcpData.sort((a, b) => { fcpData.sort((a, b) => {
const aN = a.text.replace(/\D/g, ""), bN = b.text.replace(/\D/g, ""); if (a.id === "") return -1;
return aN && bN ? parseInt(aN, 10) - parseInt(bN, 10) : a.text.localeCompare(b.text); if (b.id === "") return 1;
// Sort by preorder_count descending
if ((b.preorder_count || 0) !== (a.preorder_count || 0)) {
return (b.preorder_count || 0) - (a.preorder_count || 0);
}
// Fallback to name-based numeric/alpha sort
const aN = a.id.replace(/\D/g, ""), bN = b.id.replace(/\D/g, "");
return aN && bN ? parseInt(aN, 10) - parseInt(bN, 10) : a.id.localeCompare(b.id);
}); });
opts = { data: fcpData, placeholder: "", allowClear: true }; opts = { data: fcpData, placeholder: "", allowClear: true };
fcpSelect.empty().select2(opts); fcpSelect.empty().select2(opts);

View File

@@ -1448,10 +1448,31 @@ class PreorderController extends mfBaseController {
if (!$campaign->id) return []; if (!$campaign->id) return [];
return array_map( $fcps = ADBRimoFcp::getAll(["netzgebiet_id" => intval($campaign->network->adb_netzgebiet_id)]) ?? [];
fn($fcp) => ["real_id" => $fcp->id, "id" => $fcp->name ?? null, "text" => $fcp->name ?? null, 'lat' => $fcp->gps_lat ?? null, 'lng' => $fcp->gps_long ?? null], if (empty($fcps)) return [];
ADBRimoFcp::getAll(["netzgebiet_id" => intval($campaign->network->adb_netzgebiet_id)]) ?? []
$fcpIds = array_map(fn($fcp) => $fcp->id, $fcps);
$stats = ADBRimoFcp::getRimoFcpStatistics($fcpIds);
$statsMap = [];
foreach ($stats as $stat) {
$statsMap[$stat['fcp_id']] = $stat['total_active_preorders'];
}
$result = array_map(
fn($fcp) => [
"real_id" => $fcp->id,
"id" => $fcp->name ?? null,
"text" => $fcp->name ?? null,
'lat' => $fcp->gps_lat ?? null,
'lng' => $fcp->gps_long ?? null,
'preorder_count' => $statsMap[$fcp->id] ?? 0
],
$fcps
); );
usort($result, fn($a, b) => $b['preorder_count'] <=> $a['preorder_count']);
return $result;
} }
public function getRimoFcpStatsApi() public function getRimoFcpStatsApi()