-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Koen Caerels
committed
May 6, 2024
1 parent
b88b8ab
commit 313ae41
Showing
8 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
application/YoshiKan/Application/Command/Import/FixEmail/FixEmailHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Yoshi-Kan software. | ||
* | ||
* (c) Koen Caerels | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\YoshiKan\Application\Command\Import\FixEmail; | ||
|
||
use App\YoshiKan\Domain\Model\Member\MemberRepository; | ||
use App\YoshiKan\Domain\Model\Member\Subscription; | ||
use App\YoshiKan\Domain\Model\Member\SubscriptionRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
class FixEmailHandler | ||
{ | ||
public function __construct( | ||
protected EntityManagerInterface $entityManager, | ||
protected MemberRepository $memberRepository, | ||
protected SubscriptionRepository $subscriptionRepository, | ||
) { | ||
} | ||
|
||
public function fixSubscriptions(): bool | ||
{ | ||
$allSubscriptions = $this->subscriptionRepository->getAll(); | ||
|
||
/** @var Subscription $subscription */ | ||
foreach ($allSubscriptions as $subscription) { | ||
$filteredEmail = str_replace(' ', '', $subscription->getContactEmail()); | ||
$filteredEmail = str_replace(';', '.', $filteredEmail); | ||
$filteredEmail = str_replace('?', '.', $filteredEmail); | ||
$filteredEmail = str_replace('²', '@', $filteredEmail); | ||
$filteredEmail = strtolower($filteredEmail); | ||
|
||
$subscription->setContactEmail($filteredEmail); | ||
$this->subscriptionRepository->save($subscription); | ||
$this->entityManager->flush(); | ||
|
||
echo '<br>'.$subscription->getContactFirstname().' '.$subscription->getContactLastname().' -> '.$subscription->getContactEmail(); | ||
ob_flush(); | ||
flush(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function fixMembers(): bool | ||
{ | ||
$allMembers = $this->memberRepository->getAll(); | ||
|
||
foreach ($allMembers as $member) { | ||
$filteredEmail = str_replace(' ', '', $member->getContactEmail()); | ||
$filteredEmail = str_replace(';', '.', $filteredEmail); | ||
$filteredEmail = str_replace('?', '.', $filteredEmail); | ||
$filteredEmail = str_replace('²', '@', $filteredEmail); | ||
$filteredEmail = strtolower($filteredEmail); | ||
|
||
if ('' === $filteredEmail) { | ||
$filteredEmail = '[email protected]'; | ||
} | ||
|
||
$member->setContactInformation( | ||
contactFirstname: $member->getContactFirstname(), | ||
contactLastname: $member->getContactLastname(), | ||
contactEmail: $filteredEmail, | ||
contactPhone: $member->getContactPhone() | ||
); | ||
$this->memberRepository->save($member); | ||
$this->entityManager->flush(); | ||
|
||
echo '<br>'.$member->getFirstname().' '.$member->getLastname().' -> '.$member->getContactEmail(); | ||
ob_flush(); | ||
flush(); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,17 +66,22 @@ public function import(): bool | |
|
||
$dto = new \stdClass(); | ||
$dto->firstName = (string) $worksheet->getCellByColumnAndRow(2, $row)->getValue(); | ||
$dto->lastName = mb_strtoupper($worksheet->getCellByColumnAndRow(1, $row)->getValue()); | ||
$dto->lastName = mb_strtoupper((string) $worksheet->getCellByColumnAndRow(1, $row)->getValue()); | ||
$dto->dateOfBirth = Date::excelToDateTimeObject($worksheet->getCellByColumnAndRow(4, $row)->getValue())->format(\DateTimeInterface::ATOM); | ||
$dto->nationalNumber = (string) $worksheet->getCellByColumnAndRow(5, $row)->getValue(); | ||
$dto->street = (string) $worksheet->getCellByColumnAndRow(3, $row)->getValue(); | ||
$dto->city = $worksheet->getCellByColumnAndRow(6, $row)->getValue(); | ||
$dto->city = (string) $worksheet->getCellByColumnAndRow(6, $row)->getValue(); | ||
$dto->postalCode = (string) $worksheet->getCellByColumnAndRow(7, $row)->getValue(); | ||
$dto->contactPhone = (string) $worksheet->getCellByColumnAndRow(8, $row)->getValue(); | ||
$dto->contactEmail = (string) $worksheet->getCellByColumnAndRow(9, $row)->getValue(); | ||
|
||
$contactEmail = '[email protected]'; | ||
if ('' !== (string) $worksheet->getCellByColumnAndRow(9, $row)->getValue()) { | ||
$contactEmail = (string) $worksheet->getCellByColumnAndRow(9, $row)->getValue(); | ||
} | ||
$dto->contactEmail = $contactEmail; | ||
$dto->gender = Gender::X; | ||
$dto->location = $this->locationRepository->getById(LocationMapping::getLocationId($worksheet->getCellByColumnAndRow(26, $row)->getValue())); | ||
$dto->grade = $this->gradeRepository->getById(GradeMapping::getGradeId($worksheet->getCellByColumnAndRow(25, $row)->getValue())); | ||
$dto->location = $this->locationRepository->getById(LocationMapping::getLocationId((string) $worksheet->getCellByColumnAndRow(26, $row)->getValue())); | ||
$dto->grade = $this->gradeRepository->getById(GradeMapping::getGradeId((string) $worksheet->getCellByColumnAndRow(25, $row)->getValue())); | ||
$dto->sporta = (bool) $worksheet->getCellByColumnAndRow(23, $row)->getValue(); | ||
$dto->jv = (bool) $worksheet->getCellByColumnAndRow(24, $row)->getValue(); | ||
if ($dto->sporta) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
VITE_API_URL=http://localhost.charlesproxy.com:8080/mm/api | ||
# VITE_API_URL=http://localhost.charlesproxy.com:8080/mm/api | ||
VITE_API_URL=http://localhost:8080/mm/api | ||
VITE_VERSION=0.0.2 |