Skip to content

Commit

Permalink
[TM-931] Include the new workdays format in entity exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
roguenet committed May 16, 2024
1 parent 2417546 commit c57b464
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions app/Exports/V2/BaseExportFormSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ protected function getAnswer(array $field, array $answers): string
if (is_array($answer)) {
$list = [];
foreach ($answer as $item) {
if (is_array($item)) {
$list[] = $item['amount'].':'.$item['gender'].':'.$item['age'].':'.$item['ethnicity'].':'.$item['indigeneity'];
} else {
$list[] = $item;
}
$list[] = data_get($field, 'input_type') . '??' . $item;
}

return implode('|', $list);
Expand All @@ -72,7 +68,24 @@ protected function getAnswer(array $field, array $answers): string
return $this->stringifyModel($answer, ['name', 'amount']);

case 'workdays':
return $this->stringifyModel($answer, ['amount', 'gender', 'age', 'ethnicity', 'indigeneity']);
$list = [];
$workday = $answer->first();
if ($workday == null) {
return '';
}

$types = ['gender' => [], 'age' => [], 'ethnicity' => []];
foreach ($workday->demographics as $demographic) {
$value = match ($demographic->type) {
'ethnicity' => [$demographic->amount, $demographic->subtype, $demographic->name],
default => [$demographic->amount, $demographic->name],
};
$types[$demographic['type']][] = implode(':', $value);
}
$list[] = 'gender:(' . implode(')(', $types['gender']) . ')';
$list[] = 'age:(' . implode(')(', $types['age']) . ')';
$list[] = 'ethnicity:(' . implode(')(', $types['ethnicity']) . ')';
return implode('|', $list);

case 'leadershipTeam':
return $this->stringifyModel($answer, ['first_name', 'last_name', 'position', 'gender', 'age',]);
Expand Down

0 comments on commit c57b464

Please sign in to comment.