Refactor Slack notifications and enhance departmental progress calculation

- Replace `send_webhook_message` with `send_message` for improved Slack notification rendering using `goals_progress_alert_renderer`.
- Add methods for calculating and retrieving departmental progress and distribution in `goals_criteria`.
- Update `renderDanishPeriodSummary` and Slack cron logic to support departmental-specific summaries.
- Include departmental progress in serialized goal objects for better reporting.
This commit is contained in:
Jeppe Bundgaard
2026-01-29 18:30:04 +01:00
parent 8972db3469
commit 84bfbdad25
5 changed files with 60 additions and 7 deletions
@@ -369,6 +369,15 @@ class goals_criteria implements goals_criteria_i
return $criteria->getProgress();
}
/**
* @throws \Exception
*/
public static function calculateDepartmentalProgressFromArray(array $criteria_array): array
{
$criteria = self::fromJson(json_encode($criteria_array));
return $criteria->getDepartmentalProgress();
}
/**
* Export the criteria as an associative array suitable for JSON encoding.
* Ensures a canonical schema matching fromJson expectations.
@@ -608,4 +617,28 @@ class goals_criteria implements goals_criteria_i
}
}
}
/**
* @throws \Exception
*/
private function getDepartmentalProgress(): array
{
$results = [];
$department_ids = $this->departments->listIDs();
foreach ($department_ids as $dept_id) {
$dept_criteria = clone $this;
$dept_criteria->departments->set([(new \objects\departments_o())->select($dept_id)]);
$results[$dept_id] = $dept_criteria->getProgress();
}
// reset the departments to original
$this->departments->set(array_map(fn($id) => (new \objects\departments_o())->select($id), $department_ids));
return $results;
}
public function withDepartmentFilter(int $department_id): goals_criteria
{
$new_criteria = clone $this;
$new_criteria->departments->set([(new \objects\departments_o())->select($department_id)]);
return $new_criteria;
}
}