src/Entity/CRM/MailingEntry.php line 19
<?phpnamespace App\Entity\CRM;use App\Repository\MailingEntryRepository;use DateTime;use DateTimeImmutable;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: MailingEntryRepository::class)]#[ORM\Table(name: 'mailing_entry')]#[ORM\UniqueConstraint(name: 'uniq_email_group', columns: ['email', 'group_name'])]#[ORM\Index(name: 'idx_group_name', columns: ['group_name'])]#[ORM\HasLifecycleCallbacks]#[UniqueEntity(fields: ['email', 'groupName'], message: 'Ten email w tej grupie już istnieje.')]class MailingEntry{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[Assert\NotBlank]#[Assert\Length(max: 320)]#[Assert\Email(mode: Assert\Email::VALIDATION_MODE_STRICT)]#[Assert\Regex(pattern: '/^[^\s;]+$/u', message: 'Email nie może zawierać spacji ani średników')]#[ORM\Column(length: 320)]private string $email;#[Assert\NotBlank]#[Assert\Length(max: 100)]#[Assert\Regex(pattern: '/^[^;]+$/u', message: 'Nazwa grupy nie może zawierać średników')]#[ORM\Column(name: 'group_name', length: 100)]private string $groupName;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private DateTime $createdAt;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private DateTime $updatedAt;#[ORM\Column]private ?bool $isActive = null;public function __construct(){$this->createdAt = new DateTime();$this->isActive = true;}public function getId(): ?int{return $this->id;}public function getEmail(): string{return $this->email;}public function setEmail(string $email): self{$email = trim($email);$this->email = mb_strtolower($email);return $this;}public function getGroupName(): string{return $this->groupName;}public function setGroupName(string $groupName): self{$this->groupName = trim($groupName);return $this;}public function getCreatedAt(): DateTime{return $this->createdAt;}public function getUpdatedAt(): DateTime{return $this->updatedAt;}#[ORM\PrePersist]public function onPrePersist(): void{$now = new DateTime('now');$this->createdAt = $now;$this->updatedAt = $now;// normalize to ensure constraints hold$this->email = mb_strtolower(trim($this->email));$this->groupName = trim($this->groupName);}#[ORM\PreUpdate]public function onPreUpdate(): void{$this->updatedAt = new DateTime('now');$this->email = mb_strtolower(trim($this->email));$this->groupName = trim($this->groupName);}public function isIsActive(): ?bool{return $this->isActive;}public function setIsActive(bool $isActive): static{$this->isActive = $isActive;return $this;}}