Sindbad~EG File Manager
<?php
/**
* Notification Class
* Handles system notifications
*/
class Notification {
private $db;
public function __construct() {
$this->db = Database::getInstance()->getConnection();
}
/**
* Create a notification
*/
public function create($userId, $type, $title, $message, $link = null) {
try {
$stmt = $this->db->prepare("
INSERT INTO notifications (user_id, notification_type, title, message, link)
VALUES (:user_id, :type, :title, :message, :link)
");
$stmt->execute([
'user_id' => $userId,
'type' => $type,
'title' => $title,
'message' => $message,
'link' => $link
]);
return true;
} catch (PDOException $e) {
return false;
}
}
/**
* Get user notifications
*/
public function getUserNotifications($userId, $unreadOnly = false, $limit = 50) {
try {
$sql = "SELECT * FROM notifications WHERE user_id = :user_id";
if ($unreadOnly) {
$sql .= " AND is_read = 0";
}
$sql .= " ORDER BY created_at DESC LIMIT :limit";
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':user_id', $userId, PDO::PARAM_INT);
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll();
} catch (PDOException $e) {
return [];
}
}
/**
* Mark notification as read
*/
public function markAsRead($notificationId, $userId) {
try {
$stmt = $this->db->prepare("
UPDATE notifications
SET is_read = 1
WHERE id = :id AND user_id = :user_id
");
$stmt->execute([
'id' => $notificationId,
'user_id' => $userId
]);
return true;
} catch (PDOException $e) {
return false;
}
}
/**
* Mark all notifications as read
*/
public function markAllAsRead($userId) {
try {
$stmt = $this->db->prepare("
UPDATE notifications
SET is_read = 1
WHERE user_id = :user_id AND is_read = 0
");
$stmt->execute(['user_id' => $userId]);
return true;
} catch (PDOException $e) {
return false;
}
}
/**
* Get unread count
*/
public function getUnreadCount($userId) {
try {
$stmt = $this->db->prepare("
SELECT COUNT(*) as count
FROM notifications
WHERE user_id = :user_id AND is_read = 0
");
$stmt->execute(['user_id' => $userId]);
$result = $stmt->fetch();
return $result['count'];
} catch (PDOException $e) {
return 0;
}
}
/**
* Delete notification
*/
public function delete($notificationId, $userId) {
try {
$stmt = $this->db->prepare("
DELETE FROM notifications
WHERE id = :id AND user_id = :user_id
");
$stmt->execute([
'id' => $notificationId,
'user_id' => $userId
]);
return true;
} catch (PDOException $e) {
return false;
}
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists