From ba9b1439b5d18666f8419d41552010c4ab546163 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Mon, 23 Jan 2023 20:42:44 +0100 Subject: [PATCH 1/2] handle cases where user doesn't exit/doesn't have a profile pic --- Controllers/UserController.php | 12 ++++++++++-- static/img/{users/1.jpg => generic_user.jpg} | Bin 2 files changed, 10 insertions(+), 2 deletions(-) rename static/img/{users/1.jpg => generic_user.jpg} (100%) diff --git a/Controllers/UserController.php b/Controllers/UserController.php index cb34160..8a08beb 100644 --- a/Controllers/UserController.php +++ b/Controllers/UserController.php @@ -188,9 +188,17 @@ final class UserController $O_userModel = new UserModel(); $A_user = $O_userModel->getUserByID($A_urlParams[0]); - header("Content-Type: image/png"); + if (!isset($A_user)) { + die(); + } + + header("Content-Type: image/png"); + if ($A_user["PROFILE_PIC"] === null) { + echo file_get_contents(Constants::rootDir()."/static/img/generic_user.jpg"); + } else { + echo $A_user["PROFILE_PIC"]; + } - echo $A_user["PROFILE_PIC"]; return Utils::RETURN_RAW; } diff --git a/static/img/users/1.jpg b/static/img/generic_user.jpg similarity index 100% rename from static/img/users/1.jpg rename to static/img/generic_user.jpg From ce6cb0e3a3732a06e3598cea304bacd3e2aa9389 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Mon, 23 Jan 2023 22:37:12 +0100 Subject: [PATCH 2/2] show users profile picture instead of a generic image in apprs --- Models/ApprModel.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Models/ApprModel.php b/Models/ApprModel.php index 73901b4..6f49f9a 100644 --- a/Models/ApprModel.php +++ b/Models/ApprModel.php @@ -6,7 +6,9 @@ final class ApprModel { { $O_model = Model::get(); $stmt = $O_model->prepare(" - SELECT APPRECIATION.*, USER.USERNAME as AUTHOR_NAME FROM APPRECIATION + SELECT APPRECIATION.*, USER.USERNAME as AUTHOR_NAME, + CONCAT('/user/profilePic/', APPRECIATION.AUTHOR_ID) AS AUTHOR_IMG_LINK + FROM APPRECIATION JOIN USER ON USER.ID = APPRECIATION.AUTHOR_ID WHERE RECIPE_ID = :recipe_id "); @@ -15,10 +17,6 @@ final class ApprModel { $rows = $stmt->fetchAll(); - foreach($rows as &$row) { - $row["AUTHOR_IMG_LINK"] = "/static/img/users/1.jpg"; - } - return $rows; }