Enhance Slack notifications and pluralize Danish labels in goals_progress_alert_renderer

- Add support for sending Slack notifications to multiple department webhooks.
- Adjust Danish label pluralization based on counts for departments, customers, and products.
This commit is contained in:
Jeppe Bundgaard
2026-01-27 09:57:13 +01:00
parent 6d1e10d564
commit d01bdb7ea3
2 changed files with 29 additions and 10 deletions
@@ -25,9 +25,18 @@ class goals_progress_alert_renderer
$deptList = implode(',', $criteria->departments?->listIDs() ?? []);
// Prepare readable names for fields
$deptNames = self::commaNamesFromObjects($criteria->departments?->list() ?? [], 'department');
$customerNames = self::commaNamesFromObjects($criteria->users?->list() ?? [], 'user');
$productNames = self::commaNamesFromObjects($criteria->products?->list() ?? [], 'product');
$departmentsList = $criteria->departments?->list() ?? [];
$usersList = $criteria->users?->list() ?? [];
$productsList = $criteria->products?->list() ?? [];
$deptNames = self::commaNamesFromObjects($departmentsList, 'department');
$customerNames = self::commaNamesFromObjects($usersList, 'user');
$productNames = self::commaNamesFromObjects($productsList, 'product');
// Pluralize Danish labels based on counts
$deptLabel = (count($departmentsList) === 1) ? 'Afdeling' : 'Afdelinger';
$customerLabel = (count($usersList) === 1) ? 'Kunde' : 'Kunder';
$productLabel = (count($productsList) === 1) ? 'Produkt' : 'Produkter';
$prefix = match ($criteria->progress_alert_style) {
Style::DEPARTMENT_COMPARE => '[Dept compare] ',
@@ -40,15 +49,15 @@ class goals_progress_alert_renderer
// New DK multi-line formats for COUNT_ONLY and ALL
PType::COUNT_ONLY => self::renderDanishPeriodSummary($criteria, includeTargets: false,
header: [
$deptNames !== '' ? "Afdeling: $deptNames" : null,
$customerNames !== '' ? "Kunde: $customerNames" : null,
$productNames !== '' ? "Produkt: $productNames" : null,
$deptNames !== '' ? "$deptLabel: $deptNames" : null,
$customerNames !== '' ? "$customerLabel: $customerNames" : null,
$productNames !== '' ? "$productLabel: $productNames" : null,
]),
PType::ALL => self::renderDanishPeriodSummary($criteria, includeTargets: $target > 0,
header: [
$deptNames !== '' ? "Afdeling: $deptNames" : null,
$customerNames !== '' ? "Kunde: $customerNames" : null,
$productNames !== '' ? "Produkt: $productNames" : null,
$deptNames !== '' ? "$deptLabel: $deptNames" : null,
$customerNames !== '' ? "$customerLabel: $customerNames" : null,
$productNames !== '' ? "$productLabel: $productNames" : null,
]),
// Legacy single-line fallbacks
PType::PERCENTAGE_ONLY => sprintf('Progress: %s%%', number_format($percent, 2)),