src/Entity/Reference/ReferenceContactType.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Reference;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  6. use App\Entity\Contact;
  7. use App\Repository\Reference\ReferenceContactTypeRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. /**
  13.  *@ApiResource(
  14.  *     security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  15.  *     normalizationContext={"groups"={"reference-contact-type:read"}, "swagger_definition_name"="Read"},
  16.  *     denormalizationContext={"groups"={"reference-contact-type:write"}, "swagger_definition_name"="Write"},
  17.  *     itemOperations={
  18.  *          "get"
  19.  *     },
  20.  *     collectionOperations={
  21.  *           "get",
  22.  *
  23.  *     },
  24.  *     attributes={
  25.  *          "pagination_items_per_page"=10,
  26.  *          "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  27.  *     }
  28.  * )
  29.  * @ApiFilter(SearchFilter::class, properties={
  30.  *     "code": "exact",
  31.  * })
  32.  * @ORM\Entity(repositoryClass=ReferenceContactTypeRepository::class)
  33.  */
  34. class ReferenceContactType
  35. {
  36.     public const TRANSLATION_DOMAIN 'reference_contact';
  37.     public const REFERENCE_CONTACT_TYPE_BUYER 'reference.contact.type.BUYER';
  38.     public const REFERENCE_CONTACT_TYPE_SELLER 'reference.contact.type.SELLER';
  39.     public const REFERENCE_CONTACT_TYPE_OWNER 'reference.contact.type.OWNER';
  40.     public const REFERENCE_CONTACT_TYPE_TENANT 'reference.contact.type.TENANT';
  41.     public const CODE_REFERENCE_CONTACT_TYPE_BUYER =  '0';
  42.     public const CODE_REFERENCE_CONTACT_TYPE_SELLER '-1';
  43.     public const CODE_REFERENCE_CONTACT_TYPE_OWNER =  '1';
  44.     public const CODE_REFERENCE_CONTACT_TYPE_TENANT '2';
  45.     public const ALL_REFERENCE_CONTACT_TYPE = [
  46.         self::REFERENCE_CONTACT_TYPE_BUYER,
  47.         self::REFERENCE_CONTACT_TYPE_SELLER,
  48.         self::REFERENCE_CONTACT_TYPE_OWNER,
  49.         self::REFERENCE_CONTACT_TYPE_TENANT];
  50.     public const ALL_CODE_REFERENCE_CONTACT_TYPE = [
  51.         self::CODE_REFERENCE_CONTACT_TYPE_BUYER,
  52.         self::CODE_REFERENCE_CONTACT_TYPE_SELLER,
  53.         self::CODE_REFERENCE_CONTACT_TYPE_OWNER,
  54.         self::CODE_REFERENCE_CONTACT_TYPE_TENANT
  55.         ];
  56.     /**
  57.      * @ORM\Id
  58.      * @ORM\GeneratedValue
  59.      * @ORM\Column(type="integer")
  60.      * @Groups({
  61.      *    "transaction-item:read",
  62.      *    "mandate:read",
  63.      *    "reference-contact-type:read",
  64.      *    "contact:read",
  65.      *    "business-indication:item:read",
  66.      *    "property:read",
  67.      *    "property-visit:read",
  68.      *
  69.      * })
  70.      */
  71.     private $id;
  72.     /**
  73.      * @ORM\Column(type="string", length=255)
  74.      *
  75.      * @Groups({
  76.      *    "transaction-item:read",
  77.      *    "mandate:read",
  78.      *    "reference-contact-type:read",
  79.      *    "contact:read",
  80.      *    "business-indication:item:read",
  81.      *    "property:read",
  82.      *    "property-visit:read",
  83.      * })
  84.      */
  85.     private ?string $name;
  86.     /**
  87.      * @ORM\Column(type="string", length=255)
  88.      *
  89.      * @Groups({
  90.      *    "transaction-item:read",
  91.      *    "mandate:read",
  92.      *    "reference-contact-type:read",
  93.      *    "contact:read",
  94.      *    "business-indication:item:read",
  95.      *    "property:read",
  96.      *    "property-visit:read",
  97.      * })
  98.      */
  99.     private ?string $code;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity=Contact::class, mappedBy="contactTypeReference")
  102.      */
  103.     private $contacts;
  104.     public function __construct()
  105.     {
  106.         $this->contacts = new ArrayCollection();
  107.     }
  108.     public function getId(): ?int
  109.     {
  110.         return $this->id;
  111.     }
  112.     public function getName(): ?string
  113.     {
  114.         return $this->name;
  115.     }
  116.     public function setName(string $name): self
  117.     {
  118.         $this->name $name;
  119.         return $this;
  120.     }
  121.     public function getCode(): ?string
  122.     {
  123.         return $this->code;
  124.     }
  125.     public function setCode(string $code): self
  126.     {
  127.         $this->code $code;
  128.         return $this;
  129.     }
  130.     /**
  131.      * @return Collection|Contact[]
  132.      */
  133.     public function getContacts(): Collection
  134.     {
  135.         return $this->contacts;
  136.     }
  137.     public function addContact(Contact $contact): self
  138.     {
  139.         if (!$this->contacts->contains($contact)) {
  140.             $this->contacts[] = $contact;
  141.             $contact->setContactTypeReference($this);
  142.         }
  143.         return $this;
  144.     }
  145.     public function removeContact(Contact $contact): self
  146.     {
  147.         if ($this->contacts->removeElement($contact)) {
  148.             // set the owning side to null (unless already changed)
  149.             if ($contact->getContactTypeReference() === $this) {
  150.                 $contact->setContactTypeReference(null);
  151.             }
  152.         }
  153.         return $this;
  154.     }
  155. }