StageGuideQuery.php 853 Bytes
<?php

namespace FootyRoom\Queries;

use FootyRoom\Support\MongoClient;

class StageGuideQuery
{
    /**
     * @var \FootyRoom\Support\MongoClient
     */
    protected $mongo;

    /**
     * Constructor.
     *
     * @param \FootyRoom\Support\MongoClient $mongo
     */
    public function __construct(MongoClient $mongo)
    {
        $this->mongo = $mongo->footyroom;
    }

    /**
     * Finds one guide by stage id.
     *
     * @param int $stageId
     *
     * @return array|null
     */
    public function findOneByStageId($stageId): ?array
    {
        $guide = $this->mongo->guides->findOne([
            'stageId' => $stageId,
        ]);

        if (!$guide) {
            return null;
        }

        return [
            'html' => $guide['html'],
            'webpackAssets' => $guide['webpackAssets'] ?? [],
        ];
    }
}