src/Entity/Prescriber.php line 59

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use App\Entity\Reference\ReferencePrescriberRelation;
  5. use App\Repository\PrescriberRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. /**
  14.  * @ApiResource(
  15.  *
  16.  *     normalizationContext={"groups"={"prescriber:read"}, "swagger_definition_name"="Read"},
  17.  *     denormalizationContext={"groups"={"prescriber:write"}, "swagger_definition_name"="Write"},
  18.  *     itemOperations={
  19.  *          "get"={
  20.  *             "security"="(is_granted('ROLE_AGENT') and object.getCollaborator()==user) or is_granted('ROLE_MANAGER')",
  21.  *             "security_message"="Vous n'avez pas le droit de visualier ce prescripteur"
  22.  *           },
  23.  *           "put" = {
  24.  *             "denormalization_context"={"groups"={"prescriber:put"}},
  25.  *             "security"="(is_granted('ROLE_AGENT') and object.getCollaborator()==user) or is_granted('ROLE_MANAGER')",
  26.  *            },
  27.  *     },
  28.  *     collectionOperations={
  29.  *          "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"},
  30.  *          "post"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"}
  31.  *     },
  32.  *     attributes={
  33.  *          "pagination_items_per_page"=10,
  34.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} },
  35.  *          "order"={"id":"DESC"}
  36.  *     }
  37.  * )
  38.  * @ApiFilter(OrderFilter::class,
  39.  *     properties={"id","firstName","lastName"},
  40.  *     arguments= {"orderParameterName" : "order"})
  41.  * @ORM\Entity(repositoryClass=PrescriberRepository::class)
  42.  *
  43.  * @UniqueEntity(
  44.  *           fields={"email"},
  45.  *           entityClass=Prescriber::class,
  46.  *           message="AbstractPeople with email {{ value }} is already used."
  47.  *     )
  48.  * @UniqueEntity(
  49.  *           fields={"mainPhone"},
  50.  *           entityClass=Prescriber::class,
  51.  *           message="AbstractPeople with main phone {{ value }} is already used."
  52.  *     )
  53.  *
  54.  * @ORM\HasLifecycleCallbacks()
  55.  */
  56. class Prescriber extends AbstractPeople implements Loggable
  57. {
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity=Agent::class, inversedBy="prescribers")
  60.      * @ORM\JoinColumn(nullable=false)
  61.      * @Groups({
  62.      *    "prescriber:read",
  63.      *    "siege:write","siege:put",
  64.      *    "transaction-item:read"
  65.      * })
  66.      */
  67.     private ?Agent $collaborator;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity=Property::class, mappedBy="prescriber")
  70.      */
  71.     private $properties;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity=ReferencePrescriberRelation::class)
  74.      *
  75.      * @Groups({
  76.      *      "prescriber:read","prescriber:put","prescriber:write"
  77.      *  })
  78.      */
  79.     private ?ReferencePrescriberRelation $referencePrescriberRelation;
  80.     public function __construct()
  81.     {
  82.         $this->properties = new ArrayCollection();
  83.     }
  84.     public function getCollaborator(): ?Agent
  85.     {
  86.         return $this->collaborator;
  87.     }
  88.     public function setCollaborator(?Agent $collaborator): self
  89.     {
  90.         $this->collaborator $collaborator;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return Collection|Property[]
  95.      */
  96.     public function getProperties(): Collection
  97.     {
  98.         return $this->properties;
  99.     }
  100.     public function addProperty(Property $property): self
  101.     {
  102.         if (!$this->properties->contains($property)) {
  103.             $this->properties[] = $property;
  104.             $property->setPrescriber($this);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeProperty(Property $property): self
  109.     {
  110.         // set the owning side to null (unless already changed)
  111.         if ($this->properties->removeElement($property) && $property->getPrescriber() === $this) {
  112.             $property->setPrescriber(null);
  113.         }
  114.         return $this;
  115.     }
  116.     /**
  117.      * @return array
  118.      */
  119.     public function getFields(): array
  120.     {
  121.         return [
  122.             'gender' => 'gender',
  123.             'address' => 'address',
  124.             'email' => 'email',
  125.             'mainPhone' => 'mainPhone',
  126.             'birthDay' => 'birthDay',
  127.             'cin' => 'cin',
  128.             'rc' => 'rc',
  129.             'commonCompanyIdentifier' => 'commonCompanyIdentifier',
  130.             'companyName' => 'companyName'
  131.         ];
  132.     }
  133.     public function getReferencePrescriberRelation(): ?ReferencePrescriberRelation
  134.     {
  135.         return $this->referencePrescriberRelation;
  136.     }
  137.     public function setReferencePrescriberRelation(?ReferencePrescriberRelation $referencePrescriberRelation): self
  138.     {
  139.         $this->referencePrescriberRelation $referencePrescriberRelation;
  140.         return $this;
  141.     }
  142. }