From 04d3fdb2066518a58a6d91ad93f0d2e43479f9a0 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Thu, 26 Jan 2023 19:57:55 +0100 Subject: [PATCH] use Anon user in Recipe --- Models/RecipeModel.php | 9 +++++++++ Views/recipe/view.php | 9 +-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php index 07c63e4..ffdc71e 100644 --- a/Models/RecipeModel.php +++ b/Models/RecipeModel.php @@ -119,6 +119,15 @@ final class RecipeModel return round($avg*2)/2; } + + 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){ diff --git a/Views/recipe/view.php b/Views/recipe/view.php index d95c2b4..1229232 100644 --- a/Views/recipe/view.php +++ b/Views/recipe/view.php @@ -35,14 +35,7 @@ $O_recipe = $A_view["RECIPE"]; - getAuthor(); - if($O_author === null) { - echo '
By an anonymous user
'; - } else { - echo 'By '.$O_author->S_USERNAME.'
'; - } - ?> +By = $O_recipe->getAuthorOrAnon()->S_USERNAME ?>