src/Entity/SeasonGoogleChatConfig.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SeasonGoogleChatConfigRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassSeasonGoogleChatConfigRepository::class)]
  9. class SeasonGoogleChatConfig
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\OneToOne(inversedBy'googleChatConfig'cascade: ['persist''remove'])]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private ?Season $season null;
  18.     #[ORM\Column(length500nullabletrue)]
  19.     private ?string $webhookUrl null;
  20.     #[ORM\Column(length255nullabletrue)]
  21.     private ?string $spaceName null;
  22.     #[ORM\Column]
  23.     private ?bool $isEnabled false;
  24.     #[ORM\Column(length50)]
  25.     private ?string $timezone 'America/New_York';
  26.     #[ORM\OneToMany(mappedBy'googleChatConfig'targetEntitySeasonGoogleChatMessageType::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  27.     private Collection $messageTypes;
  28.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  29.     private ?\DateTimeInterface $createdAt null;
  30.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  31.     private ?\DateTimeInterface $updatedAt null;
  32.     public function __construct()
  33.     {
  34.         $this->messageTypes = new ArrayCollection();
  35.         $this->createdAt = new \DateTime();
  36.         $this->updatedAt = new \DateTime();
  37.     }
  38.     public function __toString(): string
  39.     {
  40.         return $this->season?->getName() . ' - Google Chat Config' ?? 'Google Chat Config';
  41.     }
  42.     #[ORM\PreUpdate]
  43.     public function setUpdatedAtValue(): void
  44.     {
  45.         $this->updatedAt = new \DateTime();
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getSeason(): ?Season
  52.     {
  53.         return $this->season;
  54.     }
  55.     public function setSeason(Season $season): static
  56.     {
  57.         $this->season $season;
  58.         return $this;
  59.     }
  60.     public function getWebhookUrl(): ?string
  61.     {
  62.         return $this->webhookUrl;
  63.     }
  64.     public function setWebhookUrl(?string $webhookUrl): static
  65.     {
  66.         $this->webhookUrl $webhookUrl;
  67.         return $this;
  68.     }
  69.     public function getSpaceName(): ?string
  70.     {
  71.         return $this->spaceName;
  72.     }
  73.     public function setSpaceName(?string $spaceName): static
  74.     {
  75.         $this->spaceName $spaceName;
  76.         return $this;
  77.     }
  78.     public function isIsEnabled(): ?bool
  79.     {
  80.         return $this->isEnabled;
  81.     }
  82.     public function setIsEnabled(bool $isEnabled): static
  83.     {
  84.         $this->isEnabled $isEnabled;
  85.         return $this;
  86.     }
  87.     public function getTimezone(): ?string
  88.     {
  89.         return $this->timezone;
  90.     }
  91.     public function setTimezone(string $timezone): static
  92.     {
  93.         $this->timezone $timezone;
  94.         return $this;
  95.     }
  96.     /**
  97.      * @return Collection<int, SeasonGoogleChatMessageType>
  98.      */
  99.     public function getMessageTypes(): Collection
  100.     {
  101.         return $this->messageTypes;
  102.     }
  103.     public function addMessageType(SeasonGoogleChatMessageType $messageType): static
  104.     {
  105.         if (!$this->messageTypes->contains($messageType)) {
  106.             $this->messageTypes->add($messageType);
  107.             $messageType->setGoogleChatConfig($this);
  108.         }
  109.         return $this;
  110.     }
  111.     public function removeMessageType(SeasonGoogleChatMessageType $messageType): static
  112.     {
  113.         if ($this->messageTypes->removeElement($messageType)) {
  114.             // set the owning side to null (unless already changed)
  115.             if ($messageType->getGoogleChatConfig() === $this) {
  116.                 $messageType->setGoogleChatConfig(null);
  117.             }
  118.         }
  119.         return $this;
  120.     }
  121.     public function getCreatedAt(): ?\DateTimeInterface
  122.     {
  123.         return $this->createdAt;
  124.     }
  125.     public function setCreatedAt(\DateTimeInterface $createdAt): static
  126.     {
  127.         $this->createdAt $createdAt;
  128.         return $this;
  129.     }
  130.     public function getUpdatedAt(): ?\DateTimeInterface
  131.     {
  132.         return $this->updatedAt;
  133.     }
  134.     public function setUpdatedAt(\DateTimeInterface $updatedAt): static
  135.     {
  136.         $this->updatedAt $updatedAt;
  137.         return $this;
  138.     }
  139.     /**
  140.      * Check if a specific message type is enabled
  141.      */
  142.     public function isMessageTypeEnabled(string $messageType): bool
  143.     {
  144.         foreach ($this->messageTypes as $type) {
  145.             if ($type->getMessageType() === $messageType && $type->isIsEnabled()) {
  146.                 return true;
  147.             }
  148.         }
  149.         return false;
  150.     }
  151.     /**
  152.      * Get message type configuration
  153.      */
  154.     public function getMessageTypeConfig(string $messageType): ?SeasonGoogleChatMessageType
  155.     {
  156.         foreach ($this->messageTypes as $type) {
  157.             if ($type->getMessageType() === $messageType) {
  158.                 return $type;
  159.             }
  160.         }
  161.         return null;
  162.     }
  163. }