Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added zipcode and birthdate to event signup export (issue #300) #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/Exports/AgendaRegistrationExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
/**
* @var AgendaApplicationFormService
*/
private $agendaApplicationFormService;
private AgendaApplicationFormService $agendaApplicationFormService;

/**
* @var AgendaItem
*/
private $agendaItem;
private AgendaItem $agendaItem;

/**
* AgendaRegistrationExport constructor.
Expand Down Expand Up @@ -64,8 +64,10 @@
'Street',
'House number',
'City',
'Zip code',

Check warning on line 67 in app/Exports/AgendaRegistrationExport.php

View check run for this annotation

Codecov / codecov/patch

app/Exports/AgendaRegistrationExport.php#L67

Added line #L67 was not covered by tests
'Email address',
'Phone number',
'Date of birth',

Check warning on line 70 in app/Exports/AgendaRegistrationExport.php

View check run for this annotation

Codecov / codecov/patch

app/Exports/AgendaRegistrationExport.php#L70

Added line #L70 was not covered by tests
];

$formQuestions = [];
Expand Down
6 changes: 6 additions & 0 deletions app/Services/AgendaApplicationFormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@
"street",
"houseNumber",
"city",
"zipcode",

Check warning on line 134 in app/Services/AgendaApplicationFormService.php

View check run for this annotation

Codecov / codecov/patch

app/Services/AgendaApplicationFormService.php#L134

Added line #L134 was not covered by tests
"email",
"phonenumber",
"birthDay",

Check warning on line 137 in app/Services/AgendaApplicationFormService.php

View check run for this annotation

Codecov / codecov/patch

app/Services/AgendaApplicationFormService.php#L137

Added line #L137 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, this would need to be changed to the birthdayFormatted property instead.

);
$selectedElements = array_merge($selectedElements, $users["customfields"]);

Expand All @@ -142,6 +144,10 @@
foreach ($selectedElements as $element) {
$userline[$element] = $user[$element];
}

//format birthday to not include the time of day
$userline["birthDay"] = substr($userline["birthDay"], 0, 10);

Check warning on line 149 in app/Services/AgendaApplicationFormService.php

View check run for this annotation

Codecov / codecov/patch

app/Services/AgendaApplicationFormService.php#L149

Added line #L149 was not covered by tests
Comment on lines +148 to +149
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest performing this attribute formatting in the User model instead. There, we can firsts add

protected $casts = [
    'birthDay' => 'date',
];

This will ensure the birthDay attribute is always type-casted to a Carbon instance.

Then, I'd suggest defining an accessor to retrieve the "formatted birthday", as follows.

public function birthdayFormatted(): Attribute
{
    return Attribute::make(
        get: fn () => $this->birthDay->format('Y-m-d'),
    );
}

Note that the formatted birthday value can now simply be retrieved using $user->birthdayFormatted (not calling the function, but relying on the new property that will be magically added by the framework) or $user['birthdayFormatted'] whenever we have an instance of the user model.


array_push($activeUsers, $userline);
}

Expand Down
Loading