WIP: Implement new role house manager
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20231103105105 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD hotel_code VARCHAR(32) DEFAULT NULL, DROP hotel_bus_pro_id');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE user ADD hotel_bus_pro_id INT DEFAULT NULL, DROP hotel_code');
|
||||
}
|
||||
}
|
||||
@@ -36,4 +36,15 @@ class HotelDataProvider
|
||||
{
|
||||
return $this->getAll()[$busProId] ?? null;
|
||||
}
|
||||
|
||||
public function findByCode(string $code): ?Hotel
|
||||
{
|
||||
foreach ($this->getAll() as $hotel) {
|
||||
if ($code === $hotel->getCode()) {
|
||||
return $hotel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ class CrmAttributesResponse
|
||||
private bool $manager = false;
|
||||
private bool $houseManager = false;
|
||||
private bool $teamer = false;
|
||||
private ?string $hotelCode = null;
|
||||
|
||||
public function getAttributeGroups(): ?array
|
||||
{
|
||||
@@ -69,6 +70,18 @@ class CrmAttributesResponse
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHotelCode(): ?string
|
||||
{
|
||||
return $this->hotelCode;
|
||||
}
|
||||
|
||||
public function setHotelCode(?string $hotelCode): static
|
||||
{
|
||||
$this->hotelCode = $hotelCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
$crmSelections = [];
|
||||
|
||||
@@ -134,6 +134,7 @@ class ResponseParser
|
||||
{
|
||||
$groups = [];
|
||||
$isAdmin = $isManager = $isHouseManager = $isTeamer = false;
|
||||
$hotelCode = null;
|
||||
|
||||
foreach ($xml->xpath('selektionsmerkmale/selektionsgruppe') as $item) {
|
||||
$group = new CrmAttributeGroup();
|
||||
@@ -141,14 +142,21 @@ class ResponseParser
|
||||
$attributes = [];
|
||||
|
||||
foreach ($item->xpath('selektion') as $subItem) {
|
||||
$attributeId = (int) $subItem->attributes()['id'];
|
||||
$attributeLabel = (string) $subItem->attributes()['bezeichnung'];
|
||||
$attributeSelected = 'True' === (string) $subItem->attributes()['auswahl'];
|
||||
$attribute = new CrmAttribute();
|
||||
$attribute
|
||||
->setId((int) $subItem->attributes()['id'])
|
||||
->setLabel((string) $subItem->attributes()['bezeichnung'])
|
||||
->setSelected('True' === (string) $subItem->attributes()['auswahl'])
|
||||
->setId($attributeId)
|
||||
->setLabel($attributeLabel)
|
||||
->setSelected($attributeSelected)
|
||||
;
|
||||
$attributes[] = $attribute;
|
||||
|
||||
if (1 === preg_match('/Hausleitung ([A-Z0-9]+)/', $attributeLabel, $matches) && true === $attributeSelected) {
|
||||
$isHouseManager = true;
|
||||
$hotelCode = $matches[1];
|
||||
}
|
||||
if ($this->config['bpn_crm_id_admin'] === $attribute->getId() && true === $attribute->isSelected()) {
|
||||
$isAdmin = true;
|
||||
}
|
||||
@@ -170,6 +178,7 @@ class ResponseParser
|
||||
->setManager($isManager)
|
||||
->setTeamer($isTeamer)
|
||||
->setHouseManager($isHouseManager)
|
||||
->setHotelCode($hotelCode)
|
||||
;
|
||||
|
||||
return $response;
|
||||
|
||||
@@ -55,7 +55,8 @@ class UserDataHandler
|
||||
ProfileResponse $profileResponse,
|
||||
array $roles,
|
||||
bool $isTeamer = false,
|
||||
array $crmSelections = []
|
||||
array $crmSelections = [],
|
||||
?string $hotelCode = null
|
||||
): User {
|
||||
$user = new User();
|
||||
$user
|
||||
@@ -64,6 +65,7 @@ class UserDataHandler
|
||||
->setEmail($profileResponse->getCommunication()->getEmail())
|
||||
->setBusProPersonId($profileResponse->getPersonId())
|
||||
->setBusProAddressId($profileResponse->getAddressId())
|
||||
->setHotelCode($hotelCode)
|
||||
->setRoles($roles)
|
||||
;
|
||||
|
||||
@@ -93,9 +95,13 @@ class UserDataHandler
|
||||
ProfileResponse $profileResponse,
|
||||
array $roles,
|
||||
bool $isTeamer = false,
|
||||
array $crmSelections = []
|
||||
array $crmSelections = [],
|
||||
?string $hotelCode = null
|
||||
): void {
|
||||
$user->setRoles($roles);
|
||||
$user
|
||||
->setRoles($roles)
|
||||
->setHotelCode($hotelCode)
|
||||
;
|
||||
|
||||
if (true === $isTeamer) {
|
||||
$address = Address::fromApiResponse($profileResponse);
|
||||
|
||||
+6
-6
@@ -48,8 +48,8 @@ class User implements UserInterface, TimestampableEntityInterface
|
||||
#[ORM\OneToOne(inversedBy: 'user', cascade: ['persist', 'remove'])]
|
||||
private ?Contact $contact = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $hotelBusProId = null;
|
||||
#[ORM\Column(length: 32, nullable: true)]
|
||||
private ?string $hotelCode = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -221,14 +221,14 @@ class User implements UserInterface, TimestampableEntityInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHotelBusProId(): ?int
|
||||
public function getHotelCode(): ?string
|
||||
{
|
||||
return $this->hotelBusProId;
|
||||
return $this->hotelCode;
|
||||
}
|
||||
|
||||
public function setHotelBusProId(?int $hotelBusProId): static
|
||||
public function setHotelCode(?string $hotelCode): static
|
||||
{
|
||||
$this->hotelBusProId = $hotelBusProId;
|
||||
$this->hotelCode = $hotelCode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
if (null !== $user) {
|
||||
$this
|
||||
->userDataHandler
|
||||
->updateLocalUser($user, $profileResponse, $roles, $isTeamer, $crmSelections)
|
||||
->updateLocalUser($user, $profileResponse, $roles, $isTeamer, $crmSelections, $crmAttributes->getHotelCode())
|
||||
;
|
||||
|
||||
return $user;
|
||||
@@ -145,7 +145,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
|
||||
return $this
|
||||
->userDataHandler
|
||||
->createLocalUser($profileResponse, $roles, $isTeamer, $crmSelections)
|
||||
->createLocalUser($profileResponse, $roles, $isTeamer, $crmSelections, $crmAttributes->getHotelCode())
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user