src/Flexy/ShopBundle/Entity/Resource/Agent.php line 26
<?php
namespace App\Flexy\ShopBundle\Entity\Resource;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use App\Entity\User;
use App\Flexy\ShopBundle\Entity\Customer\Complaint;
use App\Flexy\ShopBundle\Entity\Order\Order;
use App\Flexy\ShopBundle\Entity\Shipping\Vehicle\ShippingVehicle;
use App\Flexy\ShopBundle\Entity\Store\Store;
use App\Flexy\ShopBundle\Repository\Resource\AgentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
normalizationContext: ['groups' => ['read','readPackEngagements']],
denormalizationContext: ['groups' => ['write']],
)]
#[ApiFilter(SearchFilter::class, properties: ['user.roles' => 'partial'])]
#[ORM\Entity(repositoryClass: AgentRepository::class)]
class Agent
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(["read"])]
private $id;
#[Groups(["read","write"])]
#[ORM\Column(type: 'string', length: 255)]
private ?string $firstName = null;
#[Groups(["read","write"])]
#[ORM\Column(type: 'string', length: 255)]
private ?string $lastName = null;
#[ORM\OneToOne(targetEntity: User::class, cascade: ['persist', 'remove'])]
#[Assert\Valid()]
private ?\App\Entity\User $user = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $email = null;
#[ORM\Column(type: 'string', length: 255)]
private ?string $phone = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $address = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $photoIdentity = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $gender = null;
#[ORM\OneToMany(targetEntity: Order::class, mappedBy: 'agent')]
private \Doctrine\Common\Collections\Collection|array $orders;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $identityNumber = null;
#[ORM\OneToMany(targetEntity: Order::class, mappedBy: 'agentToDo')]
private \Doctrine\Common\Collections\Collection|array $ordersToDolist;
#[ORM\ManyToOne(inversedBy: 'agents')]
private ?AgentType $agentType = null;
#[ORM\ManyToOne(inversedBy: 'agents')]
private ?Store $store = null;
#[ORM\OneToMany(mappedBy: 'agent', targetEntity: Complaint::class)]
private Collection $complaints;
#[ORM\OneToOne(mappedBy: 'agentDriver', cascade: ['persist', 'remove'])]
private ?ShippingVehicle $shippingVehicle = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $blindPassword = null;
public function __construct()
{
$this->orders = new ArrayCollection();
$this->user = new User();
$this->ordersToDolist = new ArrayCollection();
$this->complaints = new ArrayCollection();
}
public function __toString()
{
return $this->firstName." ".$this->lastName." (".$this->getUser().")";
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getPhotoIdentity(): ?string
{
return $this->photoIdentity;
}
public function setPhotoIdentity(?string $photoIdentity): self
{
$this->photoIdentity = $photoIdentity;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): self
{
$this->gender = $gender;
return $this;
}
/**
* @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->setAgent($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->getAgent() === $this) {
$order->setAgent(null);
}
}
return $this;
}
public function getIdentityNumber(): ?string
{
return $this->identityNumber;
}
public function setIdentityNumber(?string $identityNumber): self
{
$this->identityNumber = $identityNumber;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrdersToDolist(): Collection
{
return $this->ordersToDolist;
}
public function addOrdersToDolist(Order $ordersToDolist): self
{
if (!$this->ordersToDolist->contains($ordersToDolist)) {
$this->ordersToDolist[] = $ordersToDolist;
$ordersToDolist->setAgentToDo($this);
}
return $this;
}
public function removeOrdersToDolist(Order $ordersToDolist): self
{
if ($this->ordersToDolist->removeElement($ordersToDolist)) {
// set the owning side to null (unless already changed)
if ($ordersToDolist->getAgentToDo() === $this) {
$ordersToDolist->setAgentToDo(null);
}
}
return $this;
}
public function getAgentType(): ?AgentType
{
return $this->agentType;
}
public function setAgentType(?AgentType $agentType): self
{
$this->agentType = $agentType;
return $this;
}
public function getStore(): ?Store
{
return $this->store;
}
public function setStore(?Store $store): self
{
$this->store = $store;
return $this;
}
/**
* @return Collection<int, Complaint>
*/
public function getComplaints(): Collection
{
return $this->complaints;
}
public function addComplaint(Complaint $complaint): self
{
if (!$this->complaints->contains($complaint)) {
$this->complaints->add($complaint);
$complaint->setAgent($this);
}
return $this;
}
public function getShippingVehicle(): ?ShippingVehicle
{
return $this->shippingVehicle;
}
public function setShippingVehicle(?ShippingVehicle $shippingVehicle): self
{
// unset the owning side of the relation if necessary
if ($shippingVehicle === null && $this->shippingVehicle !== null) {
$this->shippingVehicle->setAgentDriver(null);
}
// set the owning side of the relation if necessary
if ($shippingVehicle !== null && $shippingVehicle->getAgentDriver() !== $this) {
$shippingVehicle->setAgentDriver($this);
}
$this->shippingVehicle = $shippingVehicle;
return $this;
}
public function removeComplaint(Complaint $complaint): self
{
if ($this->complaints->removeElement($complaint)) {
// set the owning side to null (unless already changed)
if ($complaint->getAgent() === $this) {
$complaint->setAgent(null);
}
}
return $this;
}
public function getBlindPassword(): ?string
{
return $this->blindPassword;
}
public function setBlindPassword(?string $blindPassword): self
{
$this->blindPassword = $blindPassword;
return $this;
}
#[Groups(["read"])]
public function getFullName(): ?string
{
return $this->firstName." ".$this->lastName;
}
}