use Waystone\Workspaces\Engines\Errors\ErrorHandling;
use Waystone\Workspaces\Engines\Workspaces\Workspace;
use Keruald\Database\DatabaseEngine;
-use UserGroup;
-
/**
* User class
*/
class User {
public ?int $id;
public $name;
public $password;
public $active = 0;
public $email;
public $regdate;
public array $session = [];
public string $lastError;
/**
* @var array|null An array of the workspaces the user has access to, each element an instance of the Workspace object. As long as the field hasn't been initialized by get_workspaces, null.
*/
private $workspaces = null;
private DatabaseEngine $db;
///
/// Constructors
///
public static function fromRow (array $row) : self {
$user = new self;
$user->load_from_row($row);
return $user;
}
/**
* Create a new user instance with arbitrary user_id
*
* The created user is not saved in the database.
*
* @param int $user_id A unassigned user ID
* @return self
*/
public static function create (int $user_id) : self {
$user = new self;
$user->id = $user_id;
$user->active = true;
$user->regdate = time();
return $user;
}
/**
* Creates a new anonymous user instance
*/
public static function anonymous () : User {
return User::create(ANONYMOUS_USER);
}
///
/// Load data
///
/**
* Loads the object User (ie fill the properties) from the $_POST array
*/
function load_from_form () {
if (array_key_exists('name', $_POST)) $this->name = $_POST['name'];
if (array_key_exists('password', $_POST)) $this->password = $_POST['password'];
if (array_key_exists('active', $_POST)) $this->active = $_POST['active'];
if (array_key_exists('actkey', $_POST)) $this->actkey = $_POST['actkey'];
if (array_key_exists('email', $_POST)) $this->email = $_POST['email'];
if (array_key_exists('regdate', $_POST)) $this->regdate = $_POST['regdate'];
}
/**
* Loads the object User (ie fill the properties) from the database row