src/Entity/AbstractPeople.php line 76

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Reference\PersonTypeReference;
  4. use Symfony\Component\Serializer\Annotation\Groups;
  5. use Symfony\Component\Serializer\Annotation\SerializedName;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use ApiPlatform\Core\Annotation\ApiFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Action\NotFoundAction;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  11. use ApiPlatform\Core\Annotation\ApiResource;
  12. use App\Entity\Reference\ReferencePersonMaritalStatus;
  13. use App\Repository\AbstractPeopleRepository;
  14. use App\Traits\TimeStampTrait;
  15. use DateTimeInterface;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use App\Filter\ContactCityFilter;
  18. /**
  19.  * @ApiResource(
  20.  *  security= "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  21.  *  normalizationContext={
  22.  *     "groups"={ "abstract-people:read","directory:people:search" },
  23.  *     "swagger_definition_name"="Read"
  24.  *  },
  25.  *  denormalizationContext={
  26.  *     "groups"={"abstract-people:write"},
  27.  *     "swagger_definition_name"="Write","skip_null_values" = true
  28.  *  },
  29.  *  itemOperations={
  30.  *     "get"={
  31.  *             "path"="/peoples/{id}",
  32.  *              "controller"=NotFoundAction::class,
  33.  *              "read"=false,
  34.  *              "output"=false,
  35.  *            },
  36.  *     },
  37.  *  collectionOperations={
  38.  *      "get"={
  39.  *             "path"="/peoples",
  40.  *             "controller"=NotFoundAction::class,
  41.  *             "read"=false,
  42.  *             "output"=false,
  43.  *         },
  44.  *     },
  45.  * attributes={
  46.  *      "pagination_items_per_page"=10,
  47.  *      "formats"={"jsonld", "json", "html", "jsonhal", "csv"={"text/csv"} }
  48.  *     }
  49.  *
  50.  * )
  51.  * @ApiFilter(ContactCityFilter::class)
  52.  * @ApiFilter(SearchFilter::class, properties={
  53.  *     "id": "exact",
  54.  *     "firstName": "ipartial",
  55.  *     "lastName": "ipartial",
  56.  *     "email": "partial",
  57.  *     "mainPhone":"partial",
  58.  *     "address.city.name":"ipartial",
  59.  * })
  60.  * @ApiFilter(DateFilter::class, properties={"createdAt"})
  61.  * @ORM\InheritanceType("JOINED")
  62.  * @ORM\DiscriminatorColumn(name="type", type="string", length=12)
  63.  * @ORM\DiscriminatorMap({
  64.  *     "contact"="Contact",
  65.  *     "candidate"="Candidate",
  66.  *     "prescriber" = "Prescriber"
  67.  *
  68.  * })
  69.  * @ORM\Entity(repositoryClass=AbstractPeopleRepository::class)
  70.  * @ORM\Table(indexes={@ORM\Index(name="abstract_people_search_idx", columns={"first_name","last_name","email","main_phone"})})
  71.  * @ORM\HasLifecycleCallbacks()
  72.  */
  73. abstract class AbstractPeople
  74. {
  75.     use TimeStampTrait;
  76.     public const ROLE_CONTACT 'ROLE_CONTACT';
  77.     public const ROLE_CANDIDATE 'ROLE_CANDIDATE';
  78.     public const ROLE_PRESCRIBER 'ROLE_PRESCRIBER';
  79.     public const PERSON_TYPE_PHYSICAL 'Physical';
  80.     public const PERSON_TYPE_MORAL 'Moral';
  81.     public const ALL_PEOPLE_ROLE = [
  82.         self::ROLE_CANDIDATE,
  83.         self::ROLE_PRESCRIBER,
  84.         self::ROLE_CONTACT
  85.     ];
  86.     /**
  87.      * @ORM\Id
  88.      * @ORM\GeneratedValue
  89.      * @ORM\Column(type="integer")
  90.      * @Groups({
  91.      *   "directory:people:search",
  92.      *   "candidate:read",
  93.      *   "contact:read",
  94.      *   "transaction-item:read",
  95.      *   "mandate:read",
  96.      *   "property:read",
  97.      *   "prescriber:read",
  98.      *   "property-visit:read",
  99.      *   "business-indication:item:read"
  100.      * })
  101.      */
  102.     protected ?int $id;
  103.     /**
  104.      * @ORM\Column(type="string", length=255)
  105.      * @Assert\Type("string")
  106.      * @Assert\NotBlank
  107.      * @Groups({
  108.      *    "directory:people:search",
  109.      *    "candidate:read","candidate:write","candidate:put",
  110.      *    "contact:read","contact:write","contact:put",
  111.      *    "transaction-item:read",
  112.      *    "mandate:read",
  113.      *    "property:read",
  114.      *    "prescriber:read","prescriber:write","prescriber:put",
  115.      *    "property-visit:read",
  116.      *    "business-indication:item:read"
  117.      * })
  118.      */
  119.     protected ?string $firstName;
  120.     /**
  121.      *
  122.      * @ORM\Column(type="string", length=255)
  123.      * @Assert\Type("string")
  124.      * @Assert\NotBlank
  125.      * @Groups({
  126.      *   "directory:people:search",
  127.      *   "candidate:read","candidate:write","candidate:put",
  128.      *   "contact:read","contact:write","contact:put",
  129.      *   "transaction-item:read",
  130.      *   "mandate:read",
  131.      *   "property:read",
  132.      *   "prescriber:read","prescriber:write","prescriber:put",
  133.      *   "property-visit:read",
  134.      *   "business-indication:item:read"
  135.      * })
  136.      *
  137.      */
  138.     protected ?string $lastName;
  139.     /**
  140.      * @ORM\Column(type="string", length=100, nullable=true)
  141.      *
  142.      * @Groups({
  143.      *     "candidate:read","candidate:write","candidate:put",
  144.      *     "contact:read","contact:write","contact:put"
  145.      * })
  146.      */
  147.     protected ?string $cin;
  148.     /**
  149.      * @ORM\Column(type="string", length=255)
  150.      * @Assert\Email
  151.      * @Assert\NotBlank
  152.      * @Groups({
  153.      *    "directory:people:search",
  154.      *    "candidate:read","candidate:write","candidate:put",
  155.      *    "contact:read","contact:write","contact:put",
  156.      *    "transaction-item:read",
  157.      *    "mandate:read",
  158.      *    "property:read",
  159.      *    "prescriber:read","prescriber:write","prescriber:put",
  160.      *    "business-indication:item:read"
  161.      * })
  162.      *
  163.      */
  164.     protected ?string $email;
  165.     /**
  166.      * @ORM\Column(type="date", nullable=true)
  167.      * @Groups({
  168.      *    "directory:people:search",
  169.      *    "candidate:read","candidate:write","candidate:put",
  170.      *    "contact:read","contact:write","contact:put",
  171.      *    "transaction-item:read",
  172.      *    "mandate:read",
  173.      *    "property:read",
  174.      *    "prescriber:read","prescriber:write","prescriber:put",
  175.      *    "business-indication:item:read"
  176.      * })
  177.      *
  178.      */
  179.     protected $birthDay;
  180.     /**
  181.      * @ORM\Column(type="string", length=255,nullable=true)
  182.      *
  183.      * @Groups({
  184.      *   "directory:people:search",
  185.      *   "candidate:read","candidate:write","candidate:put",
  186.      *   "contact:read","contact:write","contact:put",
  187.      *   "transaction-item:read",
  188.      *   "mandate:read",
  189.      *   "property:read",
  190.      *   "prescriber:read","prescriber:write","prescriber:put",
  191.      *   "business-indication:item:read"
  192.      *
  193.      * })
  194.      *
  195.      */
  196.     protected ?string $phone;
  197.     /**
  198.      * @ORM\Column(type="string", length=255)
  199.      * @Assert\NotBlank
  200.      * @Groups({
  201.      *    "directory:people:search",
  202.      *    "candidate:read","candidate:write","candidate:put",
  203.      *    "contact:read","contact:write","contact:put",
  204.      *    "prescriber:read","prescriber:write","prescriber:put",
  205.      *    "transaction-item:read",
  206.      *    "mandate:read",
  207.      *    "property:read",
  208.      *    "business-indication:item:read"
  209.      * })
  210.      *
  211.      */
  212.     protected ?string $mainPhone;
  213.     /**
  214.      * @ORM\OneToOne(targetEntity=Address::class, cascade={"persist", "remove"})
  215.      * @Assert\NotBlank
  216.      * @Groups({
  217.      *   "directory:people:search",
  218.      *   "candidate:read","candidate:write","candidate:put",
  219.      *   "contact:read","contact:write","contact:put",
  220.      *   "transaction-item:read",
  221.      *   "mandate:read",
  222.      *   "property:read",
  223.      *   "prescriber:read","prescriber:put","prescriber:write",
  224.      *   "business-indication:item:read"
  225.      * })
  226.      *
  227.      */
  228.     protected ?Address $address;
  229.     /**
  230.      * @ORM\ManyToOne(targetEntity=Gender::class, inversedBy="abstractPeople")
  231.      * @ORM\JoinColumn(nullable=false)
  232.      * @Assert\NotBlank
  233.      * @Groups({
  234.      *   "directory:people:search",
  235.      *   "candidate:read","candidate:write","candidate:put",
  236.      *   "contact:read","contact:write","contact:put",
  237.      *   "transaction-item:read",
  238.      *   "mandate:read",
  239.      *   "property:read","prescriber:read","prescriber:put","prescriber:write",
  240.      *   "business-indication:item:read"
  241.      * })
  242.      *
  243.      */
  244.     protected ?Gender $gender;
  245.     /**
  246.      * @ORM\Column(type="json")
  247.      *
  248.      * @Groups({
  249.      *    "directory:people:search",
  250.      *    "candidate:read",
  251.      *     "prescriber:read",
  252.      * })
  253.      */
  254.     protected array $roles = [];
  255.     /**
  256.      * @ORM\ManyToOne(targetEntity=ReferencePersonMaritalStatus::class)
  257.      *
  258.      * @Groups({
  259.      *   "candidate:read","candidate:write","candidate:put"
  260.      * })
  261.      */
  262.     private ?ReferencePersonMaritalStatus $referenceMaritalStatus;
  263.     /**
  264.      * @ORM\Column(type="string", length=255, nullable=true)
  265.      *
  266.      * @Groups({
  267.      *   "candidate:read","candidate:write","candidate:put",
  268.      *   "contact:read","contact:write","contact:put",
  269.      *   "prescriber:read","prescriber:write","prescriber:put"
  270.      * })
  271.      */
  272.     protected ?string $companyName;
  273.     /**
  274.      * ICE (identifiant commun de l'entreprise)
  275.      * @ORM\Column(type="string", length=255, nullable=true)
  276.      *
  277.      * @Groups({
  278.      *   "candidate:read","candidate:write","candidate:put",
  279.      *   "contact:read","contact:write","contact:put",
  280.      *   "prescriber:read","prescriber:write","prescriber:put"
  281.      * })
  282.      */
  283.     protected ?string $commonCompanyIdentifier;
  284.     /**
  285.      * @ORM\Column(type="string", length=100, nullable=true)
  286.      *
  287.      * @Groups({
  288.      *     "candidate:read","candidate:write","candidate:put",
  289.      *     "contact:read","contact:write","contact:put",
  290.      *     "prescriber:read","prescriber:write","prescriber:put"
  291.      * })
  292.      */
  293.     protected ?string $rc;
  294.     /**
  295.      * @ORM\Column(type="string", length=255, nullable=true)
  296.      *
  297.      * @Groups({
  298.      *    "directory:people:search",
  299.      *    "candidate:write","candidate:put",
  300.      *    "contact:write","contact:put",
  301.      *    "prescriber:write","prescriber:put",
  302.      *    "siege:write",
  303.      *    "property:read"
  304.      * })
  305.      */
  306.     private ?string $personType null;
  307.     public function getId(): ?int
  308.     {
  309.         return $this->id;
  310.     }
  311.     public function getFirstName(): ?string
  312.     {
  313.         return $this->firstName;
  314.     }
  315.     public function setFirstName(string $firstName): self
  316.     {
  317.         $this->firstName $firstName;
  318.         return $this;
  319.     }
  320.     public function getLastName(): ?string
  321.     {
  322.         return $this->lastName;
  323.     }
  324.     public function setLastName(string $lastName): self
  325.     {
  326.         $this->lastName $lastName;
  327.         return $this;
  328.     }
  329.     public function getBirthDay(): ?DateTimeInterface
  330.     {
  331.         return $this->birthDay;
  332.     }
  333.     public function setBirthDay(?DateTimeInterface $birthDay): self
  334.     {
  335.         $this->birthDay $birthDay;
  336.         return $this;
  337.     }
  338.     public function getPhone(): ?string
  339.     {
  340.         return $this->phone;
  341.     }
  342.     public function setPhone(?string $phone): self
  343.     {
  344.         $this->phone $phone;
  345.         return $this;
  346.     }
  347.     public function getMainPhone(): ?string
  348.     {
  349.         return $this->mainPhone;
  350.     }
  351.     public function setMainPhone(string $mainPhone): self
  352.     {
  353.         $this->mainPhone $mainPhone;
  354.         return $this;
  355.     }
  356.     /**
  357.      * @return string|null
  358.      */
  359.     public function getCin(): ?string
  360.     {
  361.         return $this->cin;
  362.     }
  363.     /**
  364.      * @param string|null $cin
  365.      *
  366.      * @return $this
  367.      */
  368.     public function setCin(?string $cin): self
  369.     {
  370.         $this->cin $cin;
  371.         return $this;
  372.     }
  373.     public function getEmail(): ?string
  374.     {
  375.         return $this->email;
  376.     }
  377.     /**
  378.      * @param string $email
  379.      * @return $this
  380.      */
  381.     public function setEmail(string $email): self
  382.     {
  383.         $this->email $email;
  384.         return $this;
  385.     }
  386.     public function getAddress(): ?Address
  387.     {
  388.         return $this->address;
  389.     }
  390.     public function setAddress(Address $address): self
  391.     {
  392.         $this->address $address;
  393.         return $this;
  394.     }
  395.     public function getGender(): ?Gender
  396.     {
  397.         return $this->gender;
  398.     }
  399.     public function setGender(?Gender $gender): self
  400.     {
  401.         $this->gender $gender;
  402.         return $this;
  403.     }
  404.     public function getRoles(): array
  405.     {
  406.         return $this->roles;
  407.     }
  408.     public function setRoles(array $roles): self
  409.     {
  410.         $this->roles $roles;
  411.         return $this;
  412.     }
  413.     public function getReferenceMaritalStatus(): ?ReferencePersonMaritalStatus
  414.     {
  415.         return $this->referenceMaritalStatus;
  416.     }
  417.     public function setReferenceMaritalStatus(?ReferencePersonMaritalStatus $referenceMaritalStatus): self
  418.     {
  419.         $this->referenceMaritalStatus $referenceMaritalStatus;
  420.         return $this;
  421.     }
  422.     public function getCompanyName(): ?string
  423.     {
  424.         return $this->companyName;
  425.     }
  426.     public function setCompanyName(?string $companyName): self
  427.     {
  428.         $this->companyName $companyName;
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return string|null
  433.      */
  434.     public function getCommonCompanyIdentifier(): ?string
  435.     {
  436.         return $this->commonCompanyIdentifier;
  437.     }
  438.     /**
  439.      * @param string|null $commonCompanyIdentifier
  440.      *
  441.      * @return $this
  442.      */
  443.     public function setCommonCompanyIdentifier(?string $commonCompanyIdentifier): self
  444.     {
  445.         $this->commonCompanyIdentifier $commonCompanyIdentifier;
  446.         return $this;
  447.     }
  448.     /**
  449.      * @return string|null
  450.      */
  451.     public function getRc(): ?string
  452.     {
  453.         return $this->rc;
  454.     }
  455.     /**
  456.      * @param string|null $rc
  457.      *
  458.      * @return $this
  459.      */
  460.     public function setRc(?string $rc): self
  461.     {
  462.         $this->rc $rc;
  463.         return $this;
  464.     }
  465.     /**
  466.      * @return bool
  467.      */
  468.     public function isCompany(): bool
  469.     {
  470.         if (null === $this->getPersonType()) {
  471.             return false;
  472.         }
  473.         return $this->getPersonType() === self::PERSON_TYPE_MORAL;
  474.     }
  475.     /**
  476.      * @return bool
  477.      */
  478.     public function isFemale(): bool
  479.     {
  480.         if (null === $this->getGender()) {
  481.             return false;
  482.         }
  483.         return $this->getGender()->getCode(
  484.         ) === Gender::REFERENCE_CODE_GENDER_FEMALE;
  485.     }
  486.     /**
  487.      * @return bool
  488.      */
  489.     public function isMale(): bool
  490.     {
  491.         if (null === $this->getGender()) {
  492.             return false;
  493.         }
  494.         return $this->getGender()->getCode(
  495.         ) === Gender::REFERENCE_CODE_GENDER_MALE;
  496.     }
  497.     /**
  498.      * @return string
  499.      * @Groups({
  500.      *   "directory:people:search",
  501.      *   "candidate:read","candidate:write","candidate:put",
  502.      *   "contact:read","contact:write","contact:put",
  503.      *   "transaction-item:read",
  504.      *   "mandate:read",
  505.      *   "property:read",
  506.      *   "prescriber:read","prescriber:write","prescriber:put",
  507.      *   "property-visit:read",
  508.      *   "business-indication:item:read"
  509.      * })
  510.      */
  511.     public function getFullName(): string
  512.     {
  513.         if (null === $this->firstName && null === $this->lastName) {
  514.             return '';
  515.         }
  516.         return sprintf('%s %s'ucfirst($this->firstName), strtoupper($this->lastName));
  517.     }
  518.     public function getPersonType(): ?string
  519.     {
  520.         return $this->personType;
  521.     }
  522.     public function setPersonType(?string $personType): self
  523.     {
  524.         $this->personType $personType;
  525.         return $this;
  526.     }
  527.     /**
  528.      * @return PersonTypeReference|null
  529.      *
  530.      * @Groups({
  531.      *    "directory:people:search",
  532.      *    "candidate:read",
  533.      *    "contact:read",
  534.      *    "transaction-item:read",
  535.      *    "mandate:read",
  536.      *    "property:read",
  537.      *    "prescriber:read",
  538.      *    "property-visit:read",
  539.      *    "business-indication:item:read",
  540.      * })
  541.      *
  542.      * @SerializedName("personType")
  543.      */
  544.     public function getReferencePersonType(): ?PersonTypeReference
  545.     {
  546.         if (null === $this->personType) {
  547.             return null;
  548.         }
  549.         return PersonTypeReference::createFromCode($this->getPersonType());
  550.     }
  551. }