<?php
namespace Products\NotificationsBundle\Entity\Notifications;
use App\Model\Query\ConditionQuery\ConditionQuery;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Products\NotificationsBundle\Entity\AbstractNotification;
use Products\NotificationsBundle\Entity\Automation;
use Products\NotificationsBundle\Entity\Lists\ConditionList;
use Products\NotificationsBundle\Entity\Notifications\Channels\ChannelsInterface;
/**
*
* @ORM\Entity(
* repositoryClass = "Products\NotificationsBundle\Doctrine\Repository\Notifications\InvocationRepository",
* )
*/
class Invocation extends AbstractNotification
{
public const DISCR = 'invocation';
/**
* @var Automation|null
*
* @ORM\ManyToOne(
* targetEntity = Automation::class,
* inversedBy="invocations"
* )
* @ORM\JoinColumn(
* name = "automation",
* referencedColumnName = "id",
* nullable = true,
* onDelete = "SET NULL",
* )
*/
private ?Automation $automation;
/**
* @var ConditionQuery|null
*
* @ORM\Column(
* type = "condition_query",
* nullable = true,
* )
*/
private ?ConditionQuery $conditionQuery;
/**
* @var DateTime|null
*
* @ORM\Column(
* type = "datetime",
* nullable = false,
* )
*/
private ?DateTime $invocationTimestamp;
/**
* @return Automation|null
*/
public function getAutomation(): ?Automation
{
return $this->automation;
}
/**
* @param Automation|null $automation
* @return self
*/
public function setAutomation(?Automation $automation): self
{
$this->automation = $automation;
return $this;
}
/**
* @return ConditionQuery|null
*/
public function getConditionQuery(): ?ConditionQuery
{
return $this->conditionQuery;
}
/**
* @param ConditionQuery|null $conditionQuery
* @return self
*/
public function setConditionQuery(?ConditionQuery $conditionQuery): self
{
$this->conditionQuery = $conditionQuery;
return $this;
}
/**
* @return DateTime|null
*/
public function getInvocationTimestamp(): ?DateTime
{
return $this->invocationTimestamp;
}
/**
* @param DateTime|null $invocationTimestamp
* @return self
*/
public function setInvocationTimestamp(?DateTime $invocationTimestamp): self
{
$this->invocationTimestamp = $invocationTimestamp;
return $this;
}
/**
* {@inheritDoc}
*/
public function getLists(?Criteria $criteria = null): Collection
{
$conditionQuery = $this->getConditionQuery();
if ( ! $conditionQuery instanceof ConditionQuery) {
return new ArrayCollection();
}
return new ArrayCollection([
(new ConditionList($conditionQuery))
->setTenant($this->getTenant()),
]);
}
/**
* {@inheritDoc}
*/
public function setLists(iterable $lists): self
{
return $this;
}
/**
* {@inheritDoc}
*/
public function setChannels(int $channels): AbstractNotification
{
$skips = ChannelsInterface::CHANNELS__WEBSITE
| ChannelsInterface::CHANNELS__TWITTER
| ChannelsInterface::CHANNELS__FACEBOOK;
return parent::setChannels($channels & ~$skips);
}
/**
* {@inheritDoc}
*/
public function isPublic(): bool
{
return false;
}
}