run hinzufügen geht
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s

This commit is contained in:
Chris 2023-10-30 22:20:13 +01:00
parent 8656fd5d60
commit 1909be5314
8 changed files with 296 additions and 54 deletions

View File

@ -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=[])

17
web/models/Run.model.php Normal file
View File

@ -0,0 +1,17 @@
<?php
class Run extends Model
{
protected $dbTable = "run";
protected $dbFields = array(
'tournament' => ['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'],
);
}

View File

@ -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)

View File

@ -0,0 +1,129 @@
<?php
class Runs extends Page {
function setMenu()
{
// $this->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;
}
}

View File

@ -1,36 +1,4 @@
<!-- das hier sollte bei einem Turnier mehrfach hinzugefügt werden können. Auswahl aus Agility & Jumping -->
<div>
<h1>Agility / Jumping <?= $run_id?'Bearbeiten':'Hinzufügen'; ?></h1>
<form id="tournamenteditform" hx-post="/tournaments/edit" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="tournament_id" value="<?= $run_id; ?>">
<h2>Parcourdetails</h2>
<div>
<label for="run_category" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Parcourtyp</label>
<select id="run_category" name="run_category" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option value="Agility" <?= $tournamentdata['run_category']=='Agility'?'selected':''; ?>>Agility</option>
<option value="Jumping" <?= $tournamentdata['run_category']=='Jumping'?'selected':''; ?>>Jumping</option>
</select>
</div>
<div>
<label for="run_length" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Parcourlänge (in m)</label>
<input type="text" value="<?= $run['run_length']; ?>" id="run_length" name="run_length" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Max" required>
</div>
<div>
<label for="norm_time" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Normzeit</label>
<input type="number" value="<?= $run['norm_time']; ?>" id="norm_time" name="norm_time" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Zuchtname">
</div>
<div>
<label for="max_time" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Maxzeit</label>
<input type="number" value="<?= $run['max_time']; ?>" id="max_time" name="max_time" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Flowbite">
</div>
<div class="mb-3 mb-md-4">
<label for="tournament_referee">Richter</label>
<input type="text" value="<?= $tournamentdata['referee']; ?>" id="tournament_referee" name="tournament_referee" placeholder="Franz Ferdinand" class="form-control">
</div>
<h2>Ergebnis</h2>
<h2>Ergebnis <?= $run_id?'Bearbeiten':'Eintragen'; ?></h2>
<div>
<label for="eliminated" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Disqualifiziert</label>
<input type="number" value="<?= $run['eliminated']; ?>" id="eliminated" name="eliminated" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Flowbite">
@ -62,10 +30,10 @@
<div>
<label for="bewertung" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Bewertung</label>
<select id="bewertung" name="bewertung" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
<option value="V" <?= $tournamentdata['bewertung']=='V'?'selected':''; ?>>V</option>
<option value="SG" <?= $tournamentdata['bewertung']=='SG'?'selected':''; ?>>SG</option>
<option value="G" <?= $tournamentdata['bewertung']=='G'?'selected':''; ?>>G</option>
<option Galue="B" <?= $tournamentdata['bewertung']=='B'?'selected':''; ?>>B</option>
<option value="V" <?= $rundata['bewertung']=='V'?'selected':''; ?>>V</option>
<option value="SG" <?= $rundata['bewertung']=='SG'?'selected':''; ?>>SG</option>
<option value="G" <?= $rundata['bewertung']=='G'?'selected':''; ?>>G</option>
<option Galue="B" <?= $rundata['bewertung']=='B'?'selected':''; ?>>B</option>
</select>
</div>
<div>
@ -88,14 +56,3 @@
<label for="memo" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Memo</label>
<textarea value="<?= $run['memo']; ?>" id="memo" name="memo" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Deine Gedankengänge"></textarea>
</div>
<button type="submit" name="submit" value="true" class="btn btn-primary">Submit</button> <!-- Submit Button führt auf eine neue Seite wo man die Laufinfo eingibt -->
</form>
<progress id='progress' value='0' max='100'></progress>
<div id="response"></div>
</div>
<script>
htmx.on('#dogeditform', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
</script>

View File

@ -0,0 +1,47 @@
<!-- das hier sollte bei einem Turnier mehrfach hinzugefügt werden können. Auswahl aus Agility & Jumping -->
<div>
<h1>Lauf <?= $tournament_id?'Bearbeiten':'Hinzufügen'; ?></h1>
<form id="tournamenteditform" hx-post="/runs/validate" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="tournament_id" value="<?= $tournament_id; ?>">
<input type="hidden" name="run_id" value="<?= $run_id; ?>">
<h2>Parcourdetails</h2>
<div>
<label for="name">Bezeichnung</label>
<input type="text" value="<?= $run['name']; ?>" id="name" name="name" placeholder="zb: Oldies Jumping" required>
</div>
<div>
<label for="category">Parcourtyp</label>
<select id="category" name="category" >
<option value="Agility" <?= $run['category']=='Agility'?'selected':''; ?>>Agility</option>
<option value="Jumping" <?= $run['category']=='Jumping'?'selected':''; ?>>Jumping</option>
</select>
</div>
<div>
<label for="length">Parcourlänge (in m)</label>
<input type="number" min="1" max="1000" value="<?= $run['length']; ?>" id="length" name="length" placeholder="Max">
</div>
<div>
<label for="time_standard">Normzeit</label>
<input type="number" value="<?= $run['time_standard']?:0; ?>" id="time_standard" name="time_standard" placeholder="Zuchtname">
</div>
<div>
<label for="time_max">Maxzeit</label>
<input type="number" value="<?= $run['time_max']?:0; ?>" id="time_max" name="time_max" placeholder="Flowbite">
</div>
<div class="mb-3 mb-md-4">
<label for="referee">Richter</label>
<input type="text" value="<?= $run['referee']; ?>" id="referee" name="referee" placeholder="Franz Ferdinand" class="form-control">
</div>
<button type="submit" name="submit" value="true" class="btn btn-primary">Submit</button> <!-- Submit Button führt auf eine neue Seite wo man die Laufinfo eingibt -->
</form>
<progress id='progress' value='0' max='100'></progress>
<div id="response"></div>
</div>
<script>
htmx.on('#dogeditform', 'htmx:xhr:progress', function(evt) {
htmx.find('#progress').setAttribute('value', evt.detail.loaded/evt.detail.total * 100)
});
</script>

54
web/pages/runs/run.html Normal file
View File

@ -0,0 +1,54 @@
<div class="container">
<div class="row">
<div class="col-3">
<div class="card">
<?php if($run['photo']): ?><img src="<?= $run['photo'] ?>/300x170/fixedsize" class="card-img-top" alt="<?= escape($run['name']); ?>'s profile Picture"> <?php endif; ?>
<div class="card-body">
<h5 class="card-title"><?= escape($run['name']); ?></h5>
<p class="card-text">
<ul>
<li>Gehört zu <a href="/tournaments/event/<?= $tournament_id; ?>" hx-push-url="/tournaments/event/<?= $tournament_id; ?>" hx-get="/tournaments/event/<?= $tournament_id; ?>" hx-target="#main"><?= escape($tournament['name']); ?></a></li>
<?php if($run['category']): ?> <li>Typ: <?= escape($run['category']); ?></li><?php endif; ?>
<?php if($run['length']): ?> <li>Länge: <?= escape($run['length']); ?>m</li><?php endif; ?>
<?php if($run['time_standard']): ?> <li>Normzeit: <?= escape($run['time_standard']); ?>s</li><?php endif; ?>
<?php if($run['time_max']): ?> <li>Maxzeit: <?= escape($run['time_max']); ?>s</li><?php endif; ?>
<?php if($run['referee']): ?> <li>Richter: <?= escape($run['referee']); ?></li><?php endif; ?>
</ul>
<div class="d-flex justify-content-end">
<?php if($admin===true): ?>
<button type="button" class="btn btn-secondary" hx-get="/runs/edit/<?= $run_id; ?>" hx-target="#main">
<i class="fas fa-edit"></i>
</button>
<?php endif; ?>
</div>
</div>
</div>
<div class="card p-2">
<?php if($admins && count($admins)>0): ?> <h6>Admins</h6> <?php endif; ?>
<?php foreach($admins as $adm) : ?>
<img src="https://pictshare.net/identicon/<?= $adm['email']?>" height="50" width="50" class="rounded-circle" alt="<?= escape($adm['name']); ?>" title="<?= escape($adm['firstname'].' '.$adm['lastname']); ?>">
<?php endforeach; ?>
<?php if($members && count($members)>0): ?> <hr/> <h6>Mitglieder</h6> <?php endif; ?>
<?php foreach($members as $member) : ?>
<img src="https://pictshare.net/identicon/<?= $member['email']?>" height="50" width="50" class="rounded-circle" alt="<?= escape($member['name']); ?>" title="<?= escape($member['firstname'].' '.$member['lastname']); ?>">
<?php endforeach; ?>
</div>
</div>
<div class="col-6" id="sitemain">
<div class="card p-2">
<h4>Ergebnisse</h4>
<p class="card-text">
</p>
</div>
</div>
</div>
</div>

View File

@ -8,7 +8,6 @@
<div class="card-body">
<h5 class="card-title"><?= escape($tdata['name']); ?></h5>
<p class="card-text">
<ul>
<li>Datum: <?= escape($tdata['date']) ?></li>
@ -36,14 +35,13 @@
</button>
<?php endif; ?>
</div>
</div>
</div>
<div class="card p-2">
<?php if($admins && count($admins)>0): ?> <h6>Admins</h6> <?php endif; ?>
<?php foreach($admins as $admin) : ?>
<img src="https://pictshare.net/identicon/<?= $admin['email']?>" height="50" width="50" class="rounded-circle" alt="<?= escape($admin['name']); ?>" title="<?= escape($admin['firstname'].' '.$admin['lastname']); ?>">
<?php foreach($admins as $adm) : ?>
<img src="https://pictshare.net/identicon/<?= $adm['email']?>" height="50" width="50" class="rounded-circle" alt="<?= escape($adm['name']); ?>" title="<?= escape($adm['firstname'].' '.$adm['lastname']); ?>">
<?php endforeach; ?>
<?php if($members && count($members)>0): ?> <hr/> <h6>Mitglieder</h6> <?php endif; ?>
@ -60,6 +58,45 @@
</p>
</div>
<div class="card p-2 mt-4">
<h4>Läufe</h4>
<p class="card-text">
<?php if($admin===true): ?>
<button hx-get="/runs/add/<?= $tournament_id; ?>" hx-push-url="/runs/add/<?= $tournament_id; ?>" hx-target="#main" class="btn btn-primary"><i class="fas fa-plus-circle"></i> Lauf hinzufügen</button>
<?php endif; ?>
<table class="table">
<thead>
<tr>
<th>Bezeichnung</th>
<th>Lauf</th>
<th>Parcourlänge</th>
<th>Normzeit</th>
<th>Maxzeit</th>
<th>Richter</th>
</tr>
</thead>
<tbody>
<?php foreach($tdata['runs'] as $rid) : ?>
<?php
$run = new Run();
$run->load($rid);
?>
<tr>
<td><a href="/runs/overview/<?= $rid; ?>" hx-get="/runs/overview/<?= $rid; ?>" hx-push-url="/runs/overview/<?= $rid; ?>" hx-target="#main"><?= escape($run->data['name']); ?></a></td>
<td><?= escape($run->data['category']); ?></td>
<td><?= escape($run->data['length']); ?>m</td>
<td><?= escape($run->data['time_standard']); ?>s</td>
<td><?= escape($run->data['time_max']); ?>s</td>
<td><?= escape($run->data['referee']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</p>
</div>
</div>
</div>