src/Entity/Contact.php line 56

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\ContactRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Ramsey\Uuid\Doctrine\UuidGenerator;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Symfony\Component\Serializer\Annotation\SerializedName;
  12. /**
  13.  * @ApiResource(
  14.  *      messenger=true,
  15.  *      attributes={
  16.  *          "normalization_context"={
  17.  *              "groups"={
  18.  *                  "Contact:io",
  19.  *                  "Contact:output"
  20.  *              }
  21.  *          },
  22.  *          "denormalization_context"={
  23.  *              "groups"={
  24.  *                  "Contact:io",
  25.  *                  "Contact:input"
  26.  *              }
  27.  *          }
  28.  *      },
  29.  *     collectionOperations={
  30.  *          "post"={
  31.  *              "method"="POST",
  32.  *              "access_control"="is_granted('ROLE_USER')"
  33.  *          },
  34.  *          "public-post"={
  35.  *              "method"="POST",
  36.  *              "path"="/public/contacts",
  37.  *              "access_control"="is_granted('ROLE_PUBLIC')"
  38.  *          },
  39.  *          "get"={
  40.  *              "method"="GET",
  41.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  42.  *          },
  43.  *     },
  44.  *     itemOperations={
  45.  *          "get"={
  46.  *              "method"="GET",
  47.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  48.  *          }
  49.  *     }
  50.  * )
  51.  * @ORM\Entity(repositoryClass=ContactRepository::class)
  52.  */
  53. class Contact
  54. {
  55.     /**
  56.      * Hook timestampable behavior
  57.      * updates createdAt, updatedAt fields
  58.      */
  59.     use TimestampableEntity;
  60.     /**
  61.      * @ORM\Id
  62.      * @ORM\Column(type="uuid", unique=true)
  63.      * @ORM\GeneratedValue(strategy="CUSTOM")
  64.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  65.      * @ApiProperty(identifier=true)
  66.      * @Groups({"Contact:output"})
  67.      */
  68.     private $id;
  69.     /**
  70.      * @ORM\Column(type="string", length=5, nullable=true)
  71.      * @Groups({"Contact:io"})
  72.      */
  73.     private $civility;
  74.     /**
  75.      * @ORM\Column(type="string", length=40)
  76.      * @Groups({"Contact:io"})
  77.      * @Assert\NotBlank()
  78.      */
  79.     private $firstname;
  80.     /**
  81.      * @ORM\Column(type="string", length=40)
  82.      * @Groups({"Contact:io"})
  83.      * @Assert\NotBlank()
  84.      */
  85.     private $lastname;
  86.     /**
  87.      * @ORM\Column(type="string", length=255)
  88.      * @Groups({"Contact:io"})
  89.      * @Assert\NotBlank()
  90.      * @Assert\Email()
  91.      */
  92.     private $email;
  93.     /**
  94.      * @ORM\Column(type="string", length=2048)
  95.      * @Groups({"Contact:io"})
  96.      * @Assert\NotBlank()
  97.      */
  98.     private $message;
  99.     /**
  100.      * @ORM\Column(type="string", length=180, nullable=true)
  101.      * @SerializedName("company_name")
  102.      * @Groups({"Contact:io"})
  103.      */
  104.     private ?string $companyName;
  105.     public function getId()
  106.     {
  107.         return $this->id;
  108.     }
  109.     /**
  110.      * @return mixed
  111.      */
  112.     public function getCivility()
  113.     {
  114.         return $this->civility;
  115.     }
  116.     public function getFormattedCivility()
  117.     {
  118.         return ucfirst(strtolower($this->civility));
  119.     }
  120.     /**
  121.      * @param mixed $civility
  122.      * @return Contact
  123.      */
  124.     public function setCivility($civility)
  125.     {
  126.         $this->civility $civility;
  127.         return $this;
  128.     }
  129.     public function getFirstname(): ?string
  130.     {
  131.         return $this->firstname;
  132.     }
  133.     public function setFirstname(string $firstname): self
  134.     {
  135.         $this->firstname $firstname;
  136.         return $this;
  137.     }
  138.     public function getLastname(): ?string
  139.     {
  140.         return $this->lastname;
  141.     }
  142.     public function setLastname(string $lastname): self
  143.     {
  144.         $this->lastname $lastname;
  145.         return $this;
  146.     }
  147.     public function getEmail(): ?string
  148.     {
  149.         return $this->email;
  150.     }
  151.     public function setEmail(string $email): self
  152.     {
  153.         $this->email $email;
  154.         return $this;
  155.     }
  156.     public function getMessage(): ?string
  157.     {
  158.         return $this->message;
  159.     }
  160.     public function setMessage(string $message): self
  161.     {
  162.         $this->message $message;
  163.         return $this;
  164.     }
  165.     public function getCompanyName(): ?string
  166.     {
  167.         return $this->companyName;
  168.     }
  169.     public function setCompanyName($companyName): self
  170.     {
  171.         $this->companyName $companyName;
  172.         return $this;
  173.     }
  174. }