feat: FCP filter counts now respect all active search filters
This commit is contained in:
@@ -1451,13 +1451,14 @@ class PreorderController extends mfBaseController {
|
||||
$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'];
|
||||
$filter = $this->request->filter ?? [];
|
||||
// We want to count preorders matching ALL other filters, but ignoring the current FCP filter
|
||||
if (isset($filter['fcp'])) {
|
||||
unset($filter['fcp']);
|
||||
}
|
||||
|
||||
$statsMap = PreorderModel::countActiveGroupedByFcp($filter);
|
||||
|
||||
$result = array_map(
|
||||
fn($fcp) => [
|
||||
"real_id" => $fcp->id,
|
||||
|
||||
@@ -482,6 +482,40 @@ class PreorderModel
|
||||
return self::count($filter);
|
||||
}
|
||||
|
||||
public static function countActiveGroupedByFcp($filter = [])
|
||||
{
|
||||
if (!is_array($filter)) return false;
|
||||
|
||||
if (!array_key_exists("deleted", $filter)) {
|
||||
$filter["deleted"] = null;
|
||||
}
|
||||
|
||||
if (!array_key_exists("<status_code", $filter) && !array_key_exists(">status_code", $filter) && !array_key_exists("status_code", $filter)
|
||||
&& !array_key_exists("<status_id", $filter) && !array_key_exists(">status_id", $filter) && !array_key_exists("status_id", $filter)) {
|
||||
$filter["<status_code"] = 899;
|
||||
$filter["!status_code"] = 20;
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT adb_hausnummer.fcp_id, COUNT(*) as cnt FROM `" . FRONKDB_DBNAME . "`.Preorder tt_preorder
|
||||
LEFT JOIN `" . FRONKDB_DBNAME . "`.Preorderstatus tt_preorderstatus ON (tt_preorder.status_id = tt_preorderstatus.id)
|
||||
LEFT JOIN `" . ADDRESSDB_DBNAME . "`.view_hausnummer as adb_hausnummer ON (tt_preorder.adb_hausnummer_id = adb_hausnummer.hausnummer_id)
|
||||
LEFT JOIN `" . ADDRESSDB_DBNAME . "`.Wohneinheit as adb_wohneinheit ON (tt_preorder.adb_wohneinheit_id = adb_wohneinheit.id)
|
||||
WHERE $where AND adb_hausnummer.fcp_id IS NOT NULL
|
||||
GROUP BY adb_hausnummer.fcp_id
|
||||
";
|
||||
|
||||
$res = $db->query($sql);
|
||||
$counts = [];
|
||||
if ($db->num_rows($res)) {
|
||||
while ($row = $db->fetch_object($res)) {
|
||||
$counts[$row->fcp_id] = (int)$row->cnt;
|
||||
}
|
||||
}
|
||||
return $counts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $filter
|
||||
* @param $limit
|
||||
|
||||
Reference in New Issue
Block a user