fix: exclude teamers registered after due date from forced data check
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\RequiredTeamerCheck;
|
||||
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
@@ -30,7 +31,7 @@ class PersonalDataVerificationRequiredCheck implements RequiredTeamerCheckInterf
|
||||
return false;
|
||||
}
|
||||
|
||||
return false === $this->isVerificationRequired($teamer->getDataVerifiedAt());
|
||||
return false === $this->isVerificationRequired($teamer);
|
||||
}
|
||||
|
||||
public function getRouteName(): string
|
||||
@@ -38,14 +39,21 @@ class PersonalDataVerificationRequiredCheck implements RequiredTeamerCheckInterf
|
||||
return 'app_teamer_profile_index';
|
||||
}
|
||||
|
||||
private function isVerificationRequired(?\DateTimeImmutable $dataVerifiedAt): bool
|
||||
private function isVerificationRequired(Teamer $teamer): bool
|
||||
{
|
||||
$deadline = $this->getCurrentDeadline(CarbonImmutable::now()->startOfDay());
|
||||
$now = CarbonImmutable::now()->startOfDay();
|
||||
$deadline = $this->getCurrentDeadline($now);
|
||||
|
||||
if (null === $deadline) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (true === $this->isRegisteredAfterAnyCurrentYearDeadline($teamer, $now)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$dataVerifiedAt = $teamer->getDataVerifiedAt();
|
||||
|
||||
if (null === $dataVerifiedAt) {
|
||||
return true;
|
||||
}
|
||||
@@ -53,20 +61,49 @@ class PersonalDataVerificationRequiredCheck implements RequiredTeamerCheckInterf
|
||||
return CarbonImmutable::instance($dataVerifiedAt) < $deadline;
|
||||
}
|
||||
|
||||
private function getCurrentDeadline(CarbonImmutable $now): ?CarbonImmutable
|
||||
private function isRegisteredAfterAnyCurrentYearDeadline(Teamer $teamer, CarbonImmutable $now): bool
|
||||
{
|
||||
$deadlines = array_filter(array_map('trim', $this->dataVerificationDeadlines));
|
||||
rsort($deadlines);
|
||||
try {
|
||||
$registeredAt = CarbonImmutable::instance($teamer->getCreatedAt())->startOfDay();
|
||||
} catch (\TypeError) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($deadlines as $date) {
|
||||
foreach ($this->getDeadlinesForYear($now) as $deadline) {
|
||||
if ($registeredAt > $deadline) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CarbonImmutable[]
|
||||
*/
|
||||
private function getDeadlinesForYear(CarbonImmutable $now): array
|
||||
{
|
||||
$deadlines = [];
|
||||
|
||||
foreach (array_filter(array_map('trim', $this->dataVerificationDeadlines)) as $date) {
|
||||
$deadline = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $now->format('Y'), $date));
|
||||
|
||||
if (false === $deadline instanceof CarbonImmutable) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$deadline = $deadline->startOfDay();
|
||||
$deadlines[] = $deadline->startOfDay();
|
||||
}
|
||||
|
||||
return $deadlines;
|
||||
}
|
||||
|
||||
private function getCurrentDeadline(CarbonImmutable $now): ?CarbonImmutable
|
||||
{
|
||||
$deadlines = $this->getDeadlinesForYear($now);
|
||||
rsort($deadlines);
|
||||
|
||||
foreach ($deadlines as $deadline) {
|
||||
if ($deadline <= $now) {
|
||||
return $deadline;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user