diff --git a/web/inc/classes/Model.class.php b/web/inc/classes/Model.class.php index 330e0af..0ae19be 100644 --- a/web/inc/classes/Model.class.php +++ b/web/inc/classes/Model.class.php @@ -199,6 +199,11 @@ class Model { return true; } + function exists($id) + { + return $GLOBALS['redis']->exists($this->dbTable.':'.$id); + } + function delete() { return $GLOBALS['redis']->del($this->dbTable.':'.$this->id); diff --git a/web/models/Dog.model.php b/web/models/Dog.model.php index 96a0afe..4f12981 100644 --- a/web/models/Dog.model.php +++ b/web/models/Dog.model.php @@ -1,17 +1,31 @@ - ['type'=>'text','required','unique','autoValMethod'=>'gen_ulid'], - 'registered' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'], - 'name' => ['type'=>'text'], - 'kennel_name' => ['type'=>'text'], - 'breed' => ['type'=>'text'], - 'size' => ['type'=>'text'], //in cm - 'birthday' => ['type'=>'text'], - 'agility_size' => ['type'=>'text'], //S,M,I,L - 'active' => ['type'=>'int','default'=>1] + protected $dbFields = array( + 'uuid' => ['type' => 'text', 'required', 'unique', 'autoValMethod' => 'gen_ulid'], + 'registered' => ['type' => 'datetime', 'required', 'unique', 'autoValMethod' => 'getDateTime'], + 'name' => ['type' => 'text'], + 'kennel_name' => ['type' => 'text'], + 'breed' => ['type' => 'text'], + 'size' => ['type' => 'text'], //in cm + 'birthday' => ['type' => 'text'], + 'agility_size' => ['type' => 'text'], //S,M,I,L + 'active' => ['type' => 'int', 'default' => 1] ); - -} \ No newline at end of file + + function isMyDog($dog = false) + { + if ($dog == false) + $dog = $this->id; + + if (!$this->exists($dog)) + return false; + else { + if (in_array($dog, $_SESSION['user']->data['dogs'])) + return true; + else return false; + } + } +} diff --git a/web/models/User.model.php b/web/models/User.model.php index 8804efa..f90bab9 100644 --- a/web/models/User.model.php +++ b/web/models/User.model.php @@ -33,11 +33,6 @@ class User extends Model { unset($_SESSION['user']); } - function exists($id) - { - return $this->redis->exists($this->dbTable.':'.$id); - } - function getAll($filtered = true) { $keys = $this->redis->keys($this->dbTable.':*'); diff --git a/web/pages/dogs/controller.php b/web/pages/dogs/controller.php index 80adc60..4f2476c 100644 --- a/web/pages/dogs/controller.php +++ b/web/pages/dogs/controller.php @@ -13,6 +13,17 @@ class Dogs extends Page { { $this->addSubmenuItem('Hunde anzeigen','/dogs','far fa-list-alt'); $this->addSubmenuItem('Hund hinzufügen','/dogs/add','fas fa-plus-circle'); + if($_SESSION['user']->data['dogs'] && count($_SESSION['user']->data['dogs']) > 0) + { + $this->addSubmenuItem('divider',''); + foreach($_SESSION['user']->data['dogs'] as $dogid) + { + $dog = new Dog(); + $dog->load($dogid); + $this->addSubmenuItem($dog->data['name'],'/dogs/overview/'.$dogid,'fas fa-dog'); + } + } + } function index() { @@ -142,6 +153,16 @@ class Dogs extends Page { } } + function overview() + { + $dogid = $this->params[0]; + $d = new Dog(); + + if(!$d->isMyDog($dogid)) + return 'Not your dog :('; + return 'hier wird der hund angezeigt'; + } + function maySeeThisPage() { if($_SESSION['user']) //wenn eingeloggt, kein problem return true; diff --git a/web/templates/menu.html b/web/templates/menu.html index bb15fc4..2206c64 100644 --- a/web/templates/menu.html +++ b/web/templates/menu.html @@ -20,15 +20,19 @@