if ($race_laps > 0) {
     if (intval($race->Laps) < $race_laps) {
         echo "race not finished (not enough laps)";
         exit;
     }
 } else {
     if (intval($race->Minutes) < $race_time) {
         echo "race not finished (did not last long enough)";
         exit;
     }
 }
 # ok we have a valid race, store it
 $track = $xml->RaceResults->TrackCourse;
 $race_time = $race->TimeString;
 #print_r($league);
 $race_id = create_race($track, $mod, $league->id, $race_time);
 # insert results
 foreach ($race->Driver as $driver_data) {
     $driver_name = $driver_data->Name;
     if ($driver = check_existence_of_registered_driver($driver_name, $league)) {
         echo "valid driver: {$driver->rfname} ({$driver->username})\n";
         # create result for driver
         create_result($race_id, $driver->user_id, $driver_data->FinishTime, $driver_data->FinishStatus, $driver_data->BestLapTime, $driver_data->Pitstops, $driver_data->Position, $driver_data->GridPos, $driver_data->Laps);
     } else {
         echo "driver {$driver_data->Name} does not exist or is not registered for league {$league->name}\n";
     }
 }
 # distribute points
 distribute_points($race_id);
 // $res = $xml->xpath("/rFactorXML/RaceResults/Race");
 // if (sizeof($res) == 1) {
示例#2
0
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $xmlstr = trim(file_get_contents('php://input'));
    $xmlstr = iconv('UTF-8', 'UTF-8//IGNORE', $xmlstr);
    $xml = new SimpleXMLElement($xmlstr);
    $res = $xml->xpath("/rFactorXML/RaceResults/Race");
    if (sizeof($res) == 1) {
        $race = $res[0];
        $race_laps = $race->Laps;
        $most_laps = $race->MostLapsCompleted;
        if (intval($most_laps) < intval($race_laps)) {
            echo "race not finished";
            exit;
        }
        # find/create event
        $track = $xml->RaceResults->TrackCourse;
        $mod = $xml->RaceResults->Mod;
        $season_id = find_or_create_season($_GET["season"]);
        echo "season_id: " . $season_id . " " . $_GET["season"] . "\n";
        $event_id = find_or_create_event($season_id, $track, $mod);
        echo "event_id: " . $event_id . "\n";
        $timestring = $race->TimeString;
        $laps = intval($race->Laps);
        echo "laps:";
        $race_id = create_race($event_id, $timestring, $laps);
        echo "race_id: " . $race_id . "\n";
        foreach ($race->Driver as $driver) {
            $driver_id = find_or_create_driver($driver->Name);
            $result_id = create_result($driver_id, $race_id, $driver->BestLapTime, $driver->FinishTime, $driver->FinishStatus, $driver->Laps);
        }
    }
}