From d94656c076d33c4a4254f1c6f6b8b81a01a3515b Mon Sep 17 00:00:00 2001 From: sakulb <95277083+sakulb@users.noreply.github.com> Date: Thu, 23 Feb 2023 15:12:22 +0100 Subject: [PATCH] Add person and avatar to user. (#9) * Add person and avatar to user. * Static setters for user. --- src/Entity/AnzuUser.php | 38 +++++++++++++++++-- src/Entity/Embeds/Avatar.php | 49 ++++++++++++++++++++++++ src/Entity/Embeds/Person.php | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 src/Entity/Embeds/Avatar.php create mode 100644 src/Entity/Embeds/Person.php diff --git a/src/Entity/AnzuUser.php b/src/Entity/AnzuUser.php index f723a75..ffcf924 100644 --- a/src/Entity/AnzuUser.php +++ b/src/Entity/AnzuUser.php @@ -4,6 +4,8 @@ namespace AnzuSystems\Contracts\Entity; +use AnzuSystems\Contracts\Entity\Embeds\Avatar; +use AnzuSystems\Contracts\Entity\Embeds\Person; use AnzuSystems\Contracts\Entity\Interfaces\BaseIdentifiableInterface; use AnzuSystems\Contracts\Entity\Interfaces\EnableInterface; use AnzuSystems\Contracts\Entity\Interfaces\IdentifiableInterface; @@ -16,6 +18,7 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; +use Symfony\Component\Validator\Constraints as Assert; abstract class AnzuUser implements IdentifiableInterface, EnableInterface, UserInterface { @@ -34,9 +37,20 @@ abstract class AnzuUser implements IdentifiableInterface, EnableInterface, UserI * Unique Email of user. */ #[ORM\Column(type: Types::STRING, length: 256, unique: true)] + #[Assert\Email] #[Serialize] protected string $email = ''; + #[ORM\Embedded(class: Person::class)] + #[Assert\Valid] + #[Serialize] + protected Person $person; + + #[ORM\Embedded(class: Avatar::class)] + #[Assert\Valid] + #[Serialize] + protected Avatar $avatar; + /** * List of assigned roles. */ @@ -66,6 +80,8 @@ abstract class AnzuUser implements IdentifiableInterface, EnableInterface, UserI public function __construct() { $this->setPermissionGroups(new ArrayCollection()); + $this->setAvatar(new Avatar()); + $this->setPerson(new Person()); } public function getUserIdentifier(): string @@ -111,14 +127,28 @@ public function setEmail(string $email): static return $this; } - public function getPassword(): ?string + public function getPerson(): Person + { + return $this->person; + } + + public function setPerson(Person $person): static + { + $this->person = $person; + + return $this; + } + + public function getAvatar(): Avatar { - return null; + return $this->avatar; } - public function getSalt(): ?string + public function setAvatar(Avatar $avatar): static { - return null; + $this->avatar = $avatar; + + return $this; } public function eraseCredentials(): void diff --git a/src/Entity/Embeds/Avatar.php b/src/Entity/Embeds/Avatar.php new file mode 100644 index 0000000..4d97dc7 --- /dev/null +++ b/src/Entity/Embeds/Avatar.php @@ -0,0 +1,49 @@ +avatarColor; + } + + public function setAvatarColor(string $avatarColor): self + { + $this->avatarColor = $avatarColor; + + return $this; + } + + public function getAvatarText(): string + { + return $this->avatarText; + } + + public function setAvatarText(string $avatarText): self + { + $this->avatarText = $avatarText; + + return $this; + } +} diff --git a/src/Entity/Embeds/Person.php b/src/Entity/Embeds/Person.php new file mode 100644 index 0000000..e9fb958 --- /dev/null +++ b/src/Entity/Embeds/Person.php @@ -0,0 +1,72 @@ +personFirstName; + } + + public function setPersonFirstName(string $personFirstName): self + { + $this->personFirstName = $personFirstName; + + return $this; + } + + public function getPersonLastName(): string + { + return $this->personLastName; + } + + public function setPersonLastName(string $personLastName): self + { + $this->personLastName = $personLastName; + + return $this; + } + + public function getPersonFullName(): string + { + return $this->personFullName; + } + + public function setPersonFullName(string $personFullName): self + { + $this->personFullName = $personFullName; + + return $this; + } +}