mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 18:42:00 -04:00
Update PropertiesBase to new patterns and improve static analysis checks
This commit is contained in:
parent
5f0b57f7e9
commit
6c8414f844
33 changed files with 335 additions and 148 deletions
55
lib/User.php
55
lib/User.php
|
@ -5,35 +5,16 @@ use Safe\DateTime;
|
|||
class User extends PropertiesBase{
|
||||
public $UserId;
|
||||
public $FirstName;
|
||||
protected $DisplayFirstName = null;
|
||||
public $LastName;
|
||||
protected $DisplayLastName = null;
|
||||
protected $Name = null;
|
||||
protected $DisplayName = null;
|
||||
public $Email;
|
||||
protected $DisplayEmail;
|
||||
public $Created;
|
||||
public $Uuid;
|
||||
|
||||
public static function Get(?int $userId): User{
|
||||
$result = Db::Query('SELECT * from Users where UserId = ?', [$userId], 'User');
|
||||
|
||||
if(sizeof($result) == 0){
|
||||
throw new Exceptions\InvalidUserException();
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public static function GetByEmail(?string $email): User{
|
||||
$result = Db::Query('SELECT * from Users where Email = ?', [$email], 'User');
|
||||
|
||||
if(sizeof($result) == 0){
|
||||
throw new Exceptions\InvalidUserException();
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
// *******
|
||||
// GETTERS
|
||||
// *******
|
||||
|
||||
protected function GetName(): string{
|
||||
if($this->Name === null){
|
||||
|
@ -43,6 +24,11 @@ class User extends PropertiesBase{
|
|||
return $this->Name;
|
||||
}
|
||||
|
||||
|
||||
// *******
|
||||
// METHODS
|
||||
// *******
|
||||
|
||||
public function Create(): void{
|
||||
$uuid = Uuid::uuid4();
|
||||
$this->Uuid = $uuid->toString();
|
||||
|
@ -63,4 +49,29 @@ class User extends PropertiesBase{
|
|||
|
||||
$this->UserId = Db::GetLastInsertedId();
|
||||
}
|
||||
|
||||
|
||||
// ***********
|
||||
// ORM METHODS
|
||||
// ***********
|
||||
|
||||
public static function Get(?int $userId): User{
|
||||
$result = Db::Query('SELECT * from Users where UserId = ?', [$userId], 'User');
|
||||
|
||||
if(sizeof($result) == 0){
|
||||
throw new Exceptions\InvalidUserException();
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public static function GetByEmail(?string $email): User{
|
||||
$result = Db::Query('SELECT * from Users where Email = ?', [$email], 'User');
|
||||
|
||||
if(sizeof($result) == 0){
|
||||
throw new Exceptions\InvalidUserException();
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue