diff --git a/Layout/default/Preorder/Index.php b/Layout/default/Preorder/Index.php index 2f8219386..f4de12445 100644 --- a/Layout/default/Preorder/Index.php +++ b/Layout/default/Preorder/Index.php @@ -973,7 +973,7 @@ $pagination_entity_name = "Vorbestellungen"; } } - $requiredFlagIds = [1, 3, 4, 5]; + $requiredFlagIds = [3, 4]; $allFlagsChecked = true; foreach ($requiredFlagIds as $flagId) { @@ -2509,11 +2509,24 @@ $pagination_entity_name = "Vorbestellungen"; let fcpData = []; let opts = { data: [], placeholder: "Bitte Kampagne auswählen", allowClear: true }; 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.sort((a, b) => { - const aN = a.text.replace(/\D/g, ""), bN = b.text.replace(/\D/g, ""); - return aN && bN ? parseInt(aN, 10) - parseInt(bN, 10) : a.text.localeCompare(b.text); + if (a.id === "") return -1; + 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 }; fcpSelect.empty().select2(opts); diff --git a/application/Preorder/PreorderController.php b/application/Preorder/PreorderController.php index afeb246c2..75539694f 100644 --- a/application/Preorder/PreorderController.php +++ b/application/Preorder/PreorderController.php @@ -1448,10 +1448,31 @@ class PreorderController extends mfBaseController { if (!$campaign->id) return []; - return 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], - ADBRimoFcp::getAll(["netzgebiet_id" => intval($campaign->network->adb_netzgebiet_id)]) ?? [] + $fcps = ADBRimoFcp::getAll(["netzgebiet_id" => intval($campaign->network->adb_netzgebiet_id)]) ?? []; + if (empty($fcps)) return []; + + $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()