Diff #4 - trunk/src/Admin.php
2,219 bytes
|
|
January 20, 2025 at 08:20
|
Diff
Index: Admin.php
--- Admin.php (nonexistent) +++ Admin.php (revision 4) @@ -0,0 +1,113 @@ +<?php +declare(strict_types = 1); + + +namespace App\Webapp; + +use Apex\Svc{Db, Di}; +use Apex\Armor\User\ArmorUser; +use Apex\App\Interfaces\UserInterface; + +/** + * Admin user + */ +class Admin extends ArmorUser implements UserInterface +{ + + /** + * Constructor + */ + public function __construct( + protected string $full_name, + protected string $language, + protected string $timezone + ) { + + } + + /** + * Get name + */ + public function getFullName():string + { + return $this->full_name; + } + + /** + * Get language + */ + public function getLanguage():string + { + return $this->language; + } + + /** + * Get timezone + */ + public function getTimezone():string + { + return $this->timezone; + } + + /** + * Load by uuid + */ + public static function loadUuid(string $uuid, bool $is_deleted = false):?static + { + + // Get from db + $db = Di::get(Db::class); + if (!$user = $db->getObject(Admin::class, "SELECT * FROM admin, armor_users WHERE armor_users.uuid = %s AND admin.uuid = armor_users.uuid AND armor_users.is_deleted = %b", $uuid, $is_deleted)) { + return null; + } + + // Return + return $user; + } + + /** + * Load by username + */ + public static function loadUsername(string $username, bool $is_deleted = false):?static + { + + // Get from db + $db = Di::get(Db::class); + if (!$user = $db->getObject(Admin::class, "SELECT * FROM admin, armor_users WHERE armor_users.username = %s AND admin.uuid = armor_users.uuid AND armor_users.is_deleted = %b", $username, $is_deleted)) { + return null; + } + + // Return + return $user; + } + + /** + * Get currency + */ + public function getCurrency():string + { + return 'USD'; + } + + /** + * toDisplayArray + */ + public function toDisplayArray():array + { + + // Get vars + $vars = $this->toArray(); + + // Add vars + $vars['full_name'] = $this->full_name; + $vars['language'] = $this->language; + $vars['timezone'] = $this->timezone; + + + // return + return $vars; + } + + +} +
Full Code
<?php declare(strict_types = 1);
namespace App\Webapp;
use Apex\Svc{Db, Di}; use Apex\Armor\User\ArmorUser; use Apex\App\Interfaces\UserInterface;
/** * Admin user */ class Admin extends ArmorUser implements UserInterface {
/**
* Constructor
*/
public function __construct(
protected string $full_name,
protected string $language,
protected string $timezone
) {
}
/**
* Get name
*/
public function getFullName():string
{
return $this->full_name;
}
/**
* Get language
*/
public function getLanguage():string
{
return $this->language;
}
/**
* Get timezone
*/
public function getTimezone():string
{
return $this->timezone;
}
/**
* Load by uuid
*/
public static function loadUuid(string $uuid, bool $is_deleted = false):?static
{
// Get from db
$db = Di::get(Db::class);
if (!$user = $db->getObject(Admin::class, "SELECT * FROM admin, armor_users WHERE armor_users.uuid = %s AND admin.uuid = armor_users.uuid AND armor_users.is_deleted = %b", $uuid, $is_deleted)) {
return null;
}
// Return
return $user;
}
/**
* Load by username
*/
public static function loadUsername(string $username, bool $is_deleted = false):?static
{
// Get from db
$db = Di::get(Db::class);
if (!$user = $db->getObject(Admin::class, "SELECT * FROM admin, armor_users WHERE armor_users.username = %s AND admin.uuid = armor_users.uuid AND armor_users.is_deleted = %b", $username, $is_deleted)) {
return null;
}
// Return
return $user;
}
/**
* Get currency
*/
public function getCurrency():string
{
return 'USD';
}
/**
* toDisplayArray
*/
public function toDisplayArray():array
{
// Get vars
$vars = $this->toArray();
// Add vars
$vars['full_name'] = $this->full_name;
$vars['language'] = $this->language;
$vars['timezone'] = $this->timezone;
// return
return $vars;
}
}