src/Products/NotificationsBundle/Entity/ProfileContact.php line 37

Open in your IDE?
  1. <?php
  2. namespace Products\NotificationsBundle\Entity;
  3. use App\Entity\Shared\DiscardableInterface;
  4. use App\Entity\Shared\DiscardableTrait;
  5. use Cms\CoreBundle\Model\Interfaces\Loggable\LoggableInterface;
  6. use Cms\CoreBundle\Model\Interfaces\OneRosterable\OneRosterableInterface;
  7. use Cms\CoreBundle\Model\Interfaces\OneRosterable\OneRosterableTrait;
  8. use Cms\TenantBundle\Entity\TenantedEntity;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Products\NotificationsBundle\Entity\Recipients\AppRecipient;
  11. use Products\NotificationsBundle\Entity\Recipients\EmailRecipient;
  12. use Products\NotificationsBundle\Entity\Recipients\PhoneRecipient;
  13. use Products\NotificationsBundle\Util\PreferencesTrait;
  14. /**
  15.  * Class ProfileContact
  16.  * @package Products\NotificationsBundle\Entity
  17.  *
  18.  * @ORM\Entity(
  19.  *     repositoryClass = "Products\NotificationsBundle\Doctrine\Repository\ProfileContactRepository",
  20.  * )
  21.  * @ORM\Table(
  22.  *     name = "notis__profile_contact",
  23.  *     uniqueConstraints = {
  24.  *         @ORM\UniqueConstraint(
  25.  *             name = "uidx__profile__recipient",
  26.  *             columns = {
  27.  *                 "profile",
  28.  *                 "recipient",
  29.  *             }
  30.  *         )
  31.  *     },
  32.  * )
  33.  */
  34. class ProfileContact extends TenantedEntity
  35.     implements
  36.         OneRosterableInterface,
  37.         DiscardableInterface,
  38.         LoggableInterface
  39. {
  40.     use PreferencesTrait;
  41.     use OneRosterableTrait;
  42.     use DiscardableTrait;
  43.     /**
  44.      * NOTE:
  45.      * 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.
  46.      * For example, when a shared contact is used between two different profiles...
  47.      *
  48.      * @var Profile|null
  49.      *
  50.      * @ORM\ManyToOne(
  51.      *     targetEntity = "Products\NotificationsBundle\Entity\Profile",
  52.      *     inversedBy = "contacts",
  53.      * )
  54.      * @ORM\JoinColumn(
  55.      *     name = "profile",
  56.      *     referencedColumnName = "id",
  57.      *     nullable = true,
  58.      *     onDelete = "CASCADE",
  59.      * )
  60.      */
  61.     protected ?Profile $profile null;
  62.     /**
  63.      * @var AbstractRecipient|null
  64.      *
  65.      * @ORM\ManyToOne(
  66.      *     targetEntity = "Products\NotificationsBundle\Entity\AbstractRecipient",
  67.      *     inversedBy = "contacts",
  68.      * )
  69.      * @ORM\JoinColumn(
  70.      *     name = "recipient",
  71.      *     referencedColumnName = "id",
  72.      *     nullable = true,
  73.      *     onDelete = "CASCADE",
  74.      * )
  75.      */
  76.     protected ?AbstractRecipient $recipient null;
  77.     /**
  78.      * @var bool
  79.      *
  80.      * @ORM\Column(
  81.      *     type = "boolean",
  82.      *     nullable = false,
  83.      *     options = {
  84.      *         "default" = false,
  85.      *     },
  86.      * )
  87.      */
  88.     protected bool $managed false;
  89.     /**
  90.      * @return Profile|null
  91.      */
  92.     public function getProfile(): ?Profile
  93.     {
  94.         return $this->profile;
  95.     }
  96.     /**
  97.      * @param Profile $profile
  98.      * @return $this
  99.      */
  100.     public function setProfile(Profile $profile): self
  101.     {
  102.         $this->profile $profile;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return AbstractRecipient|null
  107.      */
  108.     public function getRecipient(): ?AbstractRecipient
  109.     {
  110.         return $this->recipient;
  111.     }
  112.     /**
  113.      * @param AbstractRecipient $recipient
  114.      * @return $this
  115.      */
  116.     public function setRecipient(AbstractRecipient $recipient): self
  117.     {
  118.         $this->recipient $recipient;
  119.         return $this;
  120.     }
  121.     /**
  122.      * @return string
  123.      */
  124.     public function getKind(): string
  125.     {
  126.         return $this->getRecipient()->getKind();
  127.     }
  128.     /**
  129.      * @return string
  130.      */
  131.     public function getKindSimple(): string
  132.     {
  133.         return $this->getRecipient()->getKindSimple();
  134.     }
  135.     /**
  136.      * @return bool
  137.      */
  138.     public function isPhone(): bool
  139.     {
  140.         return ($this->getRecipient() instanceof PhoneRecipient);
  141.     }
  142.     /**
  143.      * @return bool
  144.      */
  145.     public function isEmail(): bool
  146.     {
  147.         return ($this->getRecipient() instanceof EmailRecipient);
  148.     }
  149.     /**
  150.      * @return bool
  151.      */
  152.     public function isApp(): bool
  153.     {
  154.         return ($this->getRecipient() instanceof AppRecipient);
  155.     }
  156.     /**
  157.      * @return bool
  158.      */
  159.     public function isManaged(): bool
  160.     {
  161.         return $this->managed;
  162.     }
  163.     /**
  164.      * @param bool $managed
  165.      * @return $this
  166.      */
  167.     public function setManaged(bool $managed): self
  168.     {
  169.         $this->managed $managed;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return bool
  174.      */
  175.     public function receivesPrimary(): bool
  176.     {
  177.         return $this->hasPrimaryPreference($this->getKindSimple());
  178.     }
  179.     /**
  180.      * @return bool
  181.      */
  182.     public function receivesSecondary(): bool
  183.     {
  184.         return $this->hasSecondaryPreference($this->getKindSimple());
  185.     }
  186.     /**
  187.      * {@inheritDoc}
  188.      */
  189.     public function getLoggableDetails(): array
  190.     {
  191.         return [
  192.             'id' => (string) $this->getId(),
  193.             'title' => $this->getProfile() ? $this->getProfile()->getCensoredName() : null,
  194.         ];
  195.     }
  196. }