-
Notifications
You must be signed in to change notification settings - Fork 0
/
terumbu.php
104 lines (95 loc) · 3.17 KB
/
terumbu.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
<?php
class Terumbu
{
protected $db;
function __construct($db)
{
$this->db = $db;
}
function get_maps()
{
$cont = [];
$row = $this->db->prepare("SELECT * FROM t_maps WHERE validasi = 1");
$row->execute();
$hasil = $row->fetchAll();
foreach ($hasil as $value) {
array_push($cont, [
"type" => "Feature",
"properties" => [
"fid" => $value['id'],
"Id" => $value['id'],
"Kategori" => $value['kategori'],
"Region" => $value['region'],
"gambar" => $value['gambar'],
"title"=>$value['region'],
],
"geometry" => [
"type" => "Point",
"coordinates" => [
$value['latitude'],
$value['longitude']
]
]
]);
}
$arr = [
"type" => "FeatureCollection",
"name" => "KondisiTerumbuKarang_31",
"crs" => [
"type" => "name",
"properties" => [
"name" => "urn:ogc:def:crs:OGC:1.3:CRS84"
]
],
"features" => $cont
];
return json_encode($arr);
}
function tampil_data($tabel)
{
$row = $this->db->prepare("SELECT * FROM $tabel");
$row->execute();
return $hasil = $row->fetchAll();
}
function add_data($kategori, $region, $lat, $long, $gambar)
{
$data = $this->db->prepare("INSERT INTO kondisi_terumbu (kategori,region,lat,`long`,gambar) VALUES ('" . $kategori . "', '" . $region . "', '" . $lat . "', '" . $long . "','" . $gambar . "')");
$data->execute();
return $data->rowCount();
}
function get_by_id($id)
{
$query = $this->db->prepare("SELECT * FROM kondisi_terumbu where id=?");
$query->bindParam(1, $id);
$query->execute();
return $query->fetch();
}
public function update($kategori, $region, $lat, $long, $id,$gambar)
{
if($gambar == null){
$query = $this->db->prepare('UPDATE kondisi_terumbu set kategori=?,region=?,lat=?,`long`=? where id=?');
$query->bindParam(1, $kategori);
$query->bindParam(2, $region);
$query->bindParam(3, $lat);
$query->bindParam(4, $long);
$query->bindParam(5, $id);
}else{
$query = $this->db->prepare('UPDATE kondisi_terumbu set kategori=?,region=?,lat=?,`long`=?,gambar=? where id=?');
$query->bindParam(1, $kategori);
$query->bindParam(2, $region);
$query->bindParam(3, $lat);
$query->bindParam(4, $long);
$query->bindParam(5, $gambar);
$query->bindParam(6, $id);
}
$query->execute();
return $query->rowCount();
}
public function delete($id)
{
$query = $this->db->prepare("DELETE FROM kondisi_terumbu where id=?");
$query->bindParam(1, $id);
$query->execute();
return $query->rowCount();
}
}