src/Entity/Manager.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\ManagerRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. /**
  10.  *
  11.  * @ApiResource(
  12.  *     normalizationContext={"groups"={"manager:read"}, "swagger_definition_name"="Read"},
  13.  *     denormalizationContext={"groups"={"manager:write"}, "swagger_definition_name"="Write"},
  14.  *     itemOperations={
  15.  *           "get" = {
  16.  *              "security" = "is_granted('ROLE_MANAGER')"
  17.  *           },
  18.  *     },
  19.  *     collectionOperations={
  20.  *           "get" = {
  21.  *              "security" = "is_granted('ROLE_MANAGER')"
  22.  *           },
  23.  *
  24.  *     },
  25.  *     attributes={
  26.  *          "pagination_items_per_page"=10,
  27.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  28.  *     }
  29.  * )
  30.  *
  31.  * @ORM\Entity(repositoryClass=ManagerRepository::class)
  32.  * @UniqueEntity(
  33.  *          fields={"cin" },
  34.  *          entityClass=Manager::class,
  35.  *          message="AbstractPeople with cin {{ value }} is already used."
  36.  * )
  37.  * @UniqueEntity(
  38.  *           fields={"email"},
  39.  *           entityClass=Manager::class,
  40.  *           message="AbstractPeople with email {{ value }} is already used."
  41.  *     )
  42.  * @UniqueEntity(
  43.  *           fields={"mainPhone"},
  44.  *           entityClass=Manager::class,
  45.  *           message="AbstractPeople with main phone {{ value }} is already used."
  46.  *     )
  47.  * @ORM\HasLifecycleCallbacks()
  48.  */
  49. class Manager extends AbstractCollaborator
  50. {
  51.     public const MAX_AGENT_NUMBER '100';
  52.     /**
  53.      * @ORM\Column(type="integer")
  54.      */
  55.     private int $countAgentAssignmentNumber=0;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=Agent::class, mappedBy="manager")
  58.      */
  59.     private $agents;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity=Property::class, mappedBy="manager")
  62.      */
  63.     private $properties;
  64.     public function __construct()
  65.     {
  66.         parent::__construct();
  67.         $this->agents = new ArrayCollection();
  68.         $this->properties = new ArrayCollection();
  69.     }
  70.     public function getCountAgentAssignmentNumber(): ?int
  71.     {
  72.         return $this->countAgentAssignmentNumber;
  73.     }
  74.     public function setCountAgentAssignmentNumber(int $countAgentAssignmentNumber): self
  75.     {
  76.         $this->countAgentAssignmentNumber $countAgentAssignmentNumber;
  77.         return $this;
  78.     }
  79.     /**
  80.      * @return Collection|Agent[]
  81.      */
  82.     public function getAgents(): Collection
  83.     {
  84.         return $this->agents;
  85.     }
  86.     public function addAgent(Agent $agent): self
  87.     {
  88.         if (!$this->agents->contains($agent)) {
  89.             $this->agents[] = $agent;
  90.             $agent->setManager($this);
  91.         }
  92.         return $this;
  93.     }
  94.     public function removeAgent(Agent $agent): self
  95.     {
  96.         // set the owning side to null (unless already changed)
  97.         if ($this->agents->removeElement($agent) && $agent->getManager() === $this) {
  98.             $agent->setManager(null);
  99.         }
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return Collection|Property[]
  104.      */
  105.     public function getProperties(): Collection
  106.     {
  107.         return $this->properties;
  108.     }
  109.     public function addProperty(Property $property): self
  110.     {
  111.         if (!$this->properties->contains($property)) {
  112.             $this->properties[] = $property;
  113.             $property->setManager($this);
  114.         }
  115.         return $this;
  116.     }
  117.     public function removeProperty(Property $property): self
  118.     {
  119.         // set the owning side to null (unless already changed)
  120.         if ($this->properties->removeElement($property) && $property->getManager() === $this) {
  121.             $property->setManager(null);
  122.         }
  123.         return $this;
  124.     }
  125. }