src/Entity/SEO/PageMetadata.php line 18

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-28
  5.  * Time: 16:24
  6.  */
  7. namespace App\Entity\SEO;
  8. use AngelGamez\TranslatableBundle\Entity\TranslatableValue;
  9. use App\Entity\Location\City;
  10. use App\Repository\PageMetadataRepository;
  11. use Carbon\CarbonImmutable;
  12. use Doctrine\ORM\Mapping as ORM;
  13. #[ORM\Table(name: 'page_seo_texts')]
  14. #[ORM\Entity(repositoryClass: PageMetadataRepository::class)]
  15. class PageMetadata
  16. {
  17.     const PAGE_REQUEST_ATTRIBUTE = '_page_seo';
  18.     const FALLBACK_REQUEST_ATTRIBUTE = '_page_seo.fallback';
  19.     #[ORM\Id]
  20.     #[ORM\Column(name: 'id', type: 'integer')]
  21.     #[ORM\GeneratedValue(strategy: 'AUTO')]
  22.     protected int $id;
  23.     #[ORM\JoinColumn(name: 'city_id', referencedColumnName: 'id')]
  24.     #[ORM\ManyToOne(targetEntity: City::class)]
  25.     protected ?City $city = null;
  26.     #[ORM\Column(name: 'uri', type: 'string', unique: true)]
  27.     protected ?string $uri = null;
  28.     #[ORM\Column(name: 'top_html', type: 'translatable', nullable: true)]
  29.     protected ?TranslatableValue $topHtml = null;
  30.     #[ORM\Column(name: 'bottom_html', type: 'translatable', nullable: true)]
  31.     protected ?TranslatableValue $bottomHtml = null;
  32.     #[ORM\Column(name: 'meta_title', type: 'translatable', nullable: true)]
  33.     protected ?TranslatableValue $metaTitle = null;
  34.     #[ORM\Column(name: 'meta_description', type: 'translatable', nullable: true)]
  35.     protected ?TranslatableValue $metaDescription = null;
  36.     #[ORM\Column(name: 'meta_keywords', type: 'translatable', nullable: true)]
  37.     protected ?TranslatableValue $metaKeywords = null;
  38.     #[ORM\Column(name: 'page_heading', type: 'translatable', nullable: true)]
  39.     protected ?TranslatableValue $pageHeading = null;
  40.     #[ORM\Column(name: 'last_modified', type: 'datetime_immutable', nullable: true)]
  41.     protected ?\DateTimeImmutable $lastModified = null;
  42.     public static function create(City $city, string $uri, ?TranslatableValue $topHtml, ?TranslatableValue $bottomHtml, ?TranslatableValue $metaTitle, ?TranslatableValue $metaDescription, ?TranslatableValue $metaKeywords, ?TranslatableValue $pageHeading): self
  43.     {
  44.         $page = new static();
  45.         $page->city = $city;
  46.         $page->uri = $uri;
  47.         $page->update($topHtml, $bottomHtml, $metaTitle, $metaDescription, $metaKeywords, $pageHeading);
  48.         return $page;
  49.     }
  50.     public function update(?TranslatableValue $topHtml, ?TranslatableValue $bottomHtml, ?TranslatableValue $metaTitle, ?TranslatableValue $metaDescription, ?TranslatableValue $metaKeywords, ?TranslatableValue $pageHeading): void
  51.     {
  52.         if ($topHtml) {
  53.             $this->topHtml = $topHtml;
  54.         }
  55.         if ($bottomHtml) {
  56.             $this->bottomHtml = $bottomHtml;
  57.         }
  58.         if ($metaTitle) {
  59.             $this->metaTitle = $metaTitle;
  60.         }
  61.         if ($metaDescription) {
  62.             $this->metaDescription = $metaDescription;
  63.         }
  64.         if ($metaKeywords) {
  65.             $this->metaKeywords = $metaKeywords;
  66.         }
  67.         if ($pageHeading) {
  68.             $this->pageHeading = $pageHeading;
  69.         }
  70.     }
  71.     public function getId(): int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getCity(): ?City
  76.     {
  77.         return $this->city;
  78.     }
  79.     public function getUri(): ?string
  80.     {
  81.         return $this->uri;
  82.     }
  83.     public function getTopHtml(): ?TranslatableValue
  84.     {
  85.         return $this->topHtml;
  86.     }
  87.     public function hasTopHtml(): bool
  88.     {
  89.         return null !== $this->topHtml;
  90.     }
  91.     public function getBottomHtml(): ?TranslatableValue
  92.     {
  93.         return $this->bottomHtml;
  94.     }
  95.     public function hasBottomHtml(): bool
  96.     {
  97.         return null !== $this->bottomHtml;
  98.     }
  99.     public function getMetaTitle(): ?TranslatableValue
  100.     {
  101.         return $this->metaTitle;
  102.     }
  103.     public function hasMetaTitle(): bool
  104.     {
  105.         return null !== $this->metaTitle;
  106.     }
  107.     public function getMetaDescription(): ?TranslatableValue
  108.     {
  109.         return $this->metaDescription;
  110.     }
  111.     public function hasMetaDescription(): bool
  112.     {
  113.         return null !== $this->metaDescription;
  114.     }
  115.     public function getMetaKeywords(): ?TranslatableValue
  116.     {
  117.         return $this->metaKeywords;
  118.     }
  119.     public function hasMetaKeywords(): bool
  120.     {
  121.         return null !== $this->metaKeywords;
  122.     }
  123.     public function getPageHeading(): ?TranslatableValue
  124.     {
  125.         return $this->pageHeading;
  126.     }
  127.     public function hasPageHeading(): bool
  128.     {
  129.         return null !== $this->pageHeading;
  130.     }
  131.     public function getLastModified(): ?\DateTimeImmutable
  132.     {
  133.         return $this->lastModified;
  134.     }
  135.     public function touchLastModified(): void
  136.     {
  137.         $this->lastModified = CarbonImmutable::now();
  138.     }
  139. }