From 6d1c5c3d2c68d91e7d90efef47d170a5f6e526da Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 20 Feb 2018 14:25:28 +0100 Subject: [PATCH] Improved noticationToDB --- classes/components/notifications.php | 8 ++++++-- classes/models/Notification.php | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/classes/components/notifications.php b/classes/components/notifications.php index 6bf6a15..325dd50 100644 --- a/classes/components/notifications.php +++ b/classes/components/notifications.php @@ -262,6 +262,8 @@ class notificationComponent { $data = array(); + if($notification->has_id()) + $data['id'] = $notification->get_id(); if($notification->has_seen_state()) $data['seen'] = $notification->is_seen() ? 1 : 0; if($notification->has_from_user_id()) @@ -270,8 +272,10 @@ class notificationComponent { $data['dest_user_id'] = $notification->get_dest_user_id(); if($notification->has_type()) $data['type'] = $notification->get_type(); - $data['on_elem_id'] = $notification->get_on_elem_id(); - $data['on_elem_type'] = $notification->get_on_elem_type(); + if($notification->has_on_elem_id()) + $data['on_elem_id'] = $notification->get_on_elem_id(); + if($notification->has_on_elem_type()) + $data['on_elem_type'] = $notification->get_on_elem_type(); //Specify complementary fields only if required if($full_entry){ diff --git a/classes/models/Notification.php b/classes/models/Notification.php index 7eb1e15..5fcd287 100644 --- a/classes/models/Notification.php +++ b/classes/models/Notification.php @@ -89,7 +89,7 @@ class Notification { * @return bool TRUE if the notification as an ID / FALSE else */ public function has_id() : bool { - return $this->id != null; + return ($this->id != null) && ($this->id != 0); } /** @@ -219,6 +219,16 @@ class Notification { return $this->on_elem_id; } + /** + * Check if the id of element targeted by the notification has been + * specified or not + * + * @return bool TRUE if the ID of the target element has been specified + */ + public function has_on_elem_id() : bool { + return $this->on_elem_id != null; + } + /** * Set notification target element type * @@ -237,6 +247,16 @@ class Notification { return $this->on_elem_type; } + /** + * Check if the type of element targeted by the notification has been + * specified or not + * + * @return bool TRUE if the ID of the target element has been specified + */ + public function has_on_elem_type() : bool { + return $this->on_elem_type != null; + } + /** * Set notification event type *