From 9213ad239c7510a329c215e94e03d7fb0fae731f Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 3 Mar 2018 14:03:27 +0100 Subject: [PATCH] Created delete_notifications_friendship_request function --- helpers/notifications.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/helpers/notifications.php b/helpers/notifications.php index 467620f..58e9473 100644 --- a/helpers/notifications.php +++ b/helpers/notifications.php @@ -22,4 +22,37 @@ function delete_user_notifications_over_post(int $userID, int $postID) : bool { $notification->set_dest_user_id($userID); return components()->notifications->delete($notification); +} + +/** + * Delete all the notifications related to a friendship request between two + * users + * + * @param int $userOne The first user + * @param int $userTwo The second user + * @return bool TRUE for a success / FALSE else + */ +function delete_notifications_friendship_request(int $userOne, int $userTwo) : bool { + + user_login_required(); + + //Create notification object + $notification = new Notification(); + $notification->set_on_elem_type(Notification::FRIENDSHIP_REQUEST); + $notification->set_on_elem_id(0); + + //Delete notifications in the two ways + $notification->set_dest_user_id($userOne); + $notification->set_from_user_id($userTwo); + $notification->set_on_elem_id(0); + if(!components()->notifications->delete($notification)) + return false; + + $notification->set_dest_user_id($userTwo); + $notification->set_from_user_id($userOne); + $notification->set_on_elem_id(0); + if(!components()->notifications->delete($notification)) + return false; + + return true; } \ No newline at end of file