loaing of model via arbitrary field and nice home page
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
All checks were successful
Build and push / Pulling repo on server (push) Successful in 3s
This commit is contained in:
parent
fea847afd2
commit
4516486b8e
@ -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;
|
||||
}
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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');
|
||||
|
@ -16,6 +16,53 @@
|
||||
</div>
|
||||
|
||||
<h1>Admin stuff</h1>
|
||||
|
||||
<div class="container text-center">
|
||||
<div class="row">
|
||||
<?php foreach ($userdata as $user) : ?>
|
||||
<div class="m-3 col">
|
||||
<div class="card">
|
||||
<img src="<?= $user['photo']?:'https://pictshare.net/pj7vzx.jpg' ?>" class="card-img-top" alt="...">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title"><?= escape($user['firstname'].' '.$user['lastname']) ?></h5>
|
||||
<p class="card-text"><?= escape($user['email']) ?></p>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item">
|
||||
<h6>uuid</h6>
|
||||
<span class="badge rounded-pill text-bg-secondary"><?= escape($user['uuid']); ?></span>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<h6>Registered</h6>
|
||||
<?= escape($user['registered']); ?>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<h6>last_login</h6>
|
||||
<?= escape($user['last_login']); ?>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<h6>Active</h6>
|
||||
<?= $user['active']?'yes':'no'; ?>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<h6>Dogs</h6>
|
||||
<?php foreach($user['dogs'] as $dog): ?>
|
||||
<a href="/dogs/<?= $dog ?>" class="btn btn-secondary"><?= escape((new Dog())->getField('name',$dog)); ?></a>
|
||||
<?php endforeach; ?>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="card-body">
|
||||
<button class="btn btn-primary" name="email" value="<?= $user['email'] ?>" hx-post="/admin/loginas/">Login</button>
|
||||
<button class="btn btn-primary"name="email" value="<?= $user['email'] ?>" hx-post="/admin/edituser/" hx-target="#main">Edit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!--
|
||||
<figure class="table-responsive">
|
||||
<table class="table" role="grid">
|
||||
<thead>
|
||||
@ -58,4 +105,4 @@
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</figure>
|
||||
</figure> -->
|
Reference in New Issue
Block a user