src/Entity/Identity/User.php line 62
<?php
namespace App\Entity\Identity;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Post;
use App\Dto\User\AccountVerificationInput;
use App\Dto\User\SignupInput;
use App\Dto\User\UserSettings;
use App\Entity\Common\Blameable;
use App\Entity\Common\Company;
use App\Entity\Common\Trackable;
use App\Processor\Identity\UserSettingsProcessor;
use App\Processor\User\AccountVerificationInputProcessor;
use App\Processor\User\SignupInputProcessor;
use App\Provider\User\CurrentUserProvider;
use App\Repository\Identity\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Uid\Ulid;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: '`user`')]
#[ORM\Index(columns: ['avatar_id'], name: 'user_avatar_id_idx')]
#[ORM\Index(columns: ['company_id'], name: 'user_company_id_idx')]
#[ORM\Index(columns: ['created_by'], name: 'user_created_by_idx')]
#[ORM\Index(columns: ['updated_by'], name: 'user_updated_by_idx')]
#[ORM\UniqueConstraint(name: 'user_identifier_key', columns: ['identifier'])]
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ApiResource(security: "is_granted('ROLE_ADMIN')")]
#[ApiResource(
shortName: 'Identity',
operations: [
new Post(uriTemplate: '/signup', input: SignupInput::class, processor: SignupInputProcessor::class),
new Post(uriTemplate: '/verify', input: AccountVerificationInput::class, processor: AccountVerificationInputProcessor::class),
new Post(uriTemplate: '/settings', input: UserSettings::class, processor: UserSettingsProcessor::class),
new Get(uriTemplate: '/me', provider: CurrentUserProvider::class),
]
)]
#[ApiResource(
uriTemplate: '/companies/{slug}/users',
operations: [new GetCollection()],
uriVariables: [
'slug' => new Link(fromProperty: 'users', fromClass: Company::class),
],
)]
#[ApiFilter(SearchFilter::class, properties: [
'firstName' => 'ipartial',
'lastName' => 'ipartial',
'passport.value' => 'ipartial',
])]
class User extends Person implements UserInterface, PasswordAuthenticatedUserInterface
{
use Authenticatable;
use PassportIdentifiable;
use Blameable;
use Trackable;
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
#[ORM\SequenceGenerator(sequenceName: 'user_id_seq')]
#[ORM\Column(type: Types::INTEGER)]
protected ?int $id = null;
#[Assert\Ulid]
#[Assert\NotNull]
#[ORM\Column(type: 'ulid', unique: true)]
protected ?Ulid $identifier = null;
#[ORM\Column(type: Types::STRING, nullable: true)]
protected ?string $position = null;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'users')]
#[ORM\JoinColumn(name: 'company_id')]
protected ?Company $company = null;
/** @var Collection<int, Account> */
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Account::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
protected Collection $accounts;
#[Assert\Valid]
#[Assert\Type(type: UserSettings::class)]
#[ORM\Column(type: 'json_document', options: ['jsonb' => true])]
protected UserSettings $settings;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'created_by', nullable: true)]
protected ?User $createdBy = null;
public function __construct()
{
$this->identifier = new Ulid();
$this->settings = new UserSettings();
$this->accounts = new ArrayCollection();
$this->initIdentity();
}
public function getId(): ?int
{
return $this->id;
}
public function getIdentifier(): ?Ulid
{
return $this->identifier;
}
public function setIdentifier(?Ulid $slug): static
{
$this->identifier = $slug;
return $this;
}
public function getUserIdentifier(): string
{
return $this->getIdentifier()?->toRfc4122();
}
public function getPosition(): ?string
{
return $this->position;
}
public function setPosition(?string $position): self
{
$this->position = $position;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getSettings(): UserSettings
{
return $this->settings;
}
public function setSettings(UserSettings $settings): self
{
$this->settings = $settings;
return $this;
}
}