-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.class.php
115 lines (94 loc) · 3.44 KB
/
review.class.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
declare(strict_types = 1);
class Review {
public int $id;
public int $score;
public string $reviewText;
public int $restaurantId;
public int $userId;
public function __construct(int $id, int $score, string $reviewText, int $restaurantId, int $userId)
{
$this->id = $id;
$this->score = $score;
$this->reviewText = $reviewText;
$this->restaurantId = $restaurantId;
$this->userId = $userId;
}
static function countReview(PDO $db){
$stmt = $db->prepare('
SELECT MAX(ReviewId)
FROM Review
');
$stmt->execute(array());
$max = $stmt->fetch();
return $max['MAX(ReviewId)'];
}
static function getReviews(PDO $db, int $count) : array {
$stmt = $db->prepare('SELECT ReviewId, Score, ReviewText, RestaurantId, UserId FROM Review LIMIT ?');
$stmt->execute(array($count));
$Reviews = array();
while ($Review = $stmt->fetch()) {
$Reviews[] = new Review(
intval($Review['ReviewId']),
$Review['Score'],
$Review['ReviewText'],
intval($Review['RestaurantId']),
intval($Review['UserId'])
);
}
return $Reviews;
}
static function getReview(PDO $db, int $id) : Review {
$stmt = $db->prepare('SELECT ReviewId, Score, ReviewText, RestaurantId, UserId FROM Review WHERE ReviewId = ?');
$stmt->execute(array($id));
$Review = $stmt->fetch();
return new Review(
intval($Review['ReviewId']),
$Review['Score'],
$Review['ReviewText'],
intval($Review['RestaurantId']),
intval($Review['UserId']),
);
}
static function updateReview(PDO $db, int $score, string $reviewText, int $restaurantId, int $userId, int $id) {
$stmt = $db->prepare('UPDATE Review SET Score = ?, ReviewText = ?, RestaurantId = ?, UserId = ? WHERE ReviewId = ?');
$stmt->execute(array($score,$reviewText,$restaurantId,$userId,$id));
}
static function addReview(PDO $db, int $id, int $score, string $reviewText, int $restaurantId, int $userId) {
$stmt = $db->prepare('INSERT INTO Review(ReviewId,Score,ReviewText,RestaurantId,UserId) VALUES (?, ?, ?, ?, ?)');
$stmt->execute(array($id, $score,$reviewText,$restaurantId,$userId));
}
static function getRestaurantReviews(PDO $db, int $id) : array {
$stmt = $db->prepare('SELECT ReviewId, Score, ReviewText, UserId FROM Review WHERE RestaurantId = ?');
$stmt->execute(array($id));
$Reviews = [];
while ($Review = $stmt->fetch()) {
$Reviews[] = new Review(
intval($Review['ReviewId']),
intval($Review['Score']),
$Review['ReviewText'],
$id,
intval($Review['UserId'])
);
}
return $Reviews;
}
/* static function getUserReview(PDO $db, int $id) : User {
$stmt = $db->prepare('
SELECT UserId, FirstLastName, Username, UserAddress, PhoneNumber, RestaurantId
FROM Review
WHERE UserId = ?
');
$stmt->execute(array($id));
$User = $stmt->fetch();
return new User(
intval($User['UserId']),
$User['FirstLastName'],
$User['Username'],
$User['UserAddress'],
intval($User['PhoneNumber']),
intval($User['RestaurantId'])
);
} */
}
?>