<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ManagerRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
*
* @ApiResource(
* normalizationContext={"groups"={"manager:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"manager:write"}, "swagger_definition_name"="Write"},
* itemOperations={
* "get" = {
* "security" = "is_granted('ROLE_MANAGER')"
* },
* },
* collectionOperations={
* "get" = {
* "security" = "is_granted('ROLE_MANAGER')"
* },
*
* },
* attributes={
* "pagination_items_per_page"=10,
* "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
* }
* )
*
* @ORM\Entity(repositoryClass=ManagerRepository::class)
* @UniqueEntity(
* fields={"cin" },
* entityClass=Manager::class,
* message="AbstractPeople with cin {{ value }} is already used."
* )
* @UniqueEntity(
* fields={"email"},
* entityClass=Manager::class,
* message="AbstractPeople with email {{ value }} is already used."
* )
* @UniqueEntity(
* fields={"mainPhone"},
* entityClass=Manager::class,
* message="AbstractPeople with main phone {{ value }} is already used."
* )
* @ORM\HasLifecycleCallbacks()
*/
class Manager extends AbstractCollaborator
{
public const MAX_AGENT_NUMBER = '100';
/**
* @ORM\Column(type="integer")
*/
private int $countAgentAssignmentNumber=0;
/**
* @ORM\OneToMany(targetEntity=Agent::class, mappedBy="manager")
*/
private $agents;
/**
* @ORM\OneToMany(targetEntity=Property::class, mappedBy="manager")
*/
private $properties;
public function __construct()
{
parent::__construct();
$this->agents = new ArrayCollection();
$this->properties = new ArrayCollection();
}
public function getCountAgentAssignmentNumber(): ?int
{
return $this->countAgentAssignmentNumber;
}
public function setCountAgentAssignmentNumber(int $countAgentAssignmentNumber): self
{
$this->countAgentAssignmentNumber = $countAgentAssignmentNumber;
return $this;
}
/**
* @return Collection|Agent[]
*/
public function getAgents(): Collection
{
return $this->agents;
}
public function addAgent(Agent $agent): self
{
if (!$this->agents->contains($agent)) {
$this->agents[] = $agent;
$agent->setManager($this);
}
return $this;
}
public function removeAgent(Agent $agent): self
{
// set the owning side to null (unless already changed)
if ($this->agents->removeElement($agent) && $agent->getManager() === $this) {
$agent->setManager(null);
}
return $this;
}
/**
* @return Collection|Property[]
*/
public function getProperties(): Collection
{
return $this->properties;
}
public function addProperty(Property $property): self
{
if (!$this->properties->contains($property)) {
$this->properties[] = $property;
$property->setManager($this);
}
return $this;
}
public function removeProperty(Property $property): self
{
// set the owning side to null (unless already changed)
if ($this->properties->removeElement($property) && $property->getManager() === $this) {
$property->setManager(null);
}
return $this;
}
}