Match.php 2.2 KB
<?php

namespace FootyRoom\Queries\Match;

use JsonSerializable;
use DateTime;
use FootyRoom\Http\Match\MatchSlug;
use Laravel\Lumen\Routing\UrlGenerator as UrlGenerator;

class Match implements JsonSerializable
{
    public $id;

    public $homeTeam;

    public $awayTeam;

    public $homeScore;

    public $awayScore;

    public $homeScoreHT;

    public $awayScoreHT;

    public $homeScoreFT;

    public $awayScoreFT;

    public $homeScoreET;

    public $awayScoreET;

    public $homeScorePEN;

    public $awayScorePEN;

    public $homeScoreAggr;

    public $awayScoreAggr;

    public $homeAggrWin;

    public $awayAggrWin;

    public $datetime;

    public $timerStart;

    public $status;

    public $statusType;

    public $spectators;

    public $venueName;

    public $refereeName;

    public $round;

    public $region;

    public $stage;

    public $season;

    public $stageTree;

    public $stageId;

    public $incidents;

    public $lineup;

    public $stats;

    public $posts;

    public $legendary;

    public $predictor;

    public $lineupsConfirmed;

    public function jsonSerialize()
    {
        $asArray = (array) $this;

        if (isset($asArray['datetime'])) {
            $this->datetime->format(DateTime::ISO8601);
        }

        if (isset($asArray['timerStart'])) {
            $asArray['timerStart'] = $this->timerStart->format(DateTime::ISO8601);
        }

        return $asArray;
    }

    public function getReviewUrl(UrlGenerator $urlGenerator): string
    {
        return $urlGenerator->route('matchReview', [
            'id' => $this->id,
            'slug' => MatchSlug::fromMatchQuery($this),
        ]);
    }

    public function getPreviewUrl(UrlGenerator $urlGenerator): string
    {
        return $urlGenerator->route('matchPreview', [
            'id' => $this->id,
            'slug' => MatchSlug::fromMatchQuery($this),
        ]);
    }

    public function isReviewPublished(): bool
    {
        return isset($this->posts->review->status) && $this->posts->review->status === 'publish';
    }

    public function isPreviewPublished(): bool
    {
        return isset($this->posts->preview->status) && $this->posts->preview->status === 'publish';
    }
}