<?php
class RaceRepository {
    private $db;

    public function __construct(mysqli $db) {
        $this->db = $db;
    }

    public function productionRows($raceDate, $venue='', $raceNum=0) {
        if (!chairman_table_exists($this->db, 'wr_chairman_production_score_v44')) return array();
        $where=array("race_date=" . chairman_q($this->db,$raceDate));
        if($venue!=='') $where[]="venue=" . chairman_q($this->db,$venue);
        if(chairman_i($raceNum)>0) $where[]="race_num=" . chairman_i($raceNum);
        return chairman_rows($this->db, "SELECT * FROM wr_chairman_production_score_v44 WHERE ".implode(' AND ',$where)." ORDER BY race_num ASC, race_rank ASC, calibrated_score DESC");
    }
}
