-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapsHandler.php
138 lines (134 loc) · 3.75 KB
/
MapsHandler.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Class MapsHandler : To Manage Maps data (add, delete, update Maps, get a Map or several from database)
**/
class MapsHandler{
/* getListMaps
* @return object sql
* @global <type> $wpdb
* @global string $my_config_table
*/
public function getListMaps(){
global $wpdb, $my_config_table;
$sql = "SELECT * from {$my_config_table} ";
$sql_result=$wpdb->get_results($sql);
return $sql_result;
}
/* getListPageMaps (for pagination mode)
* @param int $action_offset
* @param int $per_page
* @return object sql
* @global <type> $wpdb
* @global string $my_config_table
*/
public function getListPageMaps($action_offset,$per_page){
global $wpdb, $my_config_table;
$sql = "SELECT * from {$my_config_table} LIMIT {$action_offset}, {$per_page}";
$sql_result=$wpdb->get_results($sql);
return $sql_result;
}
/* getMapById
* @param int $id
* @return array row sql
* @global <type> $wpdb
* @global string $my_config_table
*/
public function getMapById($id){
global $wpdb, $my_config_table;
$sql = "select * from {$my_config_table} WHERE `id`={$id}";
$sql_result=$wpdb->get_row($sql, ARRAY_A);
return $sql_result;
}
/*
* addMap add a map
* @param string $title_map
* @param string $url_map
* @return boolean
* @global <type> $wpdb
* @global string $my_config_table
*/
public function addMap($title_map,$url_map){
global $wpdb, $my_config_table;
$sql_result = $wpdb->insert(
$my_config_table,
array(
'title_map' => $title_map,
'url_map' => $url_map
),
array('%s', '%s'));
return $sql_result;
}
/*
* updateMap update a map
* @param string $title_map
* @param string $url_map
* @param int $id
* @return boolean
* @global <type> $wpdb
* @global string $my_config_table
*/
public function updateMap($title_map,$url_map,$id){
global $wpdb, $my_config_table;
$sql_result = $wpdb->update(
$my_config_table,
array(
'title_map' => $title_map,
'url_map' => $url_map
),
array('id' => $id),
array('%s', '%s'),
array('%d'));
return $sql_result;
}
/*
* deleteMap
* @param int $id
* @return boolean
* @global <type> $wpdb
* @global string $my_config_table
*/
public function deleteMap($id){
global $wpdb, $my_config_table;
$sql = "DELETE FROM {$my_config_table} WHERE id = {$id}";
$sql_result = $wpdb->query($sql);
return $sql_result;
}
/**
* display_map : display a Google Map
* @param string Url (http://maps.google.co.nz/maps/ms?msid=...fbd972e&msa=0&output=kml)
* @return string HTML content
*/
function display_map($url,$width,$height,$id_map) {
$output .= "<style> #".$id_map." {
margin: 2px auto;
border: 1px dashed #C0C0C0;
width: ".$width."px;
height: ".$height."px;
}
</style>";
$output .= '<script type="text/javascript">';
$output .= '
$(function() {
$("#'.$id_map.'").gmap3({
action : "init",
options : {
center : [-41.771312, 172.902344],
zoom : 5,
disableDefaultUI : true
}
}, {
action : "addKmlLayer",
url : "' . $url . '",
options : {
suppressInfoWindows : true,
preserveViewport : false
}
});
});
';
$output .= '</script>';
$output .= '<div id="'.$id_map.'"></div>';
return $output;
}
}
?>