forked from imabutahersiddik/CodeStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_submission.php
More file actions
52 lines (46 loc) · 1.61 KB
/
process_submission.php
File metadata and controls
52 lines (46 loc) · 1.61 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
50
51
52
// Add at the beginning of the file:
function incrementAppViews($pdo, $appId) {
$stmt = $pdo->prepare("UPDATE apps SET views_count = views_count + 1 WHERE id = ?");
return $stmt->execute([$appId]);
}
function incrementAppDownloads($pdo, $appId, $userIp) {
// Record download
$stmt = $pdo->prepare("INSERT INTO app_downloads (app_id, user_ip) VALUES (?, ?)");
$stmt->execute([$appId, $userIp]);
// Update download count
$stmt = $pdo->prepare("UPDATE apps SET downloads_count = downloads_count + 1 WHERE id = ?");
return $stmt->execute([$appId]);
}
function recordRating($pdo, $appId, $userIp, $rating, $comment = '') {
try {
$pdo->beginTransaction();
// Insert or update rating
$stmt = $pdo->prepare("
INSERT INTO app_ratings (app_id, user_ip, rating, comment)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE rating = ?, comment = ?
");
$stmt->execute([$appId, $userIp, $rating, $comment, $rating, $comment]);
// Update app's total rating
$stmt = $pdo->prepare("
UPDATE apps
SET total_rating = (
SELECT AVG(rating)
FROM app_ratings
WHERE app_id = ?
),
ratings_count = (
SELECT COUNT(*)
FROM app_ratings
WHERE app_id = ?
)
WHERE id = ?
");
$stmt->execute([$appId, $appId, $appId]);
$pdo->commit();
return true;
} catch (Exception $e) {
$pdo->rollBack();
throw $e;
}
}