2023-10-22 01:46:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class User extends Model {
|
|
|
|
protected $dbTable = "users";
|
|
|
|
protected $dbFields = Array (
|
|
|
|
'password' => ['type'=>'text'],
|
|
|
|
'registered' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'],
|
|
|
|
'email' => ['type'=>'email','unique'],
|
|
|
|
'firstname' => ['type'=>'text'],
|
|
|
|
'lastname' => ['type'=>'text'],
|
|
|
|
'last_login' => ['type'=>'datetime','required','unique','autoValMethod'=>'getDateTime'],
|
|
|
|
'token' => ['type'=>'text','required','unique','autoValMethod'=>'uuid4'],
|
|
|
|
'timezone' => ['type'=>'int'],
|
2023-10-22 23:05:24 +02:00
|
|
|
'dogs' => ['type'=> 'array','default'=>[]],
|
2023-10-26 20:26:28 +02:00
|
|
|
'tournaments' => ['type'=> 'array','default'=>[]],
|
2023-10-22 01:46:22 +02:00
|
|
|
'active' => ['type'=>'int','default'=>0]
|
|
|
|
);
|
|
|
|
protected $hidden = ['password','token'];
|
|
|
|
|
|
|
|
function login()
|
|
|
|
{
|
|
|
|
if(!$this->id) return false;
|
|
|
|
$this->last_login = $this->getDateTime();
|
|
|
|
$this->save();
|
|
|
|
|
|
|
|
$_SESSION['user'] = $this;
|
|
|
|
$_SESSION['userid'] = $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function logout()
|
|
|
|
{
|
|
|
|
if(!$this->id) return false;
|
|
|
|
unset($_SESSION['user']);
|
|
|
|
}
|
|
|
|
|
2023-10-26 17:50:54 +02:00
|
|
|
function removeDog($dogid)
|
|
|
|
{
|
|
|
|
if(!$this->id) return false;
|
|
|
|
if (in_array($dogid, $this->data['dogs']))
|
|
|
|
{
|
|
|
|
$this->data['dogs'] = array_diff($this->data['dogs'],[$dogid]);
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-22 01:46:22 +02:00
|
|
|
function getAll($filtered = true)
|
|
|
|
{
|
|
|
|
$keys = $this->redis->keys($this->dbTable.':*');
|
|
|
|
$users = [];
|
|
|
|
foreach($keys as $key)
|
|
|
|
{
|
|
|
|
$id = end(explode(':',$key));
|
|
|
|
$u = new User();
|
|
|
|
$u->load($id);
|
|
|
|
if($filtered===true)
|
|
|
|
$users[] = $u->getDataFiltered();
|
|
|
|
else
|
|
|
|
$users[] = $u->data;
|
|
|
|
}
|
|
|
|
return $users;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|