src/Entity/BlogEntry.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use JMS\Serializer\Annotation\Groups;
  5. /**
  6.  * @ORM\Table("BlogEntry",
  7.  *   indexes={
  8.  *
  9.  *     @ORM\Index(name="member_created_at_idx", columns={"member_id", "created_at", "publish_at"})
  10.  * })
  11.  *
  12.  * @ORM\Entity(repositoryClass="App\Repository\BlogEntryRepository")
  13.  */
  14. class BlogEntry
  15. {
  16.     /**
  17.      * @Groups({"commonids", "blogentries", "timelineindex"})
  18.      *
  19.      * @ORM\Id()
  20.      *
  21.      * @ORM\GeneratedValue()
  22.      *
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     protected $id;
  26.     /**
  27.      * @Groups({"blogentries", "timelineindex"})
  28.      *
  29.      * @ORM\Column(type="string", length=100)
  30.      */
  31.     protected string $title '';
  32.     /**
  33.      * @Groups({"blogentries", "timelineindex"})
  34.      *
  35.      * @ORM\Column(type="text")
  36.      */
  37.     protected string $text '';
  38.     /**
  39.      * @Groups({"commonids", "blogentries", "timelineindex"})
  40.      *
  41.      * @ORM\ManyToOne(targetEntity="App\Entity\Member")
  42.      *
  43.      * @ORM\JoinColumn(name="member_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
  44.      */
  45.     protected Member $member;
  46.     /**
  47.      * @Groups({"commonids", "blogentries", "timelineindex"})
  48.      *
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\MemberMedia",cascade={"persist"})
  50.      *
  51.      * @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="SET NULL")
  52.      */
  53.     protected ?MemberMedia $image null;
  54.     /**
  55.      * @Groups({"blogentries", "timelineindex"})
  56.      *
  57.      * @ORM\Column(type="boolean");
  58.      */
  59.     protected bool $is_checked false;
  60.     /**
  61.      * @Groups({"blogentries"})
  62.      *
  63.      * @ORM\Column(type="smallint");
  64.      */
  65.     protected int $check_count 0;
  66.     /**
  67.      * @Groups({"blogentries"})
  68.      *
  69.      * @ORM\Column(type="boolean", options={"default"=0});
  70.      */
  71.     protected bool $is_deleted false;
  72.     /**
  73.      * @Groups({"blogentries", "timelineindex"})
  74.      *
  75.      * @ORM\Column(name="publish_at", type="datetime", nullable=true)
  76.      */
  77.     protected \DateTime $publish_at;
  78.     /**
  79.      * @Groups({"blogentries"})
  80.      *
  81.      * @ORM\Column(name="created_at", type="datetime")
  82.      */
  83.     protected \DateTime $created_at;
  84.     /**
  85.      * @Groups({"blogentries"})
  86.      *
  87.      * @ORM\Column(name="activity_feed_id", type="integer")
  88.      */
  89.     protected ?int $activity_feed_id;
  90.     private bool $changed false;
  91.     public function __construct()
  92.     {
  93.         $this->publish_at $this->created_at = new \DateTime();
  94.     }
  95.     public function getId()
  96.     {
  97.         return $this->id;
  98.     }
  99.     public function getTitle(): string
  100.     {
  101.         return $this->title;
  102.     }
  103.     public function setTitle(string $title): BlogEntry
  104.     {
  105.         $newValue mb_substr($title0100);
  106.         if ($newValue !== $this->title) {
  107.             $this->changed true;
  108.             $this->title $newValue;
  109.         }
  110.         return $this;
  111.     }
  112.     public function getText(): string
  113.     {
  114.         return $this->text;
  115.     }
  116.     public function setText(string $text): BlogEntry
  117.     {
  118.         if ($text !== $this->text) {
  119.             $this->changed true;
  120.             $this->text $text;
  121.         }
  122.         return $this;
  123.     }
  124.     public function getMember(): Member
  125.     {
  126.         return $this->member;
  127.     }
  128.     public function setMember(Member $member): BlogEntry
  129.     {
  130.         $this->member $member;
  131.         return $this;
  132.     }
  133.     public function getImage(): ?MemberMedia
  134.     {
  135.         return $this->image;
  136.     }
  137.     public function setImage($image): BlogEntry
  138.     {
  139.         if (($image instanceof MemberMedia && null === $this->image) || (null === $image && $this->image instanceof MemberMedia)) {
  140.             $this->changed true;
  141.         } elseif ($image instanceof MemberMedia && $this->image instanceof MemberMedia && $image->getId() !== $this->image->getId()) {
  142.             $this->changed true;
  143.         }
  144.         $this->image $image;
  145.         return $this;
  146.     }
  147.     public function getCreatedAt(): \DateTime
  148.     {
  149.         return $this->created_at;
  150.     }
  151.     public function setCreatedAt(\DateTime $created_at): BlogEntry
  152.     {
  153.         $this->created_at $created_at;
  154.         return $this;
  155.     }
  156.     public function getPublishAt(): \DateTime
  157.     {
  158.         return $this->publish_at;
  159.     }
  160.     public function isPublic(): bool
  161.     {
  162.         return $this->isChecked() && false === $this->isIsDeleted() && $this->getPublishAt()->format('U') < time();
  163.     }
  164.     public function setPublishAt(\DateTime $publish_at): BlogEntry
  165.     {
  166.         if (null === $this->publish_at || ($this->publish_at instanceof \DateTime && $this->publish_at->format('dmYHis') !== $publish_at->format('dmYHis'))) {
  167.             $this->changed true;
  168.         }
  169.         $this->publish_at $publish_at;
  170.         return $this;
  171.     }
  172.     public function setIsChecked(bool $checked): BlogEntry
  173.     {
  174.         if (false === $this->is_checked && $checked) {
  175.             ++$this->check_count;
  176.         }
  177.         $this->is_checked $checked;
  178.         if (null !== $this->image && true === $checked) {
  179.             $this->image->setIsChecked(true);
  180.         }
  181.         return $this;
  182.     }
  183.     public function isChecked(): bool
  184.     {
  185.         return $this->is_checked;
  186.     }
  187.     public function getCheckCount(): int
  188.     {
  189.         return $this->check_count;
  190.     }
  191.     public function hasPastChecks(): bool
  192.     {
  193.         return $this->check_count 0;
  194.     }
  195.     public function isIsDeleted(): bool
  196.     {
  197.         return $this->is_deleted;
  198.     }
  199.     public function setIsDeleted(bool $is_deleted): BlogEntry
  200.     {
  201.         $this->is_deleted $is_deleted;
  202.         return $this;
  203.     }
  204.     public function hasChanged(): bool
  205.     {
  206.         return $this->changed;
  207.     }
  208.     public function getActivityFeedId(): ?int
  209.     {
  210.         return $this->activity_feed_id;
  211.     }
  212.     public function setActivityFeedId(?int $activity_feed_id): BlogEntry
  213.     {
  214.         $this->activity_feed_id $activity_feed_id;
  215.         return $this;
  216.     }
  217. }