diff --git a/web/css/dogstats.css b/web/css/dogstats.css index 973a377..1b2734d 100644 --- a/web/css/dogstats.css +++ b/web/css/dogstats.css @@ -52,4 +52,33 @@ main>.container { .tooltipp:hover:after { opacity: 1; +} + +/* XDEBUG */ +.xdebug-error th +{ + font-family:monospace; + font-weight:normal; + font-size:15px; + padding: 6px 6px 6px 6px; + border:1px solid black; + background: #FFCC99; + color:#000000; +} +.xdebug-error > tr:first-child > th:first-child, +.xdebug-error > tbody > tr:first-child > th:first-child +{ + line-height:1.6em; + padding: 10px 10px 10px 10px; + border:1px solid #000000; + background: #000000; + color:#FFFFFF; +} +.xdebug-error td +{ + font-size:14px; + padding: 6px 6px 6px 6px; + border:1px solid green; + background: #D1FFE8; + color:#000000; } \ No newline at end of file diff --git a/web/inc/classes/Model.class.php b/web/inc/classes/Model.class.php index 432f27f..41041b8 100644 --- a/web/inc/classes/Model.class.php +++ b/web/inc/classes/Model.class.php @@ -9,7 +9,7 @@ class Model { { //redis if ($GLOBALS['redis']) - $this->redis = $GLOBALS['redis']; + $GLOBALS['redis'] = $GLOBALS['redis']; } /** @@ -55,6 +55,13 @@ class Model { return $data; } + public function getField($field,$id=false) + { + if(!$id) + $id = $this->id; + return $GLOBALS['redis']->hget($this->dbTable.':'.$id,$field); + } + public function save() { $newgen = false; @@ -84,9 +91,31 @@ class Model { return $this->id; } - public function load($id) + /** + * @param $value The value to search for + * @param string $field The field to search in. HAS to be marked as unique otherwise will throw error + */ + public function load($value,$field='id') { - $this->id = $id; + if($field!='id') + { + //sanity check. Check if $field is marked as unique + if(!in_array('unique',$this->dbFields[$field])) + throw new Exception($field.' is not unique'); + //we need to find the id first + $keys = $GLOBALS['redis']->keys($this->dbTable.':*'); + foreach($keys as $key){ + $id = end(explode(':',$key)); + $thisval = $GLOBALS['redis']->hget($this->dbTable.':'.$id,$field); + if($thisval==$value) + { + $this->id = $id; + break; + } + } + } + else + $this->id = $value; if(!$GLOBALS['redis']->exists($this->dbTable.':'.$this->id)) throw new Exception($this->dbTable.':'.$this->id.' not found'); $keys = array_keys($this->dbFields); @@ -95,7 +124,7 @@ class Model { { $value = $GLOBALS['redis']->hget($this->dbTable.':'.$this->id,$key); - if($value!==NULL) //we'll leave null values + if($value!==NULL) //we'll leave null values alone switch($this->dbFields[$key]['type']) { case 'int': $value = intval($value);break; diff --git a/web/models/User.model.php b/web/models/User.model.php index 792436b..59d3d6a 100644 --- a/web/models/User.model.php +++ b/web/models/User.model.php @@ -5,7 +5,7 @@ class User extends Model { protected $dbFields = Array ( 'uuid' => ['type'=>'text','required','unique','autoValMethod'=>'gen_ulid'], 'password' => ['type'=>'text'], - 'registered' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'], + 'registered' => ['type'=>'datetime','required','autoValMethod'=>'getDateTime'], 'email' => ['type'=>'email','unique'], 'firstname' => ['type'=>'text'], 'lastname' => ['type'=>'text'], @@ -14,6 +14,7 @@ class User extends Model { 'timezone' => ['type'=>'int'], 'dogs' => ['type'=> 'array','default'=>[]], 'tournaments' => ['type'=> 'array','default'=>[]], + 'photo' => ['type'=>'text','default'=>'https://pictshare.net/pj7vzx.jpg'], 'active' => ['type'=>'int','default'=>0] ); protected $hidden = ['password','token']; @@ -46,7 +47,7 @@ class User extends Model { function getAll($filtered = true) { - $keys = $this->redis->keys($this->dbTable.':*'); + $keys = $GLOBALS['redis']->keys($this->dbTable.':*'); $users = []; foreach($keys as $key) { diff --git a/web/pages/demo/controller.php b/web/pages/demo/controller.php index ef351ec..5a2c221 100644 --- a/web/pages/demo/controller.php +++ b/web/pages/demo/controller.php @@ -15,6 +15,13 @@ class Demo extends Page{ //$this->addSubmenuItem('Hund hinzufügen','/dogs/add','fas fa-plus-circle'); } + function test() + { + $u = new User(); + $u->load('Chris','firstname'); + var_dump($u->data); + } + function index() { $this->set('successTitle','Erfolgreich'); diff --git a/web/pages/home/home.html b/web/pages/home/home.html index 3318a72..8db1cc8 100644 --- a/web/pages/home/home.html +++ b/web/pages/home/home.html @@ -16,6 +16,53 @@
= escape($user['email']) ?>
+