Ejemplo n.º 1
0
 /**
  * Get the best possible lap. Based on sectors. Also includes non-completed
  * laps.
  *
  * @return  Lap|null
  */
 public function getBestPossibleLap()
 {
     // There is cache
     if ($this->cache_best_possible_lap !== null) {
         return $this->cache_best_possible_lap;
     }
     // No best lap of one of the sectors
     if (!($sector1_lap = $this->getBestLapBySector(1)) or !($sector2_lap = $this->getBestLapBySector(2)) or !($sector3_lap = $this->getBestLapBySector(3))) {
         return null;
     }
     // Get sector times
     $sector_1 = $sector1_lap->getSectorTime(1);
     $sector_2 = $sector2_lap->getSectorTime(2);
     $sector_3 = $sector3_lap->getSectorTime(3);
     // One of the sectors is missing
     if (!$sector_1 or !$sector_2 or !$sector_3) {
         return null;
     }
     // Create best possible lap
     $best_possible_lap = new Lap();
     $best_possible_lap->setSectorTimes(array($sector_1, $sector_2, $sector_3))->setTime(round(round($sector_1 + $sector_2, 4) + $sector_3, 4))->setParticipant($this);
     // Return best possible lap and cache it
     return $this->cache_best_possible_lap = $best_possible_lap;
 }