<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ContactRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ApiResource(
* messenger=true,
* attributes={
* "normalization_context"={
* "groups"={
* "Contact:io",
* "Contact:output"
* }
* },
* "denormalization_context"={
* "groups"={
* "Contact:io",
* "Contact:input"
* }
* }
* },
* collectionOperations={
* "post"={
* "method"="POST",
* "access_control"="is_granted('ROLE_USER')"
* },
* "public-post"={
* "method"="POST",
* "path"="/public/contacts",
* "access_control"="is_granted('ROLE_PUBLIC')"
* },
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* },
* },
* itemOperations={
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
* }
* }
* )
* @ORM\Entity(repositoryClass=ContactRepository::class)
*/
class Contact
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @ApiProperty(identifier=true)
* @Groups({"Contact:output"})
*/
private $id;
/**
* @ORM\Column(type="string", length=5, nullable=true)
* @Groups({"Contact:io"})
*/
private $civility;
/**
* @ORM\Column(type="string", length=40)
* @Groups({"Contact:io"})
* @Assert\NotBlank()
*/
private $firstname;
/**
* @ORM\Column(type="string", length=40)
* @Groups({"Contact:io"})
* @Assert\NotBlank()
*/
private $lastname;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"Contact:io"})
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;
/**
* @ORM\Column(type="string", length=2048)
* @Groups({"Contact:io"})
* @Assert\NotBlank()
*/
private $message;
/**
* @ORM\Column(type="string", length=180, nullable=true)
* @SerializedName("company_name")
* @Groups({"Contact:io"})
*/
private ?string $companyName;
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getCivility()
{
return $this->civility;
}
public function getFormattedCivility()
{
return ucfirst(strtolower($this->civility));
}
/**
* @param mixed $civility
* @return Contact
*/
public function setCivility($civility)
{
$this->civility = $civility;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName($companyName): self
{
$this->companyName = $companyName;
return $this;
}
}