Skip to content

Commit

Permalink
HPC-9976: Change logframe autobuild logic for indicators to comply wi…
Browse files Browse the repository at this point in the history
…th more diverse attachment prototypes
  • Loading branch information
berliner committed Dec 22, 2024
1 parent 139daee commit b673de6
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions html/modules/custom/ghi_subpages/src/LogframeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ private function buildCaseloadColumns(AttachmentPrototype $attachment_prototype,
* container items.
*/
private function buildIndicatorColumns(AttachmentPrototype $attachment_prototype, Plan $plan) {
$columns = [];
// Setup the columns.
$columns = [];
$columns[] = [
'item_type' => 'attachment_label',
'config' => [
Expand All @@ -530,16 +530,27 @@ private function buildIndicatorColumns(AttachmentPrototype $attachment_prototype
],
'id' => count($columns),
];
// Take the first metric of type target and the last measurement.

// Take the first metric of type target.
$field_types = $attachment_prototype->getFieldTypes();
$target = array_search('target', $field_types);
$measure = array_search('measure', array_reverse($field_types, TRUE));
$available_fields = [
$target,
$measure,

// Take the last measurement from a pool of valid candidates.
$field_types_reversed = array_reverse($field_types, TRUE);
$measure_candidates = [
'periodical_measure',
'measure',
'cumulative_measure',
];
$available_fields = array_filter($available_fields, function ($field) {
return $field !== NULL;
foreach ($measure_candidates as $measure_candidate) {
if ($measure = array_search($measure_candidate, $field_types_reversed)) {
break;
}
}

// Collect the available fields.
$available_fields = array_filter([$target, $measure], function ($field) {
return is_int($field);
});
foreach ($available_fields as $index) {
$columns[] = [
Expand Down

0 comments on commit b673de6

Please sign in to comment.