hundedaten jetzt korrekt

This commit is contained in:
Chris 2023-10-23 10:00:19 +02:00
parent f7a7c3457b
commit 7779d189df
5 changed files with 45 additions and 49 deletions

View File

@ -65,13 +65,10 @@ class Model {
{ {
if(isset($this->data[$field])) if(isset($this->data[$field]))
{ {
error_log($field.' -> '.$options['type']);
if($options['type']=='array') if($options['type']=='array')
$GLOBALS['redis']->hset($this->dbTable.':'.$this->id,$field,json_encode($this->data[$field])); $GLOBALS['redis']->hset($this->dbTable.':'.$this->id,$field,json_encode($this->data[$field]));
else else
{ {
error_log("hset $this->dbTable:$this->id $field {$this->data[$field]}");
$GLOBALS['redis']->hset($this->dbTable.':'.$this->id,$field,$this->data[$field]); $GLOBALS['redis']->hset($this->dbTable.':'.$this->id,$field,$this->data[$field]);
} }
} }
@ -85,7 +82,7 @@ class Model {
{ {
$this->id = $id; $this->id = $id;
if(!$GLOBALS['redis']->exists($this->dbTable.':'.$this->id)) if(!$GLOBALS['redis']->exists($this->dbTable.':'.$this->id))
return false; throw new Exception($this->dbTable.':'.$this->id.' not found');
$keys = array_keys($this->dbFields); $keys = array_keys($this->dbFields);
foreach($keys as $key) foreach($keys as $key)

View File

@ -9,8 +9,8 @@ class Dog extends Model {
'kennel_name' => ['type'=>'text'], 'kennel_name' => ['type'=>'text'],
'breed' => ['type'=>'text'], 'breed' => ['type'=>'text'],
'size' => ['type'=>'text'], //in cm 'size' => ['type'=>'text'], //in cm
'birthday' => ['type'=>'int'], //unix timestamp 'birthday' => ['type'=>'text'],
'agility_size' => ['type'=>'int'], //S,M,I,L 'agility_size' => ['type'=>'text'], //S,M,I,L
'active' => ['type'=>'int','default'=>1] 'active' => ['type'=>'int','default'=>1]
); );

View File

@ -19,14 +19,18 @@ class Dogs extends Page {
$dogs = $_SESSION['user']->data['dogs']; $dogs = $_SESSION['user']->data['dogs'];
$doggos = []; $doggos = [];
foreach($dogs as $dogid) foreach($dogs as $key => $dogid)
{ {
//var_dump($dogid);
$dog = new Dog(); $dog = new Dog();
try{ try{
$dog->load($dogid); $dog->load($dogid);
} }
catch(Exception $e) catch(Exception $e)
{ {
error_log("Dog $dogid not found. Deleting from user");
unset($_SESSION['user']->data['dogs'][$key]);
$_SESSION['user']->save();
continue; continue;
} }
if($dog->data) if($dog->data)

View File

@ -1,48 +1,43 @@
<h1 class="text-2xl p-6 text-center">Meine Hunde</h1> <h1 class="text-2xl p-6 text-center">Meine Hunde</h1>
<div class="container flex justify-center mx-auto">
<div class="flex flex-col">
<div class="w-full">
<div class="border-b border-gray-200 shadow">
<table class="divide-y divide-gray-300 ">
<thead class="bg-gray-50">
<tr>
<?php foreach (array_keys($doggos[0]) as $key) : ?>
<th class="px-6 py-2 text-xs text-gray-500">
<?= $key ?>
</th>
<?php endforeach; ?>
<th class="px-6 py-2 text-xs text-gray-500"> <div class="border-b border-gray-200 shadow overflow-x">
Bearbeiten <table class="divide-y divide-gray-300 table-auto overflow-scroll w-ful">
</th> <thead class="bg-gray-50">
<th class="px-6 py-2 text-xs text-gray-500"> <tr>
Löschen <?php foreach (array_keys($doggos[0]) as $key) : ?>
</th> <th class="px-6 py-2 text-xs text-gray-500">
</tr> <?= $key ?>
</thead> </th>
<tbody class="bg-white divide-y divide-gray-300"> <?php endforeach; ?>
<?php foreach ($doggos as $dog) : ?>
<tr class="whitespace-nowrap"> <th class="px-6 py-2 text-xs text-gray-500">
<?php foreach (array_keys($dog) as $key) : ?> Bearbeiten
<td class="px-6 py-4 text-sm text-gray-500"> </th>
<?= $dog[$key] ?> <th class="px-6 py-2 text-xs text-gray-500">
</td> Löschen
<?php endforeach; ?> </th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-300">
<?php foreach ($doggos as $dog) : ?>
<td class="px-6 py-4"> <tr class="whitespace-nowrap">
<button hx-get="/dogs/edit/<?= $dog['id'] ?>" hx-push-url="/dogs/edit/<?= $dog['id'] ?>" hx-target="#main" class="px-4 py-1 text-sm text-indigo-600 bg-indigo-200 rounded-full">Bearbeiten</button> <?php foreach (array_keys($dog) as $key) : ?>
</td> <td class="px-6 py-4 text-sm text-gray-500">
<td class="px-6 py-4"> <?= $dog[$key] ?>
<button hx-get="/dogs/delete/<?= $dog['id'] ?>" hx-target="#main" class="px-4 py-1 text-sm text-red-400 bg-red-200 rounded-full">Löschen</button> </td>
</td> <?php endforeach; ?>
</tr>
<?php endforeach; ?> <td class="px-6 py-4">
</tbody> <button hx-get="/dogs/edit/<?= $dog['id'] ?>" hx-push-url="/dogs/edit/<?= $dog['id'] ?>" hx-target="#main" class="px-4 py-1 text-sm text-indigo-600 bg-indigo-200 rounded-full">Bearbeiten</button>
</table> </td>
</div> <td class="px-6 py-4">
</div> <button hx-get="/dogs/delete/<?= $dog['id'] ?>" hx-target="#main" class="px-4 py-1 text-sm text-red-400 bg-red-200 rounded-full">Löschen</button>
</div> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div> </div>

View File

@ -20,7 +20,7 @@
<div class="flex flex-col"> <div class="flex flex-col">
<div class="w-full"> <div class="w-full">
<div class="border-b border-gray-200 shadow"> <div class="border-b border-gray-200 shadow">
<table class="divide-y divide-gray-300 "> <table class="divide-y divide-gray-300 table-auto overflow-x-scroll w-full">
<thead class="bg-gray-50"> <thead class="bg-gray-50">
<tr> <tr>
<?php foreach (array_keys($userdata[0]) as $key) : ?> <?php foreach (array_keys($userdata[0]) as $key) : ?>