id = $id;
$this->name = $name;
$this->club = $club;
$this->course = $course;
for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
$this->splits[$i] = false;
}
}
function set_split($control, $timestamp)
{
$this->splits[$control] = $timestamp;
}
function get_control()
{
// Returns wich control the runner last passed
for ($i = 0; $i < count($this->splits); $i++) {
if (!is_object($this->splits[$i])) {
return $i-1;
}
}
return count($this->splits)-1;
}
}
//find runner by id in list of Runner objects
function get_runner($runnner_list, int $id)
{
for ($i = 0; $i < count($runnner_list); $i++) {
if ($runnner_list[$i]->id == $id) {
return $runnner_list[$i];
}
}
return false;
}
function cmp(Runner $a, Runner $b) {
$a_control = $a->get_control();
$b_control = $b->get_control();
if ($a_control > $b_control){
return -1;
}
if ($a_control < $b_control){
return 1;
}
if ($a_control == -1) {
return 1;
}
if ($b_control == -1) {
return -1;
}
if ($a->splits[$a_control]->getTimestamp() < $b->splits[$b_control]->getTimestamp()){
return -1;
}
if ($a->splits[$a_control]->getTimestamp() > $b->splits[$b_control]->getTimestamp()){
return 1;
}
return 0;
}
function cmp_course(Runner $a, Runner $b) {
return strcmp($a->course, $b->course);
}
$runners = [];
$csv_runners = file_get_contents("db.csv");
$csv_runners = str_getcsv($csv_runners, "\n");
//print_r($csv_runners);
for ($i = 1; $i < count($csv_runners); $i++) {
$line = str_getcsv($csv_runners[$i]);
array_push($runners, new Runner($line[0], $line[1], $line[2], $line[3]));
}
$timings = file_get_contents("passering.csv");
$timings = str_getcsv($timings, "\n");
for ($i = 0; $i < count($timings); $i++) {
$line = str_getcsv($timings[$i]);
$time = DateTime::createFromFormat("Y-m-d\TH:i:sp", $line[2]);
if (!$time) {
//error
continue;
}
$runner = get_runner($runners, (int) $line[1]);
if (!$runner) {
//error
continue;
}
$runner->set_split($line[0]-1, $time);
}
if (!isset($query)){
$query = explode(",",$_SERVER['QUERY_STRING']);
}
if ($query[0] == "registrering"){
$matpost = $query[1];
echo("
#
Navn
Tid
");
for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i];
// Klokkeslett for denne posten
if ($runner->splits[$matpost-1] != false) {
$tid_passering = $GLOBALS['start_time']->diff($runner->splits[$matpost-1])->format('%H:%I:%S');
}
else {
$tid_passering = "";
}
if ($runner->get_control() == $matpost-1) {
// Løperen har vært på denne matposten og vi farger raden grønn
$button = "";
$cssclass = "class=\"bg-success\"";
}
elseif ($runner->get_control() > $matpost-1) {
// Løperen har vært på denne matposten og vi farger raden grønn
$button = "";
$cssclass = "class=\"bg-active\"";
}
else {
$button = "";
$cssclass = "";
}
echo ("