<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Frivol\Common\Dict\ActivityFeedType;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Table("ActivityFeed",
* indexes={
*
* @ORM\Index(name="activity_feed_type_createdat", columns={"type", "createdAt"})
* })
*
* @ORM\Entity(repositoryClass="App\Repository\ActivityFeedRepository")
*/
class ActivityFeed
{
/**
* @Groups({"activityfeedindex", "timelineindex"})
*
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Groups({"activityfeedindex"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\Member")
*
* @ORM\JoinColumn(name="member_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private ?Member $member = null;
/**
* If visibleTo is NULL, it is visible to everybody.
*
* @ORM\ManyToOne(targetEntity="App\Entity\Member")
*
* @ORM\JoinColumn(name="visible_to", referencedColumnName="id", onDelete="SET NULL", nullable=true)
*/
private ?Member $visibleTo = null;
/**
* @Groups({"contentlist"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\Content")
*
* @ORM\JoinColumn(name="content_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
private ?Content $content = null;
/**
* @Groups({"contentlist", "timelineindex"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\BlogEntry")
*
* @ORM\JoinColumn(name="blogentry_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
private ?BlogEntry $blogEntry = null;
/**
* @Groups({"contentlist", "timelineindex"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\GuestbookEntry")
*
* @ORM\JoinColumn(name="guestbookentry_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
private ?GuestbookEntry $guestbookEntry = null;
/**
* @Groups({"contentlist", "timelineindex"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\ContentComment")
*
* @ORM\JoinColumn(name="contentcomment_id", referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
private ?ContentComment $contentComment = null;
/**
* @Groups({"activityfeedindex", "timelineindex"})
*
* @ORM\Column(type="smallint")
*/
private int $type = ActivityFeedType::NONE;
/**
* @Groups({"activityfeedindex", "timelineindex"})
*
* @ORM\Column(type="json", nullable=true)
*/
private $specs;
/**
* @Groups({"activityfeedindex", "timelineindex"})
*
* @ORM\Column(name="createdAt", type="datetime")
*/
private \DateTime $createdAt;
/**
* This will be set by the serializer, as items of type blog_post may have an image attachted to it via specs.
*
* @Groups({"timelineindex"})
*/
protected ?MemberMedia $memberMedia = null;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getMember(): ?Member
{
return $this->member;
}
public function setMember(?Member $member): self
{
$this->member = $member;
return $this;
}
public function getVisibleTo(): ?Member
{
return $this->visibleTo;
}
public function setVisibleTo(?Member $visibleTo): self
{
$this->visibleTo = $visibleTo;
return $this;
}
public function getContent(): ?Content
{
return $this->content;
}
public function setContent(?Content $content): self
{
$this->content = $content;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function getSpecs()
{
return $this->specs;
}
public function setSpecs($specs): self
{
$this->specs = $specs;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getTitle(): ?string
{
return $this->getSpec('title');
}
public function getText(): ?string
{
return $this->getSpec('text');
}
public function getMemberMediaId(): ?string
{
return $this->getSpec('memberMediaId');
}
protected function getSpec(string $key)
{
return (isset($this->getSpecs()[$key])) ? $this->getSpecs()[$key] : null;
}
public function __set(string $property, $value)
{
$specs = $this->getSpecs();
if (empty($specs)) {
$specs = [];
}
$this->setSpecs(array_merge($specs, [
$property => $this->filterMagicSetter($property, $value),
]));
}
protected function filterMagicSetter(string $key, $value): string
{
if ('text' === $key) {
$value = strip_tags($value);
}
return trim($value);
}
public function setMemberMedia(MemberMedia $media): self
{
$this->memberMedia = $media;
return $this;
}
public function getBlogEntry(): ?BlogEntry
{
return $this->blogEntry;
}
public function setBlogEntry(?BlogEntry $blogEntry): self
{
$this->blogEntry = $blogEntry;
return $this;
}
public function getGuestbookEntry(): ?GuestbookEntry
{
return $this->guestbookEntry;
}
public function setGuestbookEntry(?GuestbookEntry $guestbookEntry): self
{
$this->guestbookEntry = $guestbookEntry;
return $this;
}
public function getContentComment(): ?ContentComment
{
return $this->contentComment;
}
public function setContentComment(?ContentComment $contentComment): self
{
$this->contentComment = $contentComment;
return $this;
}
public function isGuestbookComment(): bool
{
return ActivityFeedType::GUESTBOOK_ENTRY_COMMENT === $this->type;
}
public function isGuestbookEntry(): bool
{
return ActivityFeedType::GUESTBOOK_ENTRY_PUBLISHED === $this->type || ActivityFeedType::GUESTBOOK_ENTRY_RECEIVED;
}
public function isBlogPost(): bool
{
return ActivityFeedType::BLOG_POST === $this->type;
}
public function getMemberMedia(): ?MemberMedia
{
return $this->memberMedia;
}
}