Can delete a notification.

This commit is contained in:
Pierre 2018-02-18 15:34:53 +01:00
parent 19516e3a5e
commit 87a19b02f9
2 changed files with 52 additions and 2 deletions

View File

@ -174,6 +174,37 @@ class notificationComponent {
return CS::get()->db->addLine(self::NOTIFICATIONS_TABLE, $values); return CS::get()->db->addLine(self::NOTIFICATIONS_TABLE, $values);
} }
/**
* Delete notifications
*
* @param Notification $notification The notification to delete
* @return bool TRUE for a success / FALSE else
*/
public function delete(Notification $notification) : bool {
//If the notification has an ID we delete a notification by its ID
if($notification->has_id()){
//Delete a notification by its ID
$conditions = "id = ?";
$values = array($notification->get_id());
}
//Delete the notification
else{
//Delete a specific notification
$data = $this->noticationToDB($notification, FALSE);
$array = CS::get()->db->splitConditionsArray($data);
$conditions = $array[0];
$values = $array[2];
}
//Delete the notification
return CS::get()->db->deleteEntry(self::NOTIFICATIONS_TABLE, $conditions, $values);
}
/** /**
* Convert a notification object into database array * Convert a notification object into database array
* *
@ -188,6 +219,7 @@ class notificationComponent {
$data['seen'] = $notification->is_seen() ? 1 : 0; $data['seen'] = $notification->is_seen() ? 1 : 0;
$data['from_user_id'] = $notification->get_from_user_id(); $data['from_user_id'] = $notification->get_from_user_id();
if($notification->has_dest_user_id())
$data['dest_user_id'] = $notification->get_dest_user_id(); $data['dest_user_id'] = $notification->get_dest_user_id();
$data['type'] = $notification->get_type(); $data['type'] = $notification->get_type();
$data['on_elem_id'] = $notification->get_on_elem_id(); $data['on_elem_id'] = $notification->get_on_elem_id();

View File

@ -75,7 +75,7 @@ class Notification {
} }
/** /**
* Get notification iD * Get notification ID
* *
* @return int The ID of the notification * @return int The ID of the notification
*/ */
@ -83,6 +83,15 @@ class Notification {
return $this->id; return $this->id;
} }
/**
* Check if the notification object has an ID or not
*
* @return bool TRUE if the notification as an ID / FALSE else
*/
public function has_id() : bool {
return $this->id != null;
}
/** /**
* Set notification creation time * Set notification creation time
* *
@ -156,6 +165,15 @@ class Notification {
return $this->dest_user_id; return $this->dest_user_id;
} }
/**
* Check if the notification has a destination user ID
*
* @return bool TRUE if the destination user ID was specified
*/
public function has_dest_user_id() : bool {
return $this->dest_user_id != null;
}
/** /**
* Set notification target element id * Set notification target element id
* *