Article.php 1.99 KB
<?php

namespace FootyRoom\Queries\Article;

use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;

class Article
{
    /** @var string */
    protected $id;

    /** @var string */
    protected $url;

    /** @var string */
    protected $thumbnailUrl;

    /** @var string */
    protected $title;

    /** @var string */
    protected $publisher;

    /** @var string */
    protected $content;

    /** @var string */
    protected $html;

    /** @var string Can be either 'published' or 'draft'. */
    protected $status;

    /** @var bool */
    protected $isFeatured;

    public function getId(): string
    {
        return $this->id;
    }

    public function getUrl(): string
    {
        return $this->url ?? URL::route('showArticle', [
            'id' => $this->getId(),
            'slug' => $this->getSlug(),
        ]);
    }

    public function getSlug(): string
    {
        return Str::slug($this->getTitle());
    }

    public function getThumbnailUrl(): string
    {
        return $this->thumbnailUrl;
    }

    public function getTitle(): string
    {
        return $this->title;
    }

    public function getContent(): ?string
    {
        return $this->content;
    }

    public function getHtml(): ?string
    {
        return $this->html;
    }

    public function getPublisher(): ?string
    {
        return $this->publisher;
    }

    public function getStatus(): string
    {
        return $this->status;
    }

    public function getIsFeatured(): bool
    {
        return $this->isFeatured;
    }

    public function toArray(): array
    {
        return [
            'id' => $this->getId(),
            'title' => $this->getTitle(),
            'content' => $this->getContent(),
            'html' => $this->getHtml(),
            'thumbnailUrl' => $this->getThumbnailUrl(),
            'url' => $this->getUrl(),
            'publisher' => $this->getPublisher(),
            'status' => $this->getStatus(),
            'isFeatured' => $this->getIsFeatured(),
        ];
    }
}