26 defined(
'LGV_DBF_CATCHER' ) or die ( 'Cannot Execute Directly' );
28 require_once(CO_Config::db_class_dir().'/co_main_db_record.class.php');
54 $default_setup = parent::_default_setup();
55 $default_setup[
'longitude'] = (NULL != $this->_longitude) ? $this->_longitude : 0;
56 $default_setup[
'latitude'] = (NULL != $this->_latitude) ? $this->_latitude : 0;
58 return $default_setup;
70 $ret = parent::_build_parameter_array();
72 $ret[
'longitude'] = $this->_longitude;
73 $ret[
'latitude'] = $this->_latitude;
84 $spot0 = Array(
'longitude' => $this->_longitude,
'latitude' => $this->_latitude);
85 $spot1 = Array(
'longitude' => $this->_longitude + 10.0,
'latitude' => $this->_latitude);
86 $spot2 = Array(
'longitude' => $this->_longitude - 10.0,
'latitude' => $this->_latitude);
87 $spot3 = Array(
'longitude' => $this->_longitude,
'latitude' => $this->_latitude + 10.0);
88 $spot4 = Array(
'longitude' => $this->_longitude,
'latitude' => $this->_latitude - 10.0);
94 return ($distance1 + $distance2 + $distance3 + $distance4) / 40.0;
102 $ret = Array(
'longitude' => $this->_longitude,
'latitude' => $this->_latitude);
104 $fuzz_factor = $this->fuzz_factor();
105 if (0 < $fuzz_factor) {
107 $long_offset = function_exists(
'random_int') ? random_int(0, 100000 * ($fuzz_factor)) / 100000.0 : rand(0, 100000 * ($fuzz_factor)) / 100000.0;
108 $lat_offset = function_exists(
'random_int') ? random_int(0, 100000 * ($fuzz_factor)) / 100000.0 : rand(0, 100000 * ($fuzz_factor)) / 100000.0;
111 $km_per_degree = $this->_km_per_degree();
112 $long_offset /= $km_per_degree;
113 $lat_offset /= $km_per_degree;
116 $long_offset *= (rand(0, 9) < 5 ? -1.0 : 1.0);
117 $lat_offset *= (rand(0, 9) < 5 ? -1.0 : 1.0);
119 $ret[
'longitude'] += $long_offset;
120 $ret[
'latitude'] += $lat_offset;
131 $in_db_result = NULL,
133 $in_tags_array = NULL,
134 $in_longitude = NULL,
136 $in_fuzz_factor = NULL,
137 $in_can_see_through_the_fuzz = NULL
139 parent::__construct($in_db_object, $in_db_result, $in_owner_id, $in_tags_array);
141 if (NULL != $in_longitude) {
142 $this->_longitude = $in_longitude;
145 if (NULL != $in_latitude) {
146 $this->_latitude = $in_latitude;
149 if ((NULL != $in_fuzz_factor) && (0 != $in_fuzz_factor)) {
150 $this->context[
'fuzz_factor'] = $in_fuzz_factor;
151 } elseif (!isset($this->context[
'fuzz_factor']) || !$this->context[
'fuzz_factor']) {
152 $this->context[
'fuzz_factor'] = 0;
155 if (NULL != $in_can_see_through_the_fuzz) {
156 $this->context[
'can_see_through_the_fuzz'] = $in_can_see_through_the_fuzz;
168 $ret = parent::load_from_db($in_db_result);
171 $this->class_description =
'A basic class for long/lat locations.';
173 if ($this->_db_object) {
174 if (isset($in_db_result[
'longitude'])) {
175 $this->_longitude = doubleval($in_db_result[
'longitude']);
178 if (isset($in_db_result[
'latitude'])) {
179 $this->_latitude = doubleval($in_db_result[
'latitude']);
183 $ll_string = ((NULL != $this->_longitude) && (NULL != $this->_latitude)) ?
"($this->_longitude, $this->_latitude)" :
'';
185 $this->class_description =
"Generic longitude/latitude Class.";
186 $this->instance_description = isset($this->name) && $this->name ?
"$this->name $ll_string" : $ll_string;
201 $ret = parent::update_db();
203 $ll_string = ((NULL != $this->_longitude) && (NULL != $this->_latitude)) ?
"($this->_longitude, $this->_latitude)" :
'';
205 $this->instance_description = isset($this->name) && $this->name ?
"$this->name $ll_string" : $ll_string;
221 if (isset($in_new_value) && $this->user_can_write()) {
222 $this->_longitude = floatval($in_new_value);
223 $ret = $this->update_db();
239 if (isset($in_new_value) && $this->user_can_write()) {
240 $this->_latitude = floatval($in_new_value);
241 $ret = $this->update_db();
254 return isset($this->context[
'fuzz_factor']) ? abs(floatval($this->context[
'fuzz_factor'])) : 0.0;
262 return 0.0 < $this->fuzz_factor();
275 $in_new_value = abs(floatval($in_new_value));
277 if ($this->user_can_write()) {
278 if (0 == $in_new_value) {
279 unset($this->context[
'fuzz_factor']);
281 $this->context[
'fuzz_factor'] = $in_new_value;
284 $ret = $this->update_db();
297 if ($this->i_can_see_clearly_now()) {
298 return $this->_longitude;
300 return $this->longitude();
311 if ($this->i_can_see_clearly_now()) {
312 return $this->_latitude;
314 return $this->latitude();
325 return $this->_fuzz_me()[
'longitude'];
335 return $this->_fuzz_me()[
'latitude'];
348 if ($this->user_can_write()) {
349 $in_id = intval($in_id);
352 unset($this->context[
'can_see_through_the_fuzz']);
354 $ids = $this->get_access_object()->get_security_ids();
356 $in_id = (in_array($in_id, $ids) || $this->get_access_object()->god_mode()) ? $in_id : 0;
359 $this->context[
'can_see_through_the_fuzz'] = $in_id;
361 unset($this->context[
'can_see_through_the_fuzz']);
365 $ret = $this->update_db();
380 $ids = $this->get_access_object()->get_security_ids();
382 $my_see_item = intval($this->write_security_id);
384 $the_id = isset($this->context[
'can_see_through_the_fuzz']) ? intval($this->context[
'can_see_through_the_fuzz']) : 0;
386 if (isset($ids) && is_array($ids) && count($ids)) {
387 $ret = in_array($the_id, $ids) ? $the_id : 0;
398 $ret = !$this->is_fuzzy() || $this->user_can_write();
400 if (!$ret && $this->get_access_object()->security_db_available()) {
401 if (!$ret && isset($this->context[
'can_see_through_the_fuzz'])) {
402 $ids = $this->get_access_object()->get_security_ids();
404 $my_see_item = intval($this->context[
'can_see_through_the_fuzz']);
405 if (isset($ids) && is_array($ids) && count($ids)) {
406 $ret = in_array($my_see_item, $ids);
static get_accurate_distance( $lat1, $lon1, $lat2, $lon2)
Uses the Vincenty calculation to determine the distance (in Kilometers) between the two given lat/lon...
load_from_db( $in_db_result)
__construct( $in_db_object=NULL, $in_db_result=NULL, $in_owner_id=NULL, $in_tags_array=NULL, $in_longitude=NULL, $in_latitude=NULL, $in_fuzz_factor=NULL, $in_can_see_through_the_fuzz=NULL)
can_see_through_the_fuzz()
set_fuzz_factor( $in_new_value)
set_latitude( $in_new_value)
set_longitude( $in_new_value)
set_can_see_through_the_fuzz( $in_id)