src/Entity/User.php line 40
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Uid\Ulid;
use App\Controller\Auth\MeController;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Gedmo\Mapping\Annotation as Gedmo;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]
#[ORM\Table(name: '`user`')]
#[ORM\HasLifecycleCallbacks()]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
#[ApiResource(
normalizationContext: [
'groups' => ['read:user']
],
collectionOperations: [],
itemOperations: [
'me' => [
'pagination_enabled' => false,
'path' => '/me',
'method' => 'get',
'requirements' => [],
'controller' => MeController::class,
'read' => false,
]
]
)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
use Timestamps;
#[ORM\Id]
#[ORM\Column(type: 'ulid', unique: true)]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: UlidGenerator::class)]
#[Groups(['read:user', 'read:user:profile'])]
private ?Ulid $id = null;
#[ORM\Column(type: 'string', length: 180, unique: true)]
#[Groups(['read:user'])]
private $email;
#[ORM\Column(type: 'json')]
#[Groups(['read:user'])]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:user'])]
private $first_name;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:user'])]
private $last_name;
#[ORM\Column(type: 'boolean')]
#[Groups(['read:user'])]
private $isVerified = false;
#[ORM\ManyToOne(targetEntity: Company::class, inversedBy: 'users')]
private $company;
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: Order::class, orphanRemoval: true)]
private $orders;
#[ORM\OneToMany(mappedBy: 'created_by', targetEntity: Subscription::class, orphanRemoval: true)]
private $subscriptions;
#[ORM\OneToMany(mappedBy: 'created_by', targetEntity: Payment::class, orphanRemoval: true)]
private $payments;
#[ORM\OneToMany(mappedBy: 'created_by', targetEntity: Post::class, orphanRemoval: true)]
private $posts;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(['read:user'])]
private $photo;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $google_id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $facebook_id;
#[ORM\OneToMany(mappedBy: 'created_by', targetEntity: Pointing::class, orphanRemoval: true)]
private $pointings;
#[ORM\OneToMany(mappedBy: 'created_by', targetEntity: AbsenceEmployee::class, orphanRemoval: true)]
private $absenceEmployees;
#[ORM\Column(type: 'datetime', nullable: true)]
private $last_login;
#[ORM\OneToMany(mappedBy: 'made_by', targetEntity: Activity::class)]
private Collection $activities;
#[ORM\Column(length: 255, nullable: true)]
private ?string $phone = null;
#[ORM\Column(nullable: true)]
private ?bool $isActive = true;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->subscriptions = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->pointings = new ArrayCollection();
$this->absenceEmployees = new ArrayCollection();
$this->activities = new ArrayCollection();
}
public function __toString()
{
return $this->first_name . " " . $this->last_name;
}
public function getId(): ?Ulid
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function addRole(string $roles): self
{
$this->roles[] = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getFirstName(): ?string
{
return $this->first_name;
}
public function setFirstName(?string $first_name): self
{
$this->first_name = $first_name;
return $this;
}
public function getLastName(): ?string
{
return $this->last_name;
}
public function setLastName(?string $last_name): self
{
$this->last_name = $last_name;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
// public function __toString() {
// return $this->id;
// }
public function getIsVerified(): ?bool
{
return $this->isVerified;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCustomer($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCustomer() === $this) {
$order->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection<int, Subscription>
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setCreatedBy($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getCreatedBy() === $this) {
$subscription->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Payment>
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function addPayment(Payment $payment): self
{
if (!$this->payments->contains($payment)) {
$this->payments[] = $payment;
$payment->setCreatedBy($this);
}
return $this;
}
public function removePayment(Payment $payment): self
{
if ($this->payments->removeElement($payment)) {
// set the owning side to null (unless already changed)
if ($payment->getCreatedBy() === $this) {
$payment->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setCreatedBy($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->removeElement($post)) {
// set the owning side to null (unless already changed)
if ($post->getCreatedBy() === $this) {
$post->setCreatedBy(null);
}
}
return $this;
}
public function getPhoto(): ?string
{
return $this->photo;
}
public function setPhoto(?string $photo): self
{
$this->photo = $photo;
return $this;
}
public function getGoogleId(): ?string
{
return $this->google_id;
}
public function setGoogleId(?string $google_id): self
{
$this->google_id = $google_id;
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebook_id;
}
public function setFacebookId(?string $facebook_id): self
{
$this->facebook_id = $facebook_id;
return $this;
}
/**
* @return Collection<int, Pointing>
*/
public function getPointings(): Collection
{
return $this->pointings;
}
public function addPointing(Pointing $pointing): self
{
if (!$this->pointings->contains($pointing)) {
$this->pointings[] = $pointing;
$pointing->setCreatedBy($this);
}
return $this;
}
public function removePointing(Pointing $pointing): self
{
if ($this->pointings->removeElement($pointing)) {
// set the owning side to null (unless already changed)
if ($pointing->getCreatedBy() === $this) {
$pointing->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, AbsenceEmployee>
*/
public function getAbsenceEmployees(): Collection
{
return $this->absenceEmployees;
}
public function addAbsenceEmployee(AbsenceEmployee $absenceEmployee): self
{
if (!$this->absenceEmployees->contains($absenceEmployee)) {
$this->absenceEmployees[] = $absenceEmployee;
$absenceEmployee->setCreatedBy($this);
}
return $this;
}
public function removeAbsenceEmployee(AbsenceEmployee $absenceEmployee): self
{
if ($this->absenceEmployees->removeElement($absenceEmployee)) {
// set the owning side to null (unless already changed)
if ($absenceEmployee->getCreatedBy() === $this) {
$absenceEmployee->setCreatedBy(null);
}
}
return $this;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
public function getLastLogin(): ?\DateTimeInterface
{
return $this->last_login;
}
public function setLastLogin(?\DateTimeInterface $last_login): self
{
$this->last_login = $last_login;
return $this;
}
/**
* @return Collection<int, Activity>
*/
public function getActivities(): Collection
{
return $this->activities;
}
public function addActivity(Activity $activity): static
{
if (!$this->activities->contains($activity)) {
$this->activities->add($activity);
$activity->setMadeBy($this);
}
return $this;
}
public function removeActivity(Activity $activity): static
{
if ($this->activities->removeElement($activity)) {
// set the owning side to null (unless already changed)
if ($activity->getMadeBy() === $this) {
$activity->setMadeBy(null);
}
}
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): static
{
$this->phone = $phone;
return $this;
}
public function isIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(?bool $isActive): static
{
$this->isActive = $isActive;
return $this;
}
}