src/Entity/Content/News.php line 30

  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Михаил
  5.  * Date: 21.12.2018
  6.  * Time: 11:20
  7.  */
  8. namespace App\Entity\Content;
  9. use App\Entity\Common\DateInterval;
  10. use App\Entity\Common\File;
  11. use App\Entity\Common\Owner;
  12. use App\Entity\Traits\TrackerFields;
  13. use App\Entity\Traits\UserCreatedInterface;
  14. use App\Entity\Traits\UserUpdatedInterface;
  15. use App\Entity\User\User;
  16. use App\Entity\UUID\HaveUuidInterface;
  17. use App\Entity\UUID\UuidTrait;
  18. use App\Model\Common\HaveOwnerInterface;
  19. use App\Model\Translation\TranslatableTrait;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  22. #[ORM\Table(name'news')]
  23. #[ORM\Index(name'idx_active'columns: ['published''pinned''publish_at'])]
  24. #[ORM\Index(name'idx_deleted'columns: ['deleted'])]
  25. #[ORM\Entity(repositoryClass\App\Repository\Content\NewsRepository::class)]
  26. #[ORM\HasLifecycleCallbacks]
  27. class News implements UserCreatedInterfaceUserUpdatedInterfaceHaveOwnerInterfaceHaveUuidInterfaceTranslatableInterface
  28. {
  29.     use TrackerFields;
  30.     use UuidTrait;
  31.     use TranslatableTrait;
  32.     public const SITE_PER_PAGE 10;
  33.     public const ADMIN_PER_PAGE 20;
  34.     #[ORM\Id]
  35.     #[ORM\GeneratedValue(strategy'AUTO')]
  36.     #[ORM\Column(type'integer')]
  37.     private $id;
  38.     #[ORM\Column(type'string'nullabletrue)]
  39.     private $caption;
  40.     #[ORM\Column(type'string'length250nullabletrue)]
  41.     private $subtitle;
  42.     #[ORM\Column(type'text'nullabletrue)]
  43.     private $preview;
  44.     /**
  45.      * @var File|null
  46.      */
  47.     #[ORM\ManyToOne(targetEntity'App\Entity\Common\File'cascade: ['remove''persist'])]
  48.     private $image;
  49.     #[ORM\Column(type'text'nullabletrue)]
  50.     private $text;
  51.     /**
  52.      * @var \App\Entity\Content\NewsType
  53.      */
  54.     #[ORM\ManyToOne(targetEntity'App\Entity\Content\NewsType'inversedBy'news')]
  55.     #[ORM\JoinColumn(nullablefalse)]
  56.     private $type;
  57.     /**
  58.      * @var Owner
  59.      */
  60.     #[ORM\Embedded(class: 'App\Entity\Common\Owner')]
  61.     private $owner;
  62.     /**
  63.      * @var DateInterval
  64.      */
  65.     #[ORM\Embedded(class: 'App\Entity\Common\DateInterval')]
  66.     private $interval;
  67.     /**
  68.      * @var bool
  69.      */
  70.     #[ORM\Column(type'boolean')]
  71.     private $published true;
  72.     #[ORM\Column(type'datetime'nullabletrue)]
  73.     private $publish_at;
  74.     /**
  75.      * @var bool
  76.      */
  77.     #[ORM\Column(type'boolean')]
  78.     private $pinned false;
  79.     public function __construct()
  80.     {
  81.         $this->owner = new Owner();
  82.         $this->publish_at = new \DateTime();
  83.         $this->interval = new \App\Entity\Common\DateInterval();
  84.     }
  85.     /**
  86.      * @return mixed
  87.      */
  88.     public function getId()
  89.     {
  90.         return $this->id;
  91.     }
  92.     /**
  93.      * @param mixed $id
  94.      */
  95.     public function setId($id): void
  96.     {
  97.         $this->id $id;
  98.     }
  99.     /**
  100.      * @return bool
  101.      */
  102.     public function isPublished(): bool
  103.     {
  104.         return $this->published;
  105.     }
  106.     /**
  107.      * @param bool $published
  108.      */
  109.     public function setPublished(bool $published): void
  110.     {
  111.         $this->published $published;
  112.     }
  113.     /**
  114.      * @return mixed
  115.      */
  116.     public function getPublishAt()
  117.     {
  118.         return $this->publish_at;
  119.     }
  120.     /**
  121.      * @param mixed $publish_at
  122.      */
  123.     public function setPublishAt($publish_at): void
  124.     {
  125.         $this->publish_at $publish_at;
  126.     }
  127.     /**
  128.      * @return bool
  129.      */
  130.     public function isPinned(): bool
  131.     {
  132.         return $this->pinned;
  133.     }
  134.     /**
  135.      * @param bool $pinned
  136.      */
  137.     public function setPinned(bool $pinned): void
  138.     {
  139.         $this->pinned $pinned;
  140.     }
  141.     /**
  142.      * @return User
  143.      */
  144.     public function getCreatedBy(): ?User
  145.     {
  146.         return $this->created_by;
  147.     }
  148.     public function setCreatedBy(?User $user)
  149.     {
  150.         $this->created_by $user;
  151.     }
  152.     /**
  153.      * @return User
  154.      */
  155.     public function getUpdatedBy(): ?User
  156.     {
  157.         return $this->updated_by;
  158.     }
  159.     public function setUpdatedBy(?User $user)
  160.     {
  161.         $this->updated_by $user;
  162.     }
  163.     public function getTypeString(): string
  164.     {
  165.         return $this->getType()->getType();
  166.     }
  167.     /**
  168.      * @return \App\Entity\Content\NewsType
  169.      */
  170.     public function getType(): ?\App\Entity\Content\NewsType
  171.     {
  172.         return $this->type;
  173.     }
  174.     /**
  175.      * @param mixed $type
  176.      */
  177.     public function setType($type): void
  178.     {
  179.         $this->type $type;
  180.     }
  181.     /**
  182.      * @return Owner
  183.      */
  184.     public function getOwner(): Owner
  185.     {
  186.         return $this->owner;
  187.     }
  188.     /**
  189.      * @param Owner $owner
  190.      */
  191.     public function setOwner(Owner $owner): void
  192.     {
  193.         $this->owner $owner;
  194.     }
  195.     /**
  196.      * @return DateInterval
  197.      */
  198.     public function getInterval(): ?DateInterval
  199.     {
  200.         return $this->interval;
  201.     }
  202.     /**
  203.      * @param DateInterval $interval
  204.      */
  205.     public function setInterval(DateInterval $interval): void
  206.     {
  207.         $this->interval $interval;
  208.     }
  209.     /**
  210.      * @return File|null
  211.      */
  212.     public function getImage(): ?File
  213.     {
  214.         return $this->image;
  215.     }
  216.     /**
  217.      * @param File|null $image
  218.      */
  219.     public function setImage(?File $image): void
  220.     {
  221.         $this->image $image;
  222.     }
  223.     /**
  224.      * @return bool
  225.      * @noinspection PhpUnused
  226.      */
  227.     public function isIndexable(): bool
  228.     {
  229.         return false === $this->deleted;
  230.     }
  231.     public function isActive(): bool
  232.     {
  233.         return $this->isPublished();
  234.     }
  235. }