BAOBAB
CO_Place Class Reference
Inheritance diagram for CO_Place:
Collaboration diagram for CO_Place:

Public Member Functions

 __construct ( $in_db_object=NULL, $in_db_result=NULL, $in_owner_id=NULL, $in_tags_array=NULL, $in_longitude=NULL, $in_latitude=NULL)
 
 set_address_elements ( $in_tags, $dont_save=false)
 
 set_address_element ( $in_index, $in_value, $dont_save=false)
 
 set_address_element_by_key ( $in_key, $in_value, $dont_save=false)
 
 get_address_element_by_index ( $in_index)
 
 lookup_address ()
 
 geocode_long_lat ()
 
 get_readable_address ( $with_venue=true)
 
 set_tags_from_address_elements ()
 
 get_address_elements ()
 
- Public Member Functions inherited from CO_LL_Location
 __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)
 
 load_from_db ( $in_db_result)
 
 update_db ()
 
 set_longitude ( $in_new_value)
 
 set_latitude ( $in_new_value)
 
 fuzz_factor ()
 
 is_fuzzy ()
 
 set_fuzz_factor ( $in_new_value)
 
 raw_longitude ()
 
 raw_latitude ()
 
 longitude ()
 
 latitude ()
 
 set_can_see_through_the_fuzz ( $in_id)
 
 can_see_through_the_fuzz ()
 
 i_can_see_clearly_now ()
 
- Public Member Functions inherited from CO_Main_DB_Record
 __construct ( $in_db_object=NULL, $in_db_result=NULL, $in_owner_id=NULL, $in_tags_array=NULL)
 
 set_owner_id ( $in_new_id)
 
 set_tags ( $in_tags_array)
 
 set_tag ( $in_tag_index, $in_tag_value)
 
 get_payload ()
 
 set_payload ( $in_payload)
 
 owner_id ()
 
 tags ()
 
- Public Member Functions inherited from A_CO_DB_Table_Base
 __construct ( $in_db_object=NULL, $in_db_result=NULL)
 
 set_batch_mode ()
 
 clear_batch_mode ()
 
 id ()
 
 lock ()
 
 locked ()
 
 danger_will_robinson_danger_clear_id ()
 
 user_can_read ()
 
 user_can_write ()
 
 set_read_security_id ($in_new_id)
 
 set_write_security_id ($in_new_id)
 
 set_name ($in_new_value)
 
 delete_from_db ()
 
 reload_from_db ()
 
 get_access_object ()
 
 get_lang ()
 
 set_lang ( $in_lang_id=NULL)
 

Public Attributes

 $address_elements = Array()
 These are the address elements we use for creating lookup addresses. More...
 
 $google_geocode_uri_prefix = NULL
 This is the Geocode URI for the Google Geocode. More...
 
 $google_lookup_uri_prefix = NULL
 This is the lookup URI for the Google reverse Geocode. More...
 
 $region_bias = NULL
 This can be set by subclasses in order to set a region bias. More...
 
- Public Attributes inherited from A_CO_DB_Table_Base
 $class_description
 This is a description of the class (not the instance). More...
 
 $instance_description
 This is a description that describes the instance. More...
 
 $last_access
 This is a UNIX epoch date that describes the last modification. The default is UNIX Day Two (in case of UTC timezone issues). More...
 
 $name
 This is the "object_name" string field. More...
 
 $read_security_id
 This is a single integer, defining the security ID required to view the record. If it is 0, then it is "open.". More...
 
 $write_security_id
 This is a single integer, defining the required security token to modify the record. If it is 0, then any logged-in user can modify. More...
 
 $context
 This is a mixed associative array, containing fields for the object. More...
 
 $error
 If there is an error, it is contained here, in a LGV_Error instance. More...
 

Protected Member Functions

 _get_address_element_labels ()
 
- Protected Member Functions inherited from CO_LL_Location
 _default_setup ()
 
 _build_parameter_array ()
 
 _km_per_degree ()
 
 _fuzz_me ()
 
- Protected Member Functions inherited from A_CO_DB_Table_Base
 _badger_serialize ( $in_data)
 
 _badger_unserialize ( $in_data)
 
 _write_to_db ()
 
 _seppuku ()
 

Additional Inherited Members

- Static Public Attributes inherited from CO_Main_DB_Record
static $s_table_name = 'co_data_nodes'
 
- Protected Attributes inherited from CO_LL_Location
 $_longitude
 
 $_latitude
 
- Protected Attributes inherited from CO_Main_DB_Record
 $_owner_id
 
 $_tags
 
- Protected Attributes inherited from A_CO_DB_Table_Base
 $_db_object
 This is the actual database object that "owns" this instance. It should not be exposed beyond this class or subclasses, thereof. More...
 
 $_id
 This is the within-table unique ID of this record. More...
 
 $_batch_mode
 If this is true, then the write_record call will not be made in update_db. It will be done when clear_batch_mode() is called, instead. More...
 

Detailed Description

This is a specialization of the location class. It adds support for US addresses, and uses the first eight tags for this.

Definition at line 46 of file co_place.class.php.

Constructor & Destructor Documentation

◆ __construct()

CO_Place::__construct (   $in_db_object = NULL,
  $in_db_result = NULL,
  $in_owner_id = NULL,
  $in_tags_array = NULL,
  $in_longitude = NULL,
  $in_latitude = NULL 
)

Constructor (Initializer)

Parameters
$in_db_objectThe database object for this instance.
$in_db_resultThe database row for this instance (associative array, with database keys).
$in_owner_idThe ID of the object (in the database) that "owns" this instance.
$in_tags_arrayAn array of up to 10 strings, with address information in the first 8. Order is important:
  • 0: Venue
  • 1: Street Address
  • 2: Extra Information
  • 3: Town
  • 4: County
  • 5: State
  • 6: ZIP Code
  • 7: Nation

Associative keys are not used. The array should be in that exact order.

Parameters
$in_longitudeAn initial longitude value.
$in_latitudeAn initial latitude value.

Reimplemented in CO_US_Place_Collection, CO_US_Place, and CO_Place_Collection.

Definition at line 77 of file co_place.class.php.

94  {
95 
96  parent::__construct($in_db_object, $in_db_result, $in_owner_id, $in_tags_array, $in_longitude, $in_latitude);
97 
98  $this->class_description = "This is a 'Place' Class for General Addresses.";
99  $this->instance_description = isset($this->name) && $this->name ? "$this->name ($this->_longitude, $this->_latitude)" : "($this->_longitude, $this->_latitude)";
100 
101  $this->set_address_elements($this->tags(), true);
102 
103  $bias = (NULL != $this->region_bias) ? 'region='.$this->region_bias.'&' : '';
104 
105  $this->google_geocode_uri_prefix = 'https://maps.googleapis.com/maps/api/geocode/json?'.$bias.'key='.CO_Config::$google_api_key.'&address=';
106  $this->google_lookup_uri_prefix = 'https://maps.googleapis.com/maps/api/geocode/json?'.$bias.'key='.CO_Config::$google_api_key.'&latlng=';
107  }
$region_bias
This can be set by subclasses in order to set a region bias.
set_address_elements( $in_tags, $dont_save=false)

References $region_bias, set_address_elements(), and CO_Main_DB_Record\tags().

Here is the call graph for this function:

Member Function Documentation

◆ _get_address_element_labels()

CO_Place::_get_address_element_labels ( )
protected

This fetches string labels to be used as keys for the fixed tags.

Returns
an array of strings, which will correspond to the first eight tags.

Reimplemented in CO_US_Place.

Definition at line 59 of file co_place.class.php.

References CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_0, CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_1, CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_2, CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_3, CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_4, CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_5, CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_6, and CO_CHAMELEON_Lang_Common\$chameleon_co_place_tag_7.

Referenced by geocode_long_lat(), get_address_element_by_index(), get_address_elements(), get_readable_address(), set_address_element(), set_address_element_by_key(), set_address_elements(), and set_tags_from_address_elements().

Here is the caller graph for this function:

◆ geocode_long_lat()

CO_Place::geocode_long_lat ( )

This will do a geocode, using the Google Geocode API, of the object's long/lat, and will return the address (in an associative array). This requires that CO_Config::$google_api_key be set to a valid API key with the Google Geocode service enabled.

Returns

Definition at line 260 of file co_place.class.php.

260  {
261  $uri = $this->google_lookup_uri_prefix . urlencode($this->raw_latitude()) . ',' . urlencode($this->raw_longitude());
262  $http_status = '';
263  $error_catcher = '';
264 
265  $resulting_json = json_decode(CO_Chameleon_Utils::call_curl($uri, false, $http_status, $error_catcher));
266  if (isset($resulting_json) && $resulting_json &&isset($resulting_json->results) && is_array($resulting_json->results) && count($resulting_json->results)) {
267  if (isset($resulting_json->results[0]->address_components) && is_array($resulting_json->results[0]->address_components) && count($resulting_json->results[0]->address_components)) {
268  $address_components = $resulting_json->results[0]->address_components;
269 
270  $labels = $this->_get_address_element_labels();
271  $ret = Array($labels[0] => '', $labels[1] => '', $labels[3] => '', $labels[4] => '', $labels[5] => '', $labels[6] => '');
272 
273  if (isset($labels[7])) {
274  $ret[$labels[7]] = '';
275  }
276 
277  foreach ($address_components as $component) {
278  $int_key = $component->types[0];
279 
280  switch ($int_key) {
281  case 'premise':
282  if ($ret[$labels[0]]) {
283  $ret[$labels[0]] = ' '.$ret[$labels[0]];
284  }
285  $ret[$labels[0]] = strval($component->long_name).$ret[$labels[0]];
286  break;
287  case 'street_number':
288  if ($ret[$labels[1]]) {
289  $ret[$labels[1]] = ' '.$ret[$labels[1]];
290  }
291  $ret[$labels[1]] = strval($component->short_name).$ret[$labels[1]];
292  break;
293  case 'route':
294  if ($ret[$labels[1]]) {
295  $ret[$labels[1]] .= ' ';
296  }
297  $ret[$labels[1]] .= strval($component->long_name);
298  break;
299  case 'locality':
300  $ret[$labels[3]] = strval($component->long_name);
301  break;
302  case 'administrative_area_level_1':
303  $ret[$labels[5]] = strval($component->short_name);
304  break;
305  case 'administrative_area_level_2':
306  $ret[$labels[4]] = strval($component->short_name);
307  break;
308  case 'postal_code':
309  if ($ret[$labels[6]]) {
310  $ret[$labels[6]] = '-'.$ret[$labels[6]];
311  }
312  $ret[$labels[6]] = strval($component->short_name).$ret[$labels[6]];
313  break;
314  case 'postal_code_suffix':
315  if ($ret[$labels[6]]) {
316  $ret[$labels[6]] .= '-';
317  }
318  $ret[$labels[6]] .= strval($component->short_name);
319  break;
320  case 'country':
321  if (isset($labels[7])) {
322  $ret[$labels[7]] = strval($component->short_name);
323  }
324  break;
325  }
326  }
327 
328  return $ret;
329  }
330  }
331 
335 
336  return NULL;
337  }
_get_address_element_labels()
static $co_place_error_code_failed_to_geocode
Definition: common.inc.php:57
static $co_place_error_name_failed_to_geocode
Definition: en.php:32
static $co_place_error_desc_failed_to_geocode
Definition: en.php:33
static call_curl( $in_uri, $in_post=false, &$http_status=NULL, &$content_failure_note=NULL)
This is a function that returns the results of an HTTP call to a URI. It is a lot more secure than fi...
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32

References CO_CHAMELEON_Lang_Common\$co_place_error_code_failed_to_geocode, CO_CHAMELEON_Lang\$co_place_error_desc_failed_to_geocode, CO_CHAMELEON_Lang\$co_place_error_name_failed_to_geocode, _get_address_element_labels(), CO_Chameleon_Utils\call_curl(), CO_LL_Location\raw_latitude(), and CO_LL_Location\raw_longitude().

Here is the call graph for this function:

◆ get_address_element_by_index()

CO_Place::get_address_element_by_index (   $in_index)
Returns
the indexed address element, or NULL.
Parameters
$in_indexThe 0-based index we're looking for.

Definition at line 213 of file co_place.class.php.

214  {
215  $ret = NULL;
216 
217  $labels = $this->_get_address_element_labels();
218 
219  if ((0 <= $in_index) && ($in_index < count($labels))) {
220  $key = $labels[$in_index];
221  $ret = $this->address_elements[$key];
222  }
223 
224  return $ret;
225  }

References _get_address_element_labels().

Here is the call graph for this function:

◆ get_address_elements()

CO_Place::get_address_elements ( )
Returns
the address elements, in an associative array.

Reimplemented in CO_US_Place.

Definition at line 435 of file co_place.class.php.

435  {
436  $ret = [];
437  $labels = $this->_get_address_element_labels();
438 
439  for ($i = 0; $i < count($labels); $i++) {
440  $key = $labels[$i];
441  if (isset($this->address_elements[$key]) && trim($this->address_elements[$key])) {
442  $ret[$key] = trim($this->address_elements[$key]);
443  }
444  }
445 
446  return $ret;
447  }

References _get_address_element_labels().

Here is the call graph for this function:

◆ get_readable_address()

CO_Place::get_readable_address (   $with_venue = true)
Returns
the address, in a "readable" format.
Parameters
$with_venueIf false, then only the street address/town/state/nation will be displayed. That makes this better for geocoding. Default is true.

Definition at line 343 of file co_place.class.php.

344  {
345  $ret = '';
346 
347  $tag_key_array = $this->_get_address_element_labels();
348 
349  if (isset($tag_key_array) && is_array($tag_key_array) && count($tag_key_array)) {
350  if ($with_venue && isset($tag_key_array[0]) && isset($this->address_elements[$tag_key_array[0]])) {
351  $ret = $this->address_elements[$tag_key_array[0]];
352  }
353 
354  if ($with_venue && isset($tag_key_array[2]) && isset($this->address_elements[$tag_key_array[2]]) && $this->address_elements[$tag_key_array[2]]) {
355  $open_paren = false;
356 
357  if ($ret) {
358  $ret .= ' (';
359  $open_paren = true;
360  }
361 
362  $ret .= $this->address_elements[$tag_key_array[2]];
363 
364  if ($open_paren) {
365  $ret .= ')';
366  }
367  }
368 
369  if (isset($tag_key_array[1]) && isset($this->address_elements[$tag_key_array[1]]) && $this->address_elements[$tag_key_array[1]]) {
370  if ($ret) {
371  $ret .= ', ';
372  }
373 
374  $ret .= $this->address_elements[$tag_key_array[1]];
375  }
376 
377  if (isset($tag_key_array[3]) && isset($this->address_elements[$tag_key_array[3]]) && $this->address_elements[$tag_key_array[3]]) {
378  if ($ret) {
379  $ret .= ', ';
380  }
381 
382  $ret .= $this->address_elements[$tag_key_array[3]];
383  }
384 
385  if (isset($tag_key_array[5]) && isset($this->address_elements[$tag_key_array[5]]) && $this->address_elements[$tag_key_array[5]]) {
386  if ($ret) {
387  $ret .= ', ';
388  }
389 
390  $ret .= $this->address_elements[$tag_key_array[5]];
391  }
392 
393  if (isset($tag_key_array[6]) && isset($this->address_elements[$tag_key_array[6]]) && $this->address_elements[$tag_key_array[6]]) {
394  if ($ret) {
395  $ret .= ' ';
396  }
397 
398  $ret .= $this->address_elements[$tag_key_array[6]];
399  }
400 
401  if (isset($tag_key_array[7]) && isset($this->address_elements[$tag_key_array[7]]) && $this->address_elements[$tag_key_array[7]]) {
402  if ($ret) {
403  $ret .= ' ';
404  }
405 
406  $ret .= $this->address_elements[$tag_key_array[7]];
407  }
408  }
409 
410  return $ret;
411  }

References _get_address_element_labels().

Referenced by lookup_address().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_address()

CO_Place::lookup_address ( )

This will do a reverse geocode, using the Google Geocode API, of the object's address, and will return the long/lat (in an associative array). This requires that CO_Config::$google_api_key be set to a valid API key with the Google Geocode service enabled.

Returns

Definition at line 234 of file co_place.class.php.

234  {
235  $uri = $this->google_geocode_uri_prefix.urlencode($this->get_readable_address(false));
236  $http_status = '';
237  $error_catcher = '';
238 
239  $resulting_json = json_decode(CO_Chameleon_Utils::call_curl($uri, false, $http_status, $error_catcher));
240  if (isset($resulting_json) && $resulting_json &&isset($resulting_json->results) && is_array($resulting_json->results) && count($resulting_json->results)) {
241  if (isset($resulting_json->results[0]->geometry) && isset($resulting_json->results[0]->geometry->location) && isset($resulting_json->results[0]->geometry->location->lng) && isset($resulting_json->results[0]->geometry->location->lat)) {
242  return Array( 'longitude' => floatval($resulting_json->results[0]->geometry->location->lng), 'latitude' => floatval($resulting_json->results[0]->geometry->location->lat));
243  }
244  }
245 
249 
250  return NULL;
251  }
get_readable_address( $with_venue=true)
static $co_place_error_code_failed_to_lookup
Definition: common.inc.php:58
static $co_place_error_name_failed_to_lookup
Definition: en.php:35
static $co_place_error_desc_failed_to_lookup
Definition: en.php:36

References CO_CHAMELEON_Lang_Common\$co_place_error_code_failed_to_lookup, CO_CHAMELEON_Lang\$co_place_error_desc_failed_to_lookup, CO_CHAMELEON_Lang\$co_place_error_name_failed_to_lookup, CO_Chameleon_Utils\call_curl(), and get_readable_address().

Here is the call graph for this function:

◆ set_address_element()

CO_Place::set_address_element (   $in_index,
  $in_value,
  $dont_save = false 
)

This sets the indexed address_element property, as per the provided string. This can also update the tag.

Returns
true, if $dont_save was false, and the tags were successfully saved.
Parameters
$in_indexThe 0-based index of the value to set.
$in_valueThe value to set to the address element string.
$dont_saveIf true, then the DB update will not be called.

Definition at line 159 of file co_place.class.php.

162  {
163  $ret = false;
164 
165  $in_index = intval($in_index);
166  $labels = $this->_get_address_element_labels();
167 
168  if ((0 <= $in_index) && ($in_index < count($labels))) {
169  $key = $labels[$in_index];
170 
171  $in_value = strval($in_value);
172 
173  $this->address_elements[$key] = $in_value;
174  $this->_tags[$in_index] = $in_value;
175 
176  if (!$dont_save) {
177  $ret = $this->update_db();
178  }
179  }
180 
181  return $ret;
182  }

References _get_address_element_labels(), and CO_LL_Location\update_db().

Referenced by set_address_element_by_key(), and set_address_elements().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_address_element_by_key()

CO_Place::set_address_element_by_key (   $in_key,
  $in_value,
  $dont_save = false 
)

This sets the address_element property, as per the provided string, and indexed by the associative key. This can also update the tag.

Returns
true, if $dont_save was false, and the tags were successfully saved.
Parameters
$in_keyThe string, with the element key.
$in_valueThe value to set to the address element string.
$dont_saveIf true, then the DB update will not be called.

Definition at line 190 of file co_place.class.php.

193  {
194  $ret = false;
195 
196  $in_index = intval($in_index);
197  $labels = $this->_get_address_element_labels();
198 
199  for ($i = 0; $i < count($labels); $i++) {
200  if ($labels[$i] == $in_key) {
201  $ret = $this->set_address_element($i, $in_value, $dont_save);
202  break;
203  }
204  }
205 
206  return $ret;
207  }
set_address_element( $in_index, $in_value, $dont_save=false)

References _get_address_element_labels(), and set_address_element().

Here is the call graph for this function:

◆ set_address_elements()

CO_Place::set_address_elements (   $in_tags,
  $dont_save = false 
)

This sets the address_elements property, as per the provided array of strings. This can also update the tags.

Returns
true, if $dont_save was false, and the tags were successfully saved.
Parameters
$in_tagsAn array of up to 8 strings, with the new address information. Order is important:
  • 0: Venue
  • 1: Street Address
  • 2: Extra Information
  • 3: Town
  • 4: County
  • 5: State
  • 6: ZIP Code
  • 7: Nation

Associative keys are not used. The array should be in that exact order.

Parameters
$dont_saveIf true, then the DB update will not be called.

Definition at line 115 of file co_place.class.php.

128  {
129  $ret = false;
130 
131  $this->address_elements = Array();
132  $labels = $this->_get_address_element_labels();
133 
134  for ($i = 0; $i < count($labels); $i++) {
135  $tag_value = '';
136 
137  if (test_is_assoc($in_tags)) {
138  $tag_value = isset($in_tags[$labels[$i]]) ? $in_tags[$labels[$i]] : '';
139  } else {
140  $tag_value = isset($in_tags[$i]) ? $in_tags[$i] : '';
141  }
142 
143  $this->set_address_element($i, $tag_value, true);
144  }
145 
146  if (!$dont_save) {
147  $ret = $this->update_db();
148  }
149 
150  return $ret;
151  }
test_is_assoc(array $arr)

References _get_address_element_labels(), set_address_element(), test_is_assoc(), and CO_LL_Location\update_db().

Referenced by __construct().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_tags_from_address_elements()

CO_Place::set_tags_from_address_elements ( )

This updates the tags (and saves them to the DB) as per our internal address_elements property.

Returns
true, if successful.

Definition at line 419 of file co_place.class.php.

419  {
420  $new_tags = $this->tags;
421  $labels = $this->_get_address_element_labels();
422 
423  for ($i = 0; $i < count($labels); $i++) {
424  $key = $labels[$i];
425  $new_tags[$key] = $this->address_elements[$key];
426  }
427 
428  return $this->set_tags($new_tags);
429  }

References _get_address_element_labels(), and CO_Main_DB_Record\set_tags().

Here is the call graph for this function:

Member Data Documentation

◆ $address_elements

CO_Place::$address_elements = Array()

These are the address elements we use for creating lookup addresses.

Definition at line 47 of file co_place.class.php.

◆ $google_geocode_uri_prefix

CO_Place::$google_geocode_uri_prefix = NULL

This is the Geocode URI for the Google Geocode.

Definition at line 48 of file co_place.class.php.

◆ $google_lookup_uri_prefix

CO_Place::$google_lookup_uri_prefix = NULL

This is the lookup URI for the Google reverse Geocode.

Definition at line 49 of file co_place.class.php.

◆ $region_bias

CO_Place::$region_bias = NULL

This can be set by subclasses in order to set a region bias.

Definition at line 50 of file co_place.class.php.

Referenced by __construct().