<?php
namespace Products\NotificationsBundle\Entity;
use App\Entity\Shared\DiscardableInterface;
use App\Entity\Shared\DiscardableTrait;
use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
use Cms\CoreBundle\Model\Interfaces\OneRosterable\OneRosterableInterface;
use Cms\CoreBundle\Model\Interfaces\OneRosterable\OneRosterableTrait;
use Cms\TenantBundle\Entity\TenantedEntity;
use Doctrine\ORM\Mapping as ORM;
use Products\NotificationsBundle\Entity\Recipients\AppRecipient;
use Products\NotificationsBundle\Entity\Recipients\EmailRecipient;
use Products\NotificationsBundle\Entity\Recipients\PhoneRecipient;
use Products\NotificationsBundle\Util\PreferencesTrait;
/**
* Class ProfileContact
* @package Products\NotificationsBundle\Entity
*
* @ORM\Entity(
* repositoryClass = "Products\NotificationsBundle\Doctrine\Repository\ProfileContactRepository",
* )
* @ORM\Table(
* name = "notis__profile_contact",
* uniqueConstraints = {
* @ORM\UniqueConstraint(
* name = "uidx__profile__recipient",
* columns = {
* "profile",
* "recipient",
* }
* )
* },
* )
*/
class ProfileContact extends TenantedEntity
implements
OneRosterableInterface,
DiscardableInterface,
LoggableInterface
{
use PreferencesTrait;
use OneRosterableTrait;
use DiscardableTrait;
/**
* NOTE:
* We can use the contact to obtain access to the profile, but due to changing needs of how contacts work, we may need to allow for when these are not the case.
* For example, when a shared contact is used between two different profiles...
*
* @var Profile|null
*
* @ORM\ManyToOne(
* targetEntity = "Products\NotificationsBundle\Entity\Profile",
* inversedBy = "contacts",
* )
* @ORM\JoinColumn(
* name = "profile",
* referencedColumnName = "id",
* nullable = true,
* onDelete = "CASCADE",
* )
*/
protected ?Profile $profile = null;
/**
* @var AbstractRecipient|null
*
* @ORM\ManyToOne(
* targetEntity = "Products\NotificationsBundle\Entity\AbstractRecipient",
* inversedBy = "contacts",
* )
* @ORM\JoinColumn(
* name = "recipient",
* referencedColumnName = "id",
* nullable = true,
* onDelete = "CASCADE",
* )
*/
protected ?AbstractRecipient $recipient = null;
/**
* @var bool
*
* @ORM\Column(
* type = "boolean",
* nullable = false,
* options = {
* "default" = false,
* },
* )
*/
protected bool $managed = false;
/**
* @return Profile|null
*/
public function getProfile(): ?Profile
{
return $this->profile;
}
/**
* @param Profile $profile
* @return $this
*/
public function setProfile(Profile $profile): self
{
$this->profile = $profile;
return $this;
}
/**
* @return AbstractRecipient|null
*/
public function getRecipient(): ?AbstractRecipient
{
return $this->recipient;
}
/**
* @param AbstractRecipient $recipient
* @return $this
*/
public function setRecipient(AbstractRecipient $recipient): self
{
$this->recipient = $recipient;
return $this;
}
/**
* @return string
*/
public function getKind(): string
{
return $this->getRecipient()->getKind();
}
/**
* @return string
*/
public function getKindSimple(): string
{
return $this->getRecipient()->getKindSimple();
}
/**
* @return bool
*/
public function isPhone(): bool
{
return ($this->getRecipient() instanceof PhoneRecipient);
}
/**
* @return bool
*/
public function isEmail(): bool
{
return ($this->getRecipient() instanceof EmailRecipient);
}
/**
* @return bool
*/
public function isApp(): bool
{
return ($this->getRecipient() instanceof AppRecipient);
}
/**
* @return bool
*/
public function isManaged(): bool
{
return $this->managed;
}
/**
* @param bool $managed
* @return $this
*/
public function setManaged(bool $managed): self
{
$this->managed = $managed;
return $this;
}
/**
* @return bool
*/
public function receivesPrimary(): bool
{
return $this->hasPrimaryPreference($this->getKindSimple());
}
/**
* @return bool
*/
public function receivesSecondary(): bool
{
return $this->hasSecondaryPreference($this->getKindSimple());
}
/**
* {@inheritDoc}
*/
public function getLoggableDetails(): array
{
return [
'id' => (string) $this->getId(),
'title' => $this->getProfile() ? $this->getProfile()->getCensoredName() : null,
];
}
}