<?php
namespace App\Entity;
use App\Repository\CalendarEventKindRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CalendarEventKindRepository::class)
*/
class CalendarEventKind
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nameRegex;
/**
* @ORM\Column(type="string", length=20, unique=true)
*/
private $kindId;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getNameRegex(): ?string
{
return $this->nameRegex;
}
public function getNameRegexWords(): array
{
if (!$this->getNameRegex()) {
return [];
}
$wordsStr = $this->getNameRegex();
return preg_split("/, */", $wordsStr, -1, PREG_SPLIT_NO_EMPTY);
}
public function getNameFullRegex(): ?string
{
static $nonLetterRegex = "[^а-яА-ЯёЁ\s\-]";
if (!$this->getNameRegex()) {
return null;
}
$words = $this->getNameRegexWords();
// $words = array_map(function ($word) use ($nonLetterRegex) {
// $word = preg_quote($word, "/");
// $word .= "($nonLetterRegex|$)";
// return $word;
// }, $words);
return "/" . implode("|", $words) . "/u";
}
public function setNameRegex(?string $nameRegex): self
{
$this->nameRegex = $nameRegex;
return $this;
}
public function getKindId(): ?string
{
return $this->kindId;
}
public function setKindId(string $kindId): self
{
$this->kindId = $kindId;
return $this;
}
}