TableQuery.php 1.81 KB
<?php

namespace FootyRoom\Queries;

use FootyRoom\Support\MongoClient;

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

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

    /**
     * Returns raw tables data queried by list of Enetpulse stage ids.
     *
     * @param int[] $enetStageIds
     *
     * @return array[]
     */
    public function findByEnetStageIds($enetStageIds)
    {
        $options = [
            'projection' => [
                '_id' => 0,
                'enetStageId' => 1,
                'conference' => 1,
                'spots' => 1,
                'participants.name' => 1,
                'participants.teamId' => 1,
                'participants.rank' => 1,
                'participants.form' => 1,
                'participants.next' => 1,
                'participants.data.wins.value' => 1,
                'participants.data.draws.value' => 1,
                'participants.data.defeats.value' => 1,
                'participants.data.goalsagainst.value' => 1,
                'participants.data.goalsfor.value' => 1,
                'participants.data.played.value' => 1,
                'participants.data.points.value' => 1,
                'participants.data.rank.value' => 1,
                'participants.data.currentRound' => 1,
                'participants.data.previousRound' => 1,
            ],
        ];

        return $this->mongo->tables->find(
            [
                'enetStageId' => ['$in' => $enetStageIds],
                'participants' => [
                    '$exists' => '1', '$not' => ['$size' => 0],
                ],
            ],
            $options
        );
    }
}