diff --git a/migrations/Version20231011122510.php b/migrations/Version20231011122510.php new file mode 100644 index 0000000..a351389 --- /dev/null +++ b/migrations/Version20231011122510.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE teamer ADD crm_selections JSON DEFAULT NULL COMMENT \'(DC2Type:json)\''); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE teamer DROP crm_selections'); + } +} diff --git a/src/BusProNet/Model/CrmAttributesResponse.php b/src/BusProNet/Model/CrmAttributesResponse.php index c524836..3073646 100644 --- a/src/BusProNet/Model/CrmAttributesResponse.php +++ b/src/BusProNet/Model/CrmAttributesResponse.php @@ -55,4 +55,25 @@ class CrmAttributesResponse return $this; } + + public function toArray(): array + { + $crmSelections = []; + + foreach ($this->getAttributeGroups() as $group) { + /** @var CrmAttributeGroup $group */ + if (false === isset($crmSelections[$group->getLabel()])) { + $crmSelections[$group->getLabel()] = []; + } + foreach ($group->getAttributes() as $attribute) { + /** @var CrmAttribute $attribute */ + if (false === $attribute->isSelected()) { + continue; + } + $crmSelections[$group->getLabel()][] = $attribute->getLabel(); + } + } + + return $crmSelections; + } } \ No newline at end of file diff --git a/src/BusProNet/UserDataHandler.php b/src/BusProNet/UserDataHandler.php index 30bede1..f066383 100644 --- a/src/BusProNet/UserDataHandler.php +++ b/src/BusProNet/UserDataHandler.php @@ -48,8 +48,12 @@ class UserDataHandler ]); } - public function createLocalUser(ProfileResponse $profileResponse, array $roles, bool $isTeamer = false): User - { + public function createLocalUser( + ProfileResponse $profileResponse, + array $roles, + bool $isTeamer = false, + array $crmSelections = [] + ): User { $user = new User(); $user ->setFirstName($profileResponse->getFirstName()) @@ -62,6 +66,7 @@ class UserDataHandler if (true === $isTeamer) { $teamer = Teamer::fromApiResponse($profileResponse); + $teamer->setCrmSelections($crmSelections); $user->setTeamer($teamer); $this->logger->info('Create teamer', [ 'uuid' => $teamer->getUuid(), @@ -82,7 +87,8 @@ class UserDataHandler User $user, ProfileResponse $profileResponse, array $roles, - bool $isTeamer = false + bool $isTeamer = false, + array $crmSelections = [] ): void { $user->setRoles($roles); @@ -93,6 +99,7 @@ class UserDataHandler ->getTeamer() ->setAddress($address) ->setCommunication($communication) + ->setCrmSelections($crmSelections) ; } diff --git a/src/Entity/Teamer.php b/src/Entity/Teamer.php index 3d6ebd0..32e0b15 100644 --- a/src/Entity/Teamer.php +++ b/src/Entity/Teamer.php @@ -128,6 +128,9 @@ class Teamer implements TimestampableEntityInterface #[ORM\Column(length: 2, nullable: true)] private ?string $size = null; + #[ORM\Column(nullable: true)] + private ?array $crmSelections = null; + public function __construct() { $this->uuid = Uuid::v4(); @@ -720,4 +723,16 @@ class Teamer implements TimestampableEntityInterface return $this; } + + public function getCrmSelections(): ?array + { + return $this->crmSelections; + } + + public function setCrmSelections(?array $crmSelections): static + { + $this->crmSelections = $crmSelections; + + return $this; + } } diff --git a/src/Security/BpnAuthenticator.php b/src/Security/BpnAuthenticator.php index 7731228..53043a7 100644 --- a/src/Security/BpnAuthenticator.php +++ b/src/Security/BpnAuthenticator.php @@ -4,6 +4,8 @@ namespace App\Security; use App\BusProNet\ApiClient; use App\BusProNet\ApiClientException; +use App\BusProNet\Model\CrmAttribute; +use App\BusProNet\Model\CrmAttributeGroup; use App\BusProNet\Model\CrmAttributesResponse; use App\BusProNet\Model\ProfileResponse; use App\BusProNet\UserDataHandler; @@ -117,6 +119,9 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent return null; } + // Flatten selected CRM attributes + $crmSelections = $crmAttributes->toArray(); + // Determine teamer status from CRM attributes $isTeamer = $crmAttributes->isTeamer(); @@ -130,7 +135,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent if (null !== $user) { $this ->userDataHandler - ->updateLocalUser($user, $profileResponse, $roles, $isTeamer) + ->updateLocalUser($user, $profileResponse, $roles, $isTeamer, $crmSelections) ; return $user; @@ -138,7 +143,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent return $this ->userDataHandler - ->createLocalUser($profileResponse, $roles, $isTeamer) + ->createLocalUser($profileResponse, $roles, $isTeamer, $crmSelections) ; } } diff --git a/templates/admin/teamer/crm_selections.html.twig b/templates/admin/teamer/crm_selections.html.twig index b57cb3c..6008d69 100644 --- a/templates/admin/teamer/crm_selections.html.twig +++ b/templates/admin/teamer/crm_selections.html.twig @@ -11,6 +11,25 @@

Selektionsmerkmale {{ teamer }}

+ {% for group, attributes in teamer.crmSelections %} +

+ {{ group }} +

+ {% if attributes|length %} + + {% else %} +
+ - +
+ {% endif %} + {% endfor %} {% endblock %} \ No newline at end of file