diff --git a/web/models/Result.model.php b/web/models/Result.model.php index 1aab238..a0fd896 100644 --- a/web/models/Result.model.php +++ b/web/models/Result.model.php @@ -7,6 +7,7 @@ class Result extends Model 'tournament' => ['type' => 'text', 'required'], //tournament ID 'run' => ['type' => 'text', 'required'], //run ID 'user' => ['type' => 'text', 'required'], //user ID + 'dog' => ['type' => 'text', 'required'], //dog ID 'disqualified' => ['type' => 'bool','default'=>0], 'refusals' => ['type' => 'int','default'=>0], @@ -22,7 +23,31 @@ class Result extends Model 'videos' => ['type' => 'array','default'=>[]], 'memo' => ['type' => 'text'], 'public' => ['type' => 'bool','default'=>1], - ); + function getDataOfRun($rid) + { + $run = new Run(); + if($run->exists($rid)) + $run->load($rid); + else return false; + + $results = $run->data['results']; + if(is_array($results) && count($results)>0) + { + $res = []; + foreach($results as $r) + { + $result = new Result(); + if($result->exists($r)) + { + $result->load($r); + $res[] = $result->data; + } + } + return $res; + } + else return []; + } + } diff --git a/web/models/Run.model.php b/web/models/Run.model.php index c8da142..79943ac 100644 --- a/web/models/Run.model.php +++ b/web/models/Run.model.php @@ -12,6 +12,7 @@ class Run extends Model 'time_max' => ['type' => 'int'], // in sek 'referee' => ['type' => 'text'], 'photo' => ['type' => 'text'], + 'results' => ['type' => 'array','default'=>[]], ); } diff --git a/web/pages/runs/controller.php b/web/pages/runs/controller.php index be44b17..fef134a 100644 --- a/web/pages/runs/controller.php +++ b/web/pages/runs/controller.php @@ -19,9 +19,14 @@ class Runs extends Page { $t = new Tournament(); $t->load($run->data['tournament']); + $res = new Result(); + $results = $res->getDataOfRun($rid); + + $this->set('admin',$t->amIAdmin()); $this->set('tournament', $t->data); $this->set('tournament_id', $run->data['tournament']); + $this->set('results', $results); $this->set('run', $run->data); $this->set('run_id', $rid); $this->set('template', 'run.html'); @@ -49,7 +54,7 @@ class Runs extends Page { } } - function validateResults() + function validateresults() { $rid = $_REQUEST['run_id']; $run = new Run(); @@ -74,12 +79,45 @@ class Runs extends Page { return partial('error.html', ['errorMessage' => 'Du bist in diesem Turnier nicht angemeldet']); else { - $run->data['results']['time'] = $_REQUEST['time']; - $run->data['results']['penalty'] = $_REQUEST['penalty']; - $run->data['results']['disq'] = $_REQUEST['disq']; - $run->data['results']['comment'] = $_REQUEST['comment']; - $run->data['results']['referee'] = $_REQUEST['referee']; - $run->data['results']['judge'] = $_REQUEST['judge']; + $dogid = $_REQUEST['dog']; + if(!$dogid || $dogid=='false') + return partial('error.html', ['errorMessage' => 'Du musst einen Hund auswählen']); + $dog = new Dog(); + if(!$dog->exists($dogid)) + return partial('error.html', ['errorMessage' => 'Dieser Hund existiert nicht']); + else if(!$dog->isMyDog($dogid)) + return partial('error.html', ['errorMessage' => 'Dieser Hund gehört nicht dir']); + + $res->dog = $dogid; + $res->disqualified = $_REQUEST['disqualified']; + $res->refusals = $_REQUEST['refusals']; + $res->timefaults = $_REQUEST['time_faults']; + $res->runtime = $_REQUEST['time']; + $res->penalties = $_REQUEST['penalties']; + $res->speed = $_REQUEST['time_speed']; + $res->rating = $_REQUEST['bewertung']; + $res->points = $_REQUEST['points']; + $res->ranking = $_REQUEST['rank']; + $res->public = $_REQUEST['public']; + $res->tournament = $tid; + $res->run = $rid; + $res->user = $_SESSION['user']->id; + + try{ + $resid = $res->save(); + + if(!in_array($resid, $run->data['results'])) + { + $run->data['results'][] = $resid; + $run->save(); + } + } + catch(Exception $e) + { + return partial('error.html', ['errorMessage' => 'Fehler beim Speichern des Ergebnisses: '.$e->getMessage()]); + } + + $this->redirect('/runs/overview/'.$rid); } } diff --git a/web/pages/runs/edit_result.html b/web/pages/runs/edit_result.html index 9aeb1de..1876c34 100644 --- a/web/pages/runs/edit_result.html +++ b/web/pages/runs/edit_result.html @@ -18,40 +18,54 @@