src/Entity/Notification.php line 26

Open in your IDE?
  1. <?php
  2. /**
  3.  * @license Silk Software House Sp. Z O.O.
  4.  */
  5. declare(strict_types=1);
  6. namespace App\Entity;
  7. use App\Entity\Interfaces\ChannelInterface;
  8. use App\Entity\Traits\IdTrait;
  9. use App\Entity\Traits\TimePreUpdateTrait;
  10. use App\Entity\Traits\TimeTrait;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use DateTime;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use App\Validator\Constraints as AppAssert;
  15. /**
  16.  * Class Notification.
  17.  *
  18.  * @ORM\Entity(repositoryClass="App\Repository\NotificationRepository")
  19.  * @ORM\Table(name="notifications")
  20.  * @ORM\HasLifecycleCallbacks()
  21.  */
  22. class Notification implements ChannelInterface
  23. {
  24.     use IdTrait;
  25.     use TimeTrait;
  26.     use TimePreUpdateTrait;
  27.     /**
  28.      * User.
  29.      *
  30.      * @var User
  31.      *
  32.      * @ORM\ManyToOne(targetEntity="App\Entity\User", cascade={"persist"})
  33.      * @ORM\JoinColumn(name="user_id", nullable=false)
  34.      */
  35.     private User $user;
  36.     /**
  37.      * ChannelSetting.
  38.      *
  39.      * @var ChannelSetting
  40.      *
  41.      * @AppAssert\ChannelNotBlank()
  42.      *
  43.      * @ORM\ManyToOne(targetEntity="App\Entity\ChannelSetting", cascade={"persist"})
  44.      * @ORM\JoinColumn(name="channel_setting_id", nullable=false)
  45.      */
  46.     private ChannelSetting $channelSetting;
  47.     /**
  48.      * Trigger value.
  49.      *
  50.      * @var float
  51.      *
  52.      * @Assert\NotBlank()
  53.      *
  54.      * @ORM\Column(name="strength_trigger", nullable=false, type="float", options={"comment": "Value that will trigger this notification."})
  55.      */
  56.     private float $strengthTrigger;
  57.     /**
  58.      * Time, when was this notification triggered
  59.      *
  60.      * @var DateTime|null
  61.      *
  62.      * @ORM\Column(name="triggered_at", nullable=true, type="datetime", options={"comment": "When was this notification triggered."})
  63.      */
  64.     private ?DateTime $triggeredAt;
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private ?string $email;
  69.     /**
  70.      * Get user.
  71.      *
  72.      * @return User
  73.      */
  74.     public function getUser(): ?User
  75.     {
  76.         return $this->user;
  77.     }
  78.     /**
  79.      * Set user.
  80.      *
  81.      * @param User $user
  82.      *
  83.      * @return Notification
  84.      */
  85.     public function setUser(User $user): self
  86.     {
  87.         $this->user $user;
  88.         return $this;
  89.     }
  90.     /**
  91.      * Get strength trigger.
  92.      *
  93.      * @return float|null
  94.      */
  95.     public function getStrengthTrigger(): ?float
  96.     {
  97.         return $this->strengthTrigger;
  98.     }
  99.     /**
  100.      * Set the strength trigger.
  101.      *
  102.      * @param float|null $strengthTrigger
  103.      *
  104.      * @return Notification
  105.      */
  106.     public function setStrengthTrigger(?float $strengthTrigger): self
  107.     {
  108.         $this->strengthTrigger $strengthTrigger;
  109.         return $this;
  110.     }
  111.     /**
  112.      * Get channel setting.
  113.      *
  114.      * @return ChannelSetting
  115.      */
  116.     public function getChannelSetting(): ?ChannelSetting
  117.     {
  118.         return $this->channelSetting;
  119.     }
  120.     /**
  121.      * Set channel setting.
  122.      *
  123.      * @param ChannelSetting|null $channelSetting
  124.      *
  125.      * @return Notification
  126.      */
  127.     public function setChannelSetting(?ChannelSetting $channelSetting): self
  128.     {
  129.         $this->channelSetting $channelSetting;
  130.         return $this;
  131.     }
  132.     /**
  133.      * Get is triggered.
  134.      *
  135.      * @return bool
  136.      */
  137.     public function getIsTriggered(): bool
  138.     {
  139.         return null !== $this->triggeredAt;
  140.     }
  141.     /**
  142.      * Get triggered at.
  143.      *
  144.      * @return DateTime|null
  145.      */
  146.     public function getTriggeredAt(): ?DateTime
  147.     {
  148.         return $this->triggeredAt;
  149.     }
  150.     /**
  151.      * Set triggered at.
  152.      *
  153.      * @param DateTime|null $triggeredAt
  154.      *
  155.      * @return Notification
  156.      */
  157.     public function setTriggeredAt(?DateTime $triggeredAt): self
  158.     {
  159.         $this->triggeredAt $triggeredAt;
  160.         return $this;
  161.     }
  162.     /**
  163.      * Get measurement.
  164.      *
  165.      * @return Measurement|null
  166.      */
  167.     public function getMeasurement(): ?Measurement
  168.     {
  169.         return $this->channelSetting $this->channelSetting->getMeasurement() : null;
  170.     }
  171.     /**
  172.      * Has channel.
  173.      *
  174.      * @return bool
  175.      */
  176.     public function hasChannel(): bool
  177.     {
  178.         return null !== $this->channelSetting;
  179.     }
  180.     public function getEmail(): ?string
  181.     {
  182.         return $this->email;
  183.     }
  184.     public function setEmail(?string $email): self
  185.     {
  186.         $this->email $email;
  187.         return $this;
  188.     }
  189. }