src/Entity/News.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\LinkTrait;
  4. use App\Entity\Traits\MetaTrait;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Entity\Traits\ActiveTrait;
  7. use App\Entity\Traits\DeleteTrait;
  8. use App\Repository\NewsRepository;
  9. use App\Entity\Traits\SubTitleTrait;
  10. use App\Entity\Traits\TranslateTrait;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use App\Entity\Traits\ImageUploadTrait;
  13. use App\Entity\Traits\TitleAndContentTrait;
  14. use App\Entity\Traits\ThirdImageUploadTrait;
  15. use App\Entity\Traits\SecondImageUploadTrait;
  16. use App\Entity\Traits\SitemapableTrait;
  17. use App\Entity\Interfaces\DefaultLinkedEntity;
  18. use Gedmo\Timestampable\Traits\TimestampableEntity;
  19. /**
  20.  * News.
  21.  *
  22.  * @Gedmo\Loggable
  23.  *
  24.  * @Gedmo\TranslationEntity(class="App\Entity\NewsTranslations")
  25.  */
  26. #[ORM\Entity(repositoryClassNewsRepository::class)]
  27. #[ORM\Table(name'news')]
  28. class News implements DefaultLinkedEntity
  29. {
  30.     use TitleAndContentTrait;
  31.     use SubTitleTrait;
  32.     use LinkTrait;
  33.     use MetaTrait;
  34.     use ActiveTrait;
  35.     use DeleteTrait;
  36.     use ImageUploadTrait;
  37.     use SecondImageUploadTrait;
  38.     use ThirdImageUploadTrait;
  39.     use TimestampableEntity;
  40.     use TranslateTrait;
  41.     use SitemapableTrait;
  42.     public $imageUpload;
  43.     #[ORM\Column(name'id'type'integer')]
  44.     #[ORM\Id]
  45.     #[ORM\GeneratedValue(strategy'AUTO')]
  46.     private int $id;
  47.     /**
  48.      * @Gedmo\Versioned
  49.      *
  50.      * @Gedmo\Translatable
  51.      */
  52.     #[ORM\Column(name'excerpt'type'text'nullabletrue)]
  53.     private ?string $excerpt null;
  54.     /**
  55.      * @Gedmo\Versioned
  56.      */
  57.     #[ORM\Column(name'publish_date'type'datetime')]
  58.     private ?\DateTimeInterface $publishDate null;
  59.     /**
  60.      * @Gedmo\Versioned
  61.      */
  62.     #[ORM\Column(name'thumbnail'type'string'length255nullabletrue)]
  63.     private ?string $thumbnail null;
  64.     #[ORM\Column(type'text'nullabletrue)]
  65.     private ?string $content2 null;
  66.     #[ORM\Column(type'text'nullabletrue)]
  67.     private ?string $kicker null;
  68.     #[ORM\Column(type'boolean'nullablefalse)]
  69.     private bool $featured false;
  70.     #[ORM\ManyToOne(targetEntityUser::class, inversedBy'news')]
  71.     #[ORM\JoinColumn(nullablefalse)]
  72.     private ?User $updatedBy null;
  73.     /**
  74.      * Get id.
  75.      *
  76.      * @return int
  77.      */
  78.     public function getId()
  79.     {
  80.         return $this->id;
  81.     }
  82.     /**
  83.      * Set excerpt.
  84.      *
  85.      * @param string $excerpt
  86.      *
  87.      * @return News
  88.      */
  89.     public function setExcerpt($excerpt)
  90.     {
  91.         $this->excerpt $excerpt;
  92.         return $this;
  93.     }
  94.     /**
  95.      * Get excerpt.
  96.      *
  97.      * @return string
  98.      */
  99.     public function getExcerpt()
  100.     {
  101.         return $this->excerpt;
  102.     }
  103.     /**
  104.      * Set publishDate.
  105.      *
  106.      * @param \DateTime|\DateTimeImmutable $publishDate
  107.      *
  108.      * @return News
  109.      */
  110.     public function setPublishDate(\DateTimeInterface $publishDate)
  111.     {
  112.         $this->publishDate $publishDate;
  113.         return $this;
  114.     }
  115.     /**
  116.      * Get publishDate.
  117.      *
  118.      * @return \DateTime
  119.      */
  120.     public function getPublishDate()
  121.     {
  122.         return $this->publishDate;
  123.     }
  124.     /**
  125.      * Set thumbnail.
  126.      *
  127.      * @param string $thumbnail
  128.      *
  129.      * @return News
  130.      */
  131.     public function setThumbnail($thumbnail)
  132.     {
  133.         $this->thumbnail $thumbnail;
  134.         return $this;
  135.     }
  136.     /**
  137.      * Get thumbnail.
  138.      *
  139.      * @return string
  140.      */
  141.     public function getThumbnail()
  142.     {
  143.         return $this->thumbnail;
  144.     }
  145.     // REQUIRED BY THE META LINKS TRAIT
  146.     public function getLinkedPageId(): int
  147.     {
  148.         return 3;
  149.     }
  150.     public function getUpdatedBy(): ?User
  151.     {
  152.         return $this->updatedBy;
  153.     }
  154.     public function setUpdatedBy(?User $updatedBy): self
  155.     {
  156.         $this->updatedBy $updatedBy;
  157.         return $this;
  158.     }
  159.     public function getContent2(): ?string
  160.     {
  161.         return $this->content2;
  162.     }
  163.     public function setContent2(?string $content2): self
  164.     {
  165.         $this->content2 $content2;
  166.         return $this;
  167.     }
  168.     public function getKicker(): ?string
  169.     {
  170.         return $this->kicker;
  171.     }
  172.     public function setKicker(?string $kicker): self
  173.     {
  174.         $this->kicker $kicker;
  175.         return $this;
  176.     }
  177.     public function isFeatured(): bool
  178.     {
  179.         return $this->featured;
  180.     }
  181.     public function setFeatured(bool $featured): void
  182.     {
  183.         $this->featured $featured;
  184.     }
  185.     public function getSitemapRouteParams(): array
  186.     {
  187.         return ['slug' => $this->getSlug()];
  188.     }
  189.     public function isIncludedInSitemap(): bool
  190.     {
  191.         $now = new \DateTime();
  192.         // if ($this->id === 2) {
  193.         //     dd($this->isActive(),
  194.         //         ! $this->isDeleted(),
  195.         //         $this->getPublishDate() < $now);
  196.         // }
  197.         return $this->isActive() &&
  198.             ! $this->isDeleted() &&
  199.             $this->getPublishDate() < $now
  200.         ;
  201.     }
  202. }