forked from imabutahersiddik/CodeStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotification_system.php
More file actions
49 lines (45 loc) · 1.28 KB
/
notification_system.php
File metadata and controls
49 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class NotificationSystem {
private $pdo;
private $userId;
private $currentTime;
public function __construct($pdo, $userId) {
$this->pdo = $pdo;
$this->userId = $userId;
$this->currentTime = '2025-06-14 12:47:29';
}
public function createNotification($type, $data) {
$stmt = $this->pdo->prepare("
INSERT INTO notifications
(user_id, type, data, created_at, is_read)
VALUES (?, ?, ?, ?, 0)
");
return $stmt->execute([
$this->userId,
$type,
json_encode($data),
$this->currentTime
]);
}
public function getUnreadNotifications() {
$stmt = $this->pdo->prepare("
SELECT * FROM notifications
WHERE user_id = ?
AND is_read = 0
ORDER BY created_at DESC
");
$stmt->execute([$this->userId]);
return $stmt->fetchAll();
}
public function markAsRead($notificationId) {
$stmt = $this->pdo->prepare("
UPDATE notifications
SET is_read = 1,
read_at = ?
WHERE id = ?
AND user_id = ?
");
return $stmt->execute([$this->currentTime, $notificationId, $this->userId]);
}
}
?>