src/Entity/ActivityFeed.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Frivol\Common\Dict\ActivityFeedType;
  5. use JMS\Serializer\Annotation\Groups;
  6. /**
  7.  * @ORM\Table("ActivityFeed",
  8.  *   indexes={
  9.  *
  10.  *     @ORM\Index(name="activity_feed_type_createdat", columns={"type", "createdAt"})
  11.  * })
  12.  *
  13.  * @ORM\Entity(repositoryClass="App\Repository\ActivityFeedRepository")
  14.  */
  15. class ActivityFeed
  16. {
  17.     /**
  18.      * @Groups({"activityfeedindex", "timelineindex"})
  19.      *
  20.      * @ORM\Id()
  21.      *
  22.      * @ORM\GeneratedValue()
  23.      *
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @Groups({"activityfeedindex"})
  29.      *
  30.      * @ORM\ManyToOne(targetEntity="App\Entity\Member")
  31.      *
  32.      * @ORM\JoinColumn(name="member_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
  33.      */
  34.     private ?Member $member null;
  35.     /**
  36.      * If visibleTo is NULL, it is visible to everybody.
  37.      *
  38.      * @ORM\ManyToOne(targetEntity="App\Entity\Member")
  39.      *
  40.      * @ORM\JoinColumn(name="visible_to", referencedColumnName="id", onDelete="SET NULL", nullable=true)
  41.      */
  42.     private ?Member $visibleTo null;
  43.     /**
  44.      * @Groups({"contentlist"})
  45.      *
  46.      * @ORM\ManyToOne(targetEntity="App\Entity\Content")
  47.      *
  48.      * @ORM\JoinColumn(name="content_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  49.      */
  50.     private ?Content $content null;
  51.     /**
  52.      * @Groups({"contentlist", "timelineindex"})
  53.      *
  54.      * @ORM\ManyToOne(targetEntity="App\Entity\BlogEntry")
  55.      *
  56.      * @ORM\JoinColumn(name="blogentry_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  57.      */
  58.     private ?BlogEntry $blogEntry null;
  59.     /**
  60.      * @Groups({"contentlist", "timelineindex"})
  61.      *
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\GuestbookEntry")
  63.      *
  64.      * @ORM\JoinColumn(name="guestbookentry_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  65.      */
  66.     private ?GuestbookEntry $guestbookEntry null;
  67.     /**
  68.      * @Groups({"contentlist", "timelineindex"})
  69.      *
  70.      * @ORM\ManyToOne(targetEntity="App\Entity\ContentComment")
  71.      *
  72.      * @ORM\JoinColumn(name="contentcomment_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
  73.      */
  74.     private ?ContentComment $contentComment null;
  75.     /**
  76.      * @Groups({"activityfeedindex", "timelineindex"})
  77.      *
  78.      * @ORM\Column(type="smallint")
  79.      */
  80.     private int $type ActivityFeedType::NONE;
  81.     /**
  82.      * @Groups({"activityfeedindex", "timelineindex"})
  83.      *
  84.      * @ORM\Column(type="json", nullable=true)
  85.      */
  86.     private $specs;
  87.     /**
  88.      * @Groups({"activityfeedindex", "timelineindex"})
  89.      *
  90.      * @ORM\Column(name="createdAt", type="datetime")
  91.      */
  92.     private \DateTime $createdAt;
  93.     /**
  94.      * This will be set by the serializer, as items of type blog_post may have an image attachted to it via specs.
  95.      *
  96.      * @Groups({"timelineindex"})
  97.      */
  98.     protected ?MemberMedia $memberMedia null;
  99.     public function __construct()
  100.     {
  101.         $this->createdAt = new \DateTime();
  102.     }
  103.     public function getId(): ?int
  104.     {
  105.         return $this->id;
  106.     }
  107.     public function getMember(): ?Member
  108.     {
  109.         return $this->member;
  110.     }
  111.     public function setMember(?Member $member): self
  112.     {
  113.         $this->member $member;
  114.         return $this;
  115.     }
  116.     public function getVisibleTo(): ?Member
  117.     {
  118.         return $this->visibleTo;
  119.     }
  120.     public function setVisibleTo(?Member $visibleTo): self
  121.     {
  122.         $this->visibleTo $visibleTo;
  123.         return $this;
  124.     }
  125.     public function getContent(): ?Content
  126.     {
  127.         return $this->content;
  128.     }
  129.     public function setContent(?Content $content): self
  130.     {
  131.         $this->content $content;
  132.         return $this;
  133.     }
  134.     public function getType(): ?int
  135.     {
  136.         return $this->type;
  137.     }
  138.     public function setType(int $type): self
  139.     {
  140.         $this->type $type;
  141.         return $this;
  142.     }
  143.     public function getSpecs()
  144.     {
  145.         return $this->specs;
  146.     }
  147.     public function setSpecs($specs): self
  148.     {
  149.         $this->specs $specs;
  150.         return $this;
  151.     }
  152.     public function getCreatedAt(): ?\DateTime
  153.     {
  154.         return $this->createdAt;
  155.     }
  156.     public function setCreatedAt(\DateTime $createdAt): self
  157.     {
  158.         $this->createdAt $createdAt;
  159.         return $this;
  160.     }
  161.     public function getTitle(): ?string
  162.     {
  163.         return $this->getSpec('title');
  164.     }
  165.     public function getText(): ?string
  166.     {
  167.         return $this->getSpec('text');
  168.     }
  169.     public function getMemberMediaId(): ?string
  170.     {
  171.         return $this->getSpec('memberMediaId');
  172.     }
  173.     protected function getSpec(string $key)
  174.     {
  175.         return (isset($this->getSpecs()[$key])) ? $this->getSpecs()[$key] : null;
  176.     }
  177.     public function __set(string $property$value)
  178.     {
  179.         $specs $this->getSpecs();
  180.         if (empty($specs)) {
  181.             $specs = [];
  182.         }
  183.         $this->setSpecs(array_merge($specs, [
  184.             $property => $this->filterMagicSetter($property$value),
  185.         ]));
  186.     }
  187.     protected function filterMagicSetter(string $key$value): string
  188.     {
  189.         if ('text' === $key) {
  190.             $value strip_tags($value);
  191.         }
  192.         return trim($value);
  193.     }
  194.     public function setMemberMedia(MemberMedia $media): self
  195.     {
  196.         $this->memberMedia $media;
  197.         return $this;
  198.     }
  199.     public function getBlogEntry(): ?BlogEntry
  200.     {
  201.         return $this->blogEntry;
  202.     }
  203.     public function setBlogEntry(?BlogEntry $blogEntry): self
  204.     {
  205.         $this->blogEntry $blogEntry;
  206.         return $this;
  207.     }
  208.     public function getGuestbookEntry(): ?GuestbookEntry
  209.     {
  210.         return $this->guestbookEntry;
  211.     }
  212.     public function setGuestbookEntry(?GuestbookEntry $guestbookEntry): self
  213.     {
  214.         $this->guestbookEntry $guestbookEntry;
  215.         return $this;
  216.     }
  217.     public function getContentComment(): ?ContentComment
  218.     {
  219.         return $this->contentComment;
  220.     }
  221.     public function setContentComment(?ContentComment $contentComment): self
  222.     {
  223.         $this->contentComment $contentComment;
  224.         return $this;
  225.     }
  226.     public function isGuestbookComment(): bool
  227.     {
  228.         return ActivityFeedType::GUESTBOOK_ENTRY_COMMENT === $this->type;
  229.     }
  230.     public function isGuestbookEntry(): bool
  231.     {
  232.         return ActivityFeedType::GUESTBOOK_ENTRY_PUBLISHED === $this->type || ActivityFeedType::GUESTBOOK_ENTRY_RECEIVED;
  233.     }
  234.     public function isBlogPost(): bool
  235.     {
  236.         return ActivityFeedType::BLOG_POST === $this->type;
  237.     }
  238.     public function getMemberMedia(): ?MemberMedia
  239.     {
  240.         return $this->memberMedia;
  241.     }
  242. }