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: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170:
<?php
namespace WPGMZA;
require_once(plugin_dir_path(__FILE__) . '/class.crud.php');
class Marker extends Crud implements \JsonSerializable
{
const DEFAULT_ICON = "//maps.gstatic.com/mapfiles/api-3/images/spotlight-poi2.png";
private static $columns;
protected $custom_fields;
public function __construct($id_or_fields=-1)
{
global $wpdb;
Crud::__construct("{$wpdb->prefix}wpgmza", $id_or_fields);
if(class_exists('WPGMZA\\CustomMarkerFields'))
$this->custom_fields = apply_filters('wpgmza_get_marker_custom_fields', $this->id);
}
public static function getColumns()
{
global $wpdb;
global $WPGMZA_TABLE_NAME_MARKERS;
if(Marker::$columns)
return Marker::$columns;
Marker::$columns = $wpdb->get_results('SHOW COLUMNS FROM ' . $WPGMZA_TABLE_NAME_MARKERS);
return Marker::$columns;
}
public static function create_instance($id_or_fields=-1)
{
return apply_filters('wpgmza_create_marker_instance', $id_or_fields);
}
public static function get_table_name_static()
{
global $wpdb;
return "{$wpdb->prefix}wpgmza";
}
public function jsonSerialize()
{
$json = Crud::jsonSerialize();
unset($json['latlng']);
return $json;
}
protected function get_placeholder_by_type($type)
{
global $wpgmza;
if($type == 'point')
return "{$wpgmza->spatialFunctionPrefix}GeomFromText(%s)";
return Crud::get_placeholder_by_type($type);
}
protected function get_column_parameter($name)
{
if($name == 'latlng')
return "POINT(" . floatval($this->lat) . " " . floatval($this->lng) . ")";
return Crud::get_column_parameter($name);
}
protected function get_arbitrary_data_column_name()
{
return 'other_data';
}
public function update()
{
Crud::update();
}
protected function update_latlng()
{
global $wpgmza;
global $wpdb;
$params = array(
$this->lat,
$this->lng,
$this->get_column_parameter('latlng'),
$this->id
);
$stmt = $wpdb->prepare("UPDATE " . $this->get_table_name() . " SET lat=%s, lng=%s, latlng={$wpgmza->spatialFunctionPrefix}GeomFromText(%s) WHERE id=%d", $params);
$wpdb->query($stmt);
}
public function __set($name, $value)
{
Crud::__set($name, $value);
switch($name)
{
case 'lat':
case 'lng':
case 'latlng':
$this->update_latlng();
break;
}
}
public function getPosition()
{
return new LatLng($this->lat, $this->lng);
}
}
add_filter('wpgmza_create_marker_instance', 'WPGMZA\\create_marker_instance_delegate', 10, 1);
function create_marker_instance_delegate($id)
{
return new Marker($id);
}