<?php
/**
* @license Silk Software House Sp. Z O.O.
*/
declare(strict_types=1);
namespace App\Entity;
use App\Entity\Interfaces\ChannelInterface;
use App\Entity\Traits\IdTrait;
use App\Entity\Traits\TimePreUpdateTrait;
use App\Entity\Traits\TimeTrait;
use Doctrine\ORM\Mapping as ORM;
use DateTime;
use Symfony\Component\Validator\Constraints as Assert;
use App\Validator\Constraints as AppAssert;
/**
* Class Notification.
*
* @ORM\Entity(repositoryClass="App\Repository\NotificationRepository")
* @ORM\Table(name="notifications")
* @ORM\HasLifecycleCallbacks()
*/
class Notification implements ChannelInterface
{
use IdTrait;
use TimeTrait;
use TimePreUpdateTrait;
/**
* User.
*
* @var User
*
* @ORM\ManyToOne(targetEntity="App\Entity\User", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", nullable=false)
*/
private User $user;
/**
* ChannelSetting.
*
* @var ChannelSetting
*
* @AppAssert\ChannelNotBlank()
*
* @ORM\ManyToOne(targetEntity="App\Entity\ChannelSetting", cascade={"persist"})
* @ORM\JoinColumn(name="channel_setting_id", nullable=false)
*/
private ChannelSetting $channelSetting;
/**
* Trigger value.
*
* @var float
*
* @Assert\NotBlank()
*
* @ORM\Column(name="strength_trigger", nullable=false, type="float", options={"comment": "Value that will trigger this notification."})
*/
private float $strengthTrigger;
/**
* Time, when was this notification triggered
*
* @var DateTime|null
*
* @ORM\Column(name="triggered_at", nullable=true, type="datetime", options={"comment": "When was this notification triggered."})
*/
private ?DateTime $triggeredAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $email;
/**
* Get user.
*
* @return User
*/
public function getUser(): ?User
{
return $this->user;
}
/**
* Set user.
*
* @param User $user
*
* @return Notification
*/
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
/**
* Get strength trigger.
*
* @return float|null
*/
public function getStrengthTrigger(): ?float
{
return $this->strengthTrigger;
}
/**
* Set the strength trigger.
*
* @param float|null $strengthTrigger
*
* @return Notification
*/
public function setStrengthTrigger(?float $strengthTrigger): self
{
$this->strengthTrigger = $strengthTrigger;
return $this;
}
/**
* Get channel setting.
*
* @return ChannelSetting
*/
public function getChannelSetting(): ?ChannelSetting
{
return $this->channelSetting;
}
/**
* Set channel setting.
*
* @param ChannelSetting|null $channelSetting
*
* @return Notification
*/
public function setChannelSetting(?ChannelSetting $channelSetting): self
{
$this->channelSetting = $channelSetting;
return $this;
}
/**
* Get is triggered.
*
* @return bool
*/
public function getIsTriggered(): bool
{
return null !== $this->triggeredAt;
}
/**
* Get triggered at.
*
* @return DateTime|null
*/
public function getTriggeredAt(): ?DateTime
{
return $this->triggeredAt;
}
/**
* Set triggered at.
*
* @param DateTime|null $triggeredAt
*
* @return Notification
*/
public function setTriggeredAt(?DateTime $triggeredAt): self
{
$this->triggeredAt = $triggeredAt;
return $this;
}
/**
* Get measurement.
*
* @return Measurement|null
*/
public function getMeasurement(): ?Measurement
{
return $this->channelSetting ? $this->channelSetting->getMeasurement() : null;
}
/**
* Has channel.
*
* @return bool
*/
public function hasChannel(): bool
{
return null !== $this->channelSetting;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
}