Skip to content

Commit

Permalink
Merge pull request #352 from esac-ic/applicationform-null-check
Browse files Browse the repository at this point in the history
Add null check to application form service
  • Loading branch information
wouterbles authored Oct 18, 2023
2 parents 147ccb5 + 2f87ff5 commit 00ae171
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions app/Services/AgendaApplicationFormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,46 @@ public function getRegisteredUsers(AgendaItem $agendaItem): array
{
// Eager load necessary relationships
$agendaItem->load('getApplicationForm.applicationFormRows', 'getApplicationFormResponses.getApplicationResponseUser', 'getApplicationFormResponses.getApplicationFormResponseRows.getApplicationFormRow');

// Retrieve necessary objects
$applicationForm = $agendaItem->getApplicationForm;
$applicationResponses = $agendaItem->getApplicationFormResponses;


if (is_null($applicationForm)) {
return [];
}

// Map custom fields
$customfields = $applicationForm->applicationFormRows
->pluck('applicationFormRowName')
->map->text()
->all();

// Map user data
$userdata = $applicationResponses->map(function ($response) use ($agendaItem) {
$user = $response->getApplicationResponseUser;
$user["_signupId"] = $response->id;
$response->getApplicationFormResponseRows->each(function($responseRow) use (&$user) {

$response->getApplicationFormResponseRows->each(function ($responseRow) use (&$user) {
$columnname = $responseRow->getApplicationFormRow->applicationFormRowName->text();
$user[$columnname] = $responseRow->value;
});

if ($agendaItem->climbing_activity) {
$user['certificate_names'] = $user->getCertificationsAbbreviations();
}
return $user;
})->all();

// Build the final array to return
return [
"agendaitem" => $agendaItem->agendaItemTitle->text(),
"agendaId" => $agendaItem->id,
"userdata" => $userdata,
"customfields" => $customfields
"agendaitem" => $agendaItem->agendaItemTitle->text(),
"agendaId" => $agendaItem->id,
"userdata" => $userdata,
"customfields" => $customfields,
];
}


/**
* @param AgendaItem $agendaItem
* @return array
Expand All @@ -69,15 +72,14 @@ public function getRegisteredUserIds(AgendaItem $agendaItem): array

return $userdataIds;
}


/**
* @param AgendaItem $agendaItem
* @return Collection
*/
public function getExportData(AgendaItem $agendaItem): Collection
{
$users = $this->getRegisteredUsers($agendaItem);
$users = $this->getRegisteredUsers($agendaItem);
$selectedElements = array(
"firstname",
"preposition",
Expand All @@ -86,7 +88,7 @@ public function getExportData(AgendaItem $agendaItem): Collection
"houseNumber",
"city",
"email",
"phonenumber"
"phonenumber",
);
$selectedElements = array_merge($selectedElements, $users["customfields"]);

Expand All @@ -102,4 +104,4 @@ public function getExportData(AgendaItem $agendaItem): Collection
return new Collection($activeUsers);
}

}
}

0 comments on commit 00ae171

Please sign in to comment.