From 1909be531459ac53cc67021f61aae59f764753b7 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 30 Oct 2023 22:20:13 +0100 Subject: [PATCH] =?UTF-8?q?run=20hinzuf=C3=BCgen=20geht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/inc/helpers.php | 2 +- web/models/Run.model.php | 17 +++ web/models/Tournament.model.php | 1 + web/pages/runs/controller.php | 129 ++++++++++++++++++ .../edit_run.html => runs/edit_result.html} | 55 +------- web/pages/runs/edit_run.html | 47 +++++++ web/pages/runs/run.html | 54 ++++++++ web/pages/tournaments/event.html | 45 +++++- 8 files changed, 296 insertions(+), 54 deletions(-) create mode 100644 web/models/Run.model.php create mode 100644 web/pages/runs/controller.php rename web/pages/{tournaments/edit_run.html => runs/edit_result.html} (61%) create mode 100644 web/pages/runs/edit_run.html create mode 100644 web/pages/runs/run.html diff --git a/web/inc/helpers.php b/web/inc/helpers.php index b08718a..4be1f5e 100644 --- a/web/inc/helpers.php +++ b/web/inc/helpers.php @@ -246,7 +246,7 @@ function pictshareUploadImage($path,$hash=false) function partial($name,$variables=[]) { $templatefile = ROOT.DS.'templates'.DS.'partials'.DS.$name; - return template($name,$variables); + return template($templatefile,$variables); } function template($templatefile,$variables=[]) diff --git a/web/models/Run.model.php b/web/models/Run.model.php new file mode 100644 index 0000000..c8da142 --- /dev/null +++ b/web/models/Run.model.php @@ -0,0 +1,17 @@ + ['type' => 'text', 'required'], + 'name' => ['type' => 'text', 'required'], + 'category' => ['type' => 'text'], + 'length' => ['type' => 'int'], //in meters + 'time_standard' => ['type' => 'int'], // in sek + 'time_max' => ['type' => 'int'], // in sek + 'referee' => ['type' => 'text'], + 'photo' => ['type' => 'text'], + ); + +} diff --git a/web/models/Tournament.model.php b/web/models/Tournament.model.php index e80e4f5..edd27c0 100644 --- a/web/models/Tournament.model.php +++ b/web/models/Tournament.model.php @@ -13,6 +13,7 @@ class Tournament extends Model 'logo' => ['type' => 'text', 'default' => 'https://pictshare.net/prrnrk.jpg'], 'admins' => ['type'=> 'array', 'default'=>[]], 'members' => ['type'=> 'array', 'default'=>[]], + 'runs' => ['type'=> 'array', 'default'=>[]], ); function joinUser($tournament = false) diff --git a/web/pages/runs/controller.php b/web/pages/runs/controller.php new file mode 100644 index 0000000..6290c71 --- /dev/null +++ b/web/pages/runs/controller.php @@ -0,0 +1,129 @@ +menu_text = 'Läufe'; + // $this->menu_image = 'fas fa-running'; + // $this->menu_priority = 3; + } + + function overview() + { + $run = new Run(); + $rid = $this->params[0]; + if(!$run->exists($rid)) + return partial('error.html', ['errorMessage' => 'Dieser Lauf existiert nicht']); + $run->load($rid); + $t = new Tournament(); + $t->load($run->data['tournament']); + + $this->set('admin',$t->amIAdmin()); + $this->set('tournament', $t->data); + $this->set('tournament_id', $run->data['tournament']); + $this->set('run', $run->data); + $this->set('run_id', $rid); + $this->set('template', 'run.html'); + } + + function add() + { + $tournament = $this->params[0]; + $t = new Tournament(); + if(!$t->exists($tournament)) + return partial('error.html', ['errorMessage' => 'Dieses Turnier existiert nicht']); + $t->load($tournament); + if(!$t->amIAdmin($tournament)) + return partial('error.html', ['errorMessage' => 'Du bist kein Admin dieses Turniers']); + else + { + $this->set('tournament', $t->data); + $this->set('tournament_id', $tournament); + $this->set('template', 'edit_run.html'); + } + } + + function edit() + { + $rid = $this->params[0]; + $r = new Run(); + $t = new Tournament(); + if(!$r->exists($rid)) + return partial('error.html', ['errorMessage' => 'Dieser Run existiert nicht']); + $r->load($rid); + $tournament = $r->data['tournament']; + $t->load($tournament); + if(!$t->amIAdmin($tournament)) + return partial('error.html', ['errorMessage' => 'Du bist kein Admin dieses Turniers']); + else + { + $this->set('tournament', $t->data); + $this->set('tournament_id', $tournament); + $this->set('run_id',$rid); + $this->set('run',$r->data); + $this->set('template', 'edit_run.html'); + } + } + + function validate() + { + + if($_REQUEST['submit']=='true') + { + $t = new Tournament(); + + if(!$t->exists($_REQUEST['tournament_id'])) + return partial('error.html', ['errorMessage' => 'Dieses Turnier existiert nicht']); + $t->load($_REQUEST['tournament_id']); + + if(!$t->amIAdmin($_REQUEST['tournament_id'])) + return partial('error.html', ['errorMessage' => 'Du bist kein Admin dieses Turniers']); + + $run = new Run(); + if($_REQUEST['run_id']) + { + if(!$run->exists($_REQUEST['run_id'])) + return partial('error.html', ['errorMessage' => 'Dieser Lauf existiert nicht']); + $run->load($_REQUEST['run_id']); + if(!$run->data['tournament']==$t->id) + return partial('error.html', ['errorMessage' => 'Dieser Lauf gehört nicht zu diesem Turnier']); + } + else + $run->id = gen_ulid(); + + + + $run->data['tournament'] = $_REQUEST['tournament_id']; + $run->data['name'] = trim($_REQUEST['name']); + $run->data['category'] = $_REQUEST['category']; + $run->data['length'] = $_REQUEST['length']; + $run->data['time_standard'] = $_REQUEST['time_standard']; + $run->data['time_max'] = $_REQUEST['time_max']; + $run->data['referee'] = $_REQUEST['referee']; + + try{ + $runid = $run->save(); + } + catch(Exception $e) + { + return partial('error.html', ['errorMessage' => 'Fehler beim Speichern des Laufs: '.$e->getMessage()]); + } + + if(!in_array($runid, $t->data['runs'])) + { + $t->data['runs'][] = $runid; + $t->save(); + } + + $this->redirect('/tournaments/event/'.$t->id); + } + else return partial('error.html', ['errorMessage' => 'Fehler beim Speichern des Laufs']); + } + + function maySeeThisPage() { + if($_SESSION['user']) //wenn eingeloggt, kein problem + return true; + else return false; + } +} \ No newline at end of file diff --git a/web/pages/tournaments/edit_run.html b/web/pages/runs/edit_result.html similarity index 61% rename from web/pages/tournaments/edit_run.html rename to web/pages/runs/edit_result.html index bfa8fe0..c732183 100644 --- a/web/pages/tournaments/edit_run.html +++ b/web/pages/runs/edit_result.html @@ -1,36 +1,4 @@ - -
-

Agility / Jumping

- -
- -

Parcourdetails

-
- - -
-
- - -
-
- - -
-
- - -
- -
- - -
- -

Ergebnis

+

Ergebnis

@@ -62,10 +30,10 @@
@@ -87,15 +55,4 @@
-
- - - -
-
- - \ No newline at end of file +
\ No newline at end of file diff --git a/web/pages/runs/edit_run.html b/web/pages/runs/edit_run.html new file mode 100644 index 0000000..ef81896 --- /dev/null +++ b/web/pages/runs/edit_run.html @@ -0,0 +1,47 @@ + +
+

Lauf

+ +
+ + +

Parcourdetails

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+
+ + \ No newline at end of file diff --git a/web/pages/runs/run.html b/web/pages/runs/run.html new file mode 100644 index 0000000..3e59cc2 --- /dev/null +++ b/web/pages/runs/run.html @@ -0,0 +1,54 @@ +
+
+
+
+ <?= escape($run['name']); ?>'s profile Picture +
+
+

+

    + +
  • Gehört zu
  • +
  • Typ:
  • +
  • Länge: m
  • +
  • Normzeit: s
  • +
  • Maxzeit: s
  • +
  • Richter:
  • +
+ + +
+ + + +
+
+
+ +
+ 0): ?>
Admins
+ + <?= escape($adm['name']); ?> + + + 0): ?>
Mitglieder
+ + <?= escape($member['name']); ?> + +
+
+
+
+

Ergebnisse

+

+ +

+ +
+
+ +
+
+ diff --git a/web/pages/tournaments/event.html b/web/pages/tournaments/event.html index fedb4a0..f2b9a39 100644 --- a/web/pages/tournaments/event.html +++ b/web/pages/tournaments/event.html @@ -8,7 +8,6 @@

-

  • Datum:
  • @@ -36,14 +35,13 @@
-
0): ?>
Admins
- - <?= escape($admin['name']); ?> + + <?= escape($adm['name']); ?> 0): ?>
Mitglieder
@@ -60,6 +58,45 @@

+ +
+

Läufe

+

+ + + + + + + + + + + + + + + + + + load($rid); + ?> + + + + + + + + + + +
BezeichnungLaufParcourlängeNormzeitMaxzeitRichter
data['name']); ?>data['category']); ?>data['length']); ?>mdata['time_standard']); ?>sdata['time_max']); ?>sdata['referee']); ?>
+

+ +