<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Groups;
/**
* @ORM\Table("BlogEntry",
* indexes={
*
* @ORM\Index(name="member_created_at_idx", columns={"member_id", "created_at", "publish_at"})
* })
*
* @ORM\Entity(repositoryClass="App\Repository\BlogEntryRepository")
*/
class BlogEntry
{
/**
* @Groups({"commonids", "blogentries", "timelineindex"})
*
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @Groups({"blogentries", "timelineindex"})
*
* @ORM\Column(type="string", length=100)
*/
protected string $title = '';
/**
* @Groups({"blogentries", "timelineindex"})
*
* @ORM\Column(type="text")
*/
protected string $text = '';
/**
* @Groups({"commonids", "blogentries", "timelineindex"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\Member")
*
* @ORM\JoinColumn(name="member_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
protected Member $member;
/**
* @Groups({"commonids", "blogentries", "timelineindex"})
*
* @ORM\ManyToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"})
*
* @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="SET NULL")
*/
protected ?MemberMedia $image = null;
/**
* @Groups({"blogentries", "timelineindex"})
*
* @ORM\Column(type="boolean");
*/
protected bool $is_checked = false;
/**
* @Groups({"blogentries"})
*
* @ORM\Column(type="smallint");
*/
protected int $check_count = 0;
/**
* @Groups({"blogentries"})
*
* @ORM\Column(type="boolean", options={"default"=0});
*/
protected bool $is_deleted = false;
/**
* @Groups({"blogentries", "timelineindex"})
*
* @ORM\Column(name="publish_at", type="datetime", nullable=true)
*/
protected \DateTime $publish_at;
/**
* @Groups({"blogentries"})
*
* @ORM\Column(name="created_at", type="datetime")
*/
protected \DateTime $created_at;
/**
* @Groups({"blogentries"})
*
* @ORM\Column(name="activity_feed_id", type="integer")
*/
protected ?int $activity_feed_id;
private bool $changed = false;
public function __construct()
{
$this->publish_at = $this->created_at = new \DateTime();
}
public function getId()
{
return $this->id;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): BlogEntry
{
$newValue = mb_substr($title, 0, 100);
if ($newValue !== $this->title) {
$this->changed = true;
$this->title = $newValue;
}
return $this;
}
public function getText(): string
{
return $this->text;
}
public function setText(string $text): BlogEntry
{
if ($text !== $this->text) {
$this->changed = true;
$this->text = $text;
}
return $this;
}
public function getMember(): Member
{
return $this->member;
}
public function setMember(Member $member): BlogEntry
{
$this->member = $member;
return $this;
}
public function getImage(): ?MemberMedia
{
return $this->image;
}
public function setImage($image): BlogEntry
{
if (($image instanceof MemberMedia && null === $this->image) || (null === $image && $this->image instanceof MemberMedia)) {
$this->changed = true;
} elseif ($image instanceof MemberMedia && $this->image instanceof MemberMedia && $image->getId() !== $this->image->getId()) {
$this->changed = true;
}
$this->image = $image;
return $this;
}
public function getCreatedAt(): \DateTime
{
return $this->created_at;
}
public function setCreatedAt(\DateTime $created_at): BlogEntry
{
$this->created_at = $created_at;
return $this;
}
public function getPublishAt(): \DateTime
{
return $this->publish_at;
}
public function isPublic(): bool
{
return $this->isChecked() && false === $this->isIsDeleted() && $this->getPublishAt()->format('U') < time();
}
public function setPublishAt(\DateTime $publish_at): BlogEntry
{
if (null === $this->publish_at || ($this->publish_at instanceof \DateTime && $this->publish_at->format('dmYHis') !== $publish_at->format('dmYHis'))) {
$this->changed = true;
}
$this->publish_at = $publish_at;
return $this;
}
public function setIsChecked(bool $checked): BlogEntry
{
if (false === $this->is_checked && $checked) {
++$this->check_count;
}
$this->is_checked = $checked;
if (null !== $this->image && true === $checked) {
$this->image->setIsChecked(true);
}
return $this;
}
public function isChecked(): bool
{
return $this->is_checked;
}
public function getCheckCount(): int
{
return $this->check_count;
}
public function hasPastChecks(): bool
{
return $this->check_count > 0;
}
public function isIsDeleted(): bool
{
return $this->is_deleted;
}
public function setIsDeleted(bool $is_deleted): BlogEntry
{
$this->is_deleted = $is_deleted;
return $this;
}
public function hasChanged(): bool
{
return $this->changed;
}
public function getActivityFeedId(): ?int
{
return $this->activity_feed_id;
}
public function setActivityFeedId(?int $activity_feed_id): BlogEntry
{
$this->activity_feed_id = $activity_feed_id;
return $this;
}
}