eintragung geht 🎉
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s

This commit is contained in:
Chris 2023-10-31 15:32:29 +01:00
parent 4ef26e2b64
commit e550c42488
5 changed files with 107 additions and 27 deletions

View File

@ -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 [];
}
}

View File

@ -12,6 +12,7 @@ class Run extends Model
'time_max' => ['type' => 'int'], // in sek
'referee' => ['type' => 'text'],
'photo' => ['type' => 'text'],
'results' => ['type' => 'array','default'=>[]],
);
}

View File

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

View File

@ -18,40 +18,54 @@
<h2>Ergebnis
<?= $result_id?'Bearbeiten':'Eintragen'; ?>
</h2>
<form>
<form hx-post="/runs/validateresults" hx-encoding='multipart/form-data' hx-target="#response">
<input type="hidden" name="result_id" value="<?= $result_id; ?>">
<input type="hidden" name="run_id" value="<?= $run_id; ?>">
<div>
<label for="dog">Hund</label>
<select id="dog" name="dog">
<option value="false" <?= !$result['dog']?'selected':''; ?>>-- Bitte auswählen --</option>
<?php foreach($_SESSION['user']->data['dogs'] as $dogid) : ?>
<?php
$dog = new Dog();
$dog->load($dogid);
$dd = $dog->data;
?>
<option value="<?= $dogid ?>" <?=$result['dog']==$dogid ?'selected':''; ?>><?= escape($dd['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-check form-switch">
<label class="form-check-label" for="disqualified">Disqualifiziert</label>
<input class="form-check-input" type="checkbox" id="disqualified" name="disqualified" value="1" <?= $result['disqualified']=='1'?'checked':''; ?>>
</div>
<div>
<label for="refusals">Verweigeresultgen</label>
<input type="number" value="<?= $result['refusals']; ?>" id="refusals" name="refusals" 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">
<input type="number" value="<?= $result['refusals']; ?>" id="refusals" name="refusals" placeholder="Flowbite">
</div>
<div>
<label for="faults">Fehler</label>
<input type="number" value="<?= $result['faults']; ?>" id="faults" name="faults" 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">
<input type="number" value="<?= $result['faults']; ?>" id="faults" name="faults" placeholder="Flowbite">
</div>
<div>
<label for="time_faults">Zeitfehler</label>
<input type="number" value="<?= $result['time_faults']; ?>" id="time_faults" name="time_faults" 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">
<input type="number" value="<?= $result['time_faults']; ?>" id="time_faults" name="time_faults" placeholder="Flowbite">
</div>
<div>
<label for="time">Zeit</label>
<input type="number" value="<?= $result['time']; ?>" id="time" name="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">
<input type="number" value="<?= $result['time']; ?>" id="time" name="time" placeholder="Flowbite">
</div>
<div>
<label for="penalties">Gesamtfehler</label>
<input type="number" value="<?= $result['penalties']; ?>" id="penalties" name="penalties" 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">
<input type="number" value="<?= $result['penalties']; ?>" id="penalties" name="penalties" placeholder="Flowbite">
</div>
<div>
<label for="time_speed">m/Sek</label>
<input type="number" value="<?= $result['time_speed']; ?>" id="time_speed" name="time_speed" 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">
<input type="number" value="<?= $result['time_speed']; ?>" id="time_speed" name="time_speed" placeholder="Flowbite">
</div>
<div>
<label for="bewertung">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">
<select id="bewertung" name="bewertung">
<option value="V" <?=$result['bewertung']=='V' ?'selected':''; ?>>V</option>
<option value="SG" <?=$result['bewertung']=='SG' ?'selected':''; ?>>SG</option>
<option value="G" <?=$result['bewertung']=='G' ?'selected':''; ?>>G</option>
@ -60,11 +74,11 @@
</div>
<div>
<label for="points">Punkte</label>
<input type="number" value="<?= $result['points']; ?>" id="points" name="points" 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">
<input type="number" value="<?= $result['points']; ?>" id="points" name="points" placeholder="Flowbite">
</div>
<div>
<label for="rank">Platz</label>
<input type="number" value="<?= $result['rank']; ?>" id="rank" name="rank" 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">
<input type="number" value="<?= $result['rank']; ?>" id="rank" name="rank" placeholder="Flowbite">
</div>
<div>
<label for="uploads">Uploads</label>
@ -76,11 +90,13 @@
</div>
<div>
<label for="memo">Memo</label>
<textarea value="<?= $result['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>
<textarea value="<?= $result['memo']; ?>" id="memo" name="memo" placeholder="Deine Gedankengänge"></textarea>
</div>
<div class="form-check form-switch">
<label class="form-check-label" for="public">Daten im Lauf veröffentlichen</label>
<input class="form-check-input" type="checkbox" id="public" name="public" value="1" <?= $result['public']!='0'?'checked':''; ?>>
</div>
<button type="submit" name="submit" value="true" class="btn btn-primary">Speichern</button>
<div id="response"></div>
</form>

View File

@ -59,16 +59,16 @@
<tbody>
<?php foreach($results as $result) : ?>
<tr>
<td><?= escape($result['place']); ?></td>
<td><?= escape($result['eliminated']); ?></td>
<td><?= escape($result['ranking']); ?></td>
<td><?= $result['disqualified']?'Ja':'Nein'; ?></td>
<td><?= escape($result['refusals']); ?></td>
<td><?= escape($result['faults']); ?></td>
<td><?= escape($result['time_faults']); ?></td>
<td><?= escape($result['time']); ?></td>
<td><?= escape($result['errors']); ?></td>
<td><?= escape($result['timefaults']); ?></td>
<td><?= escape($result['runtime']); ?></td>
<td><?= escape($result['penalties']); ?></td>
<td><?= escape($result['time_speed']); ?></td>
<td><?= escape($result['bewertung']); ?></td>
<td><?= escape($result['member']); ?></td>
<td><?= escape($result['speed']); ?></td>
<td><?= escape($result['rating']); ?></td>
<td><?= escape( (new Dog())->getField('name',$result['dog']) ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>