<?php
class RankingEngine implements RankingInterface {
    private $repo;
    private $events;

    public function __construct(RaceRepository $repo, ChairmanEventDispatcher $events=null) {
        $this->repo = $repo;
        $this->events = $events;
    }

    public function ranking($raceDate, $venue='', $raceNum=0) {
        if($this->events) $this->events->dispatch('BeforeRanking', compact('raceDate','venue','raceNum'));
        $rows = $this->repo->productionRows($raceDate,$venue,$raceNum);
        if($this->events) $this->events->dispatch('AfterRanking', array('rows'=>count($rows)));
        return $rows;
    }
}
