-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_fetch_group.php
99 lines (85 loc) · 4.17 KB
/
admin_fetch_group.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
<?php
include 'connect.php';
header('Content-type: application/json');
// FILE UNTUK RESPONSE PENGAMBILAN DATA SUATU GROUP DARI DB
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// SQL untuk ambil data group dengan pagination
$MAX_PER_PAGES = 20;
$PAGES = $_GET['page'];
$OFFSET = ($PAGES - 1) * $MAX_PER_PAGES;
$sql = "SELECT ga.nama AS nama_group,
dg.id_group as id,
u.email AS email,
u.nama AS nama,
u.ketua,
ga.isActive,
ga.id AS groupId
FROM detail_group as dg
JOIN group_alkitab AS ga
ON ga.id = dg.id_group
JOIN user u
ON u.id = dg.id_user
WHERE ketua = 1
GROUP BY dg.id_group
LIMIT ? OFFSET ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$MAX_PER_PAGES,$OFFSET]);
$output = '';
$notif = '';
// Setiap Group dihitung jumlah membernya
while($row = $stmt->fetch()){
$id = $row['id'];
// SQL untuk hitung member
$sqlCount = "SELECT COUNT(id_user) AS total
FROM (
SELECT dg.id_user as id_user
FROM detail_group AS dg
JOIN user AS u
ON u.id = dg.id_user
JOIN group_alkitab AS ga
ON ga.id = dg.id_group
WHERE u.ketua = 0 AND
ga.id = ?
GROUP BY dg.id_user
) AS myCount";
$stmtCount = $pdo->prepare($sqlCount);
$stmtCount->execute([$id]);
$total = $stmtCount->fetch()['total'];
// Badge aktif dan non-aktif dari suatu group
$badge = '<span style="cursor:pointer;" data-id="' . $row['groupId'] . '" class="badge-group badge rounded-pill bg-success float-end">Active</span>';
if(!$row['isActive']){
$badge = '<span style="cursor:pointer;" data-id="' . $row['groupId'] . '" class="badge-group badge rounded-pill bg-danger float-end">Non-Active</span>';
}
// Card dari group
$output .= '<div class="col-4">
<div class="card text-white bg-secondary mb-3 align-center" style="max-width: 18rem;">
<div class="card-header">
<div class="row">
<div class="col-8">
<span>
<input
type="text"
class="form-control group-name-input"
value="' . $row['nama_group'] . '"
disabled
data-id="'. $row['groupId'] .'">
</span>
</div>
<div class="col-4 text-right align-middle">
'. $badge .'
</div>
</div>
</div>
<div class="card-body">
<h5 class="card-title">'. $row['nama'] .'</h5>
<p class="card-text">Total : '. $total . ' Member</p>
<div class="row">
<div class="col-12 col-sm-6"><input type="button" class="btn btn-info detail-group" value="Detail Group" data-sp="' . $row['id'] . '" data-group="' . $row['nama_group'] . '"></div>
<div class="col-12 col-sm-6"><input type="button" class="btn btn-light see-list-event" value="Detail Event" data-sp="' . $row['id'] . '" data-group="' . $row['nama_group'] . '"></div>
</div>
</div>
</div>
</div>';
}
echo json_encode(array('output' => $output, 'notif' => $notif));
}