add Anon user object

This commit is contained in:
Thomas Rubini 2023-01-26 19:49:30 +01:00
parent cf7d337c9d
commit 1e80101833
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
3 changed files with 42 additions and 11 deletions

View File

@ -53,6 +53,15 @@ final class ApprModel {
$stmt->bindParam("id", $this->I_ID);
$stmt->execute();
}
public function getAuthorOrAnon(){
$O_author = self::getAuthor();
if ($O_author === null) {
return UserModel::getAnonUser();
} else {
return $O_author;
}
}
public function getAuthor(){
if($this->O_AUTHOR === null){

View File

@ -2,6 +2,8 @@
final class UserModel extends UserSessionModel
{
private static $O_ANONUSER = null;
public $I_ID = null;
public $S_EMAIL = null;
public $S_USERNAME= null;
@ -11,16 +13,36 @@ final class UserModel extends UserSessionModel
public $B_ADMIN = 0;
public $B_DISABLED = 0;
public function __construct($S_EMAIL, $S_USERNAME,$S_PASSWORD_HASH,$S_LAST_SEEN,$S_FIRST_SEEN,$B_ADMIN,$B_DISABLED)
private function __construct(){}
public static function createFull($S_EMAIL, $S_USERNAME,$S_PASSWORD_HASH,$S_LAST_SEEN,$S_FIRST_SEEN,$B_ADMIN,$B_DISABLED)
{
$this->S_EMAIL = $S_EMAIL;
$this->S_USERNAME = $S_USERNAME;
$this->S_PASSWORD_HASH = $S_PASSWORD_HASH;
$this->S_LAST_SEEN = $S_LAST_SEEN;
$this->S_FIRST_SEEN = $S_FIRST_SEEN;
$this->B_ADMIN = $B_ADMIN;
$this->B_DISABLED = $B_DISABLED;
$O_user = new UserModel();
$O_user->S_EMAIL = $S_EMAIL;
$O_user->S_USERNAME = $S_USERNAME;
$O_user->S_PASSWORD_HASH = $S_PASSWORD_HASH;
$O_user->S_LAST_SEEN = $S_LAST_SEEN;
$O_user->S_FIRST_SEEN = $S_FIRST_SEEN;
$O_user->B_ADMIN = $B_ADMIN;
$O_user->B_DISABLED = $B_DISABLED;
return $O_user;
}
public static function createEmpty(){
$O_user = new UserModel();
}
public static function getAnonUser(){
if(self::$O_ANONUSER === null) {
self::$O_ANONUSER = new UserModel();
self::$O_ANONUSER->I_ID = 0;
self::$O_ANONUSER->S_EMAIL = "anonymous_user@example.fr";
self::$O_ANONUSER->S_USERNAME = "Anonymous user";
}
return self::$O_ANONUSER;
}
public function insert(){
$O_model = Model::get();
$stmt = $O_model->prepare("INSERT INTO USER (EMAIL, USERNAME, PASS_HASH, FIRST_SEEN) VALUES(:email, :username, :password_hash, :first_seen)");
@ -67,7 +89,7 @@ final class UserModel extends UserSessionModel
}
private static function createFromRow($A_row, $I_ID){
$O_user = new UserModel($A_row["EMAIL"],$A_row["USERNAME"],$A_row["PASS_HASH"],$A_row["LAST_SEEN"],$A_row["FIRST_SEEN"],$A_row["ADMIN"],$A_row["DISABLED"]);
$O_user = UserModel::createFull($A_row["EMAIL"],$A_row["USERNAME"],$A_row["PASS_HASH"],$A_row["LAST_SEEN"],$A_row["FIRST_SEEN"],$A_row["ADMIN"],$A_row["DISABLED"]);
$O_user->I_ID = $I_ID;
return $O_user;
}

View File

@ -4,8 +4,8 @@
<section>
<header>
<img src="<?= $O_appr->getAuthor()->getProfilePicLink() ?>" alt="profile picture">
<h3> <?= $O_appr->getAuthor()->S_USERNAME ?> </h3>
<img src="<?= $O_appr->getAuthorOrAnon()->getProfilePicLink() ?>" alt="profile picture">
<h3> <?= $O_appr->getAuthorOrAnon()->S_USERNAME ?> </h3>
<p>Le <?= $O_appr->S_DATE ?> </p>
<p> <?= $O_appr->I_NOTE ?>/5 </p>
<?php if ($A_view["ADMIN"] || $A_view["USER_ID"] === $O_appr->I_AUTHOR_ID) { ?>