SLP_Premier_Territory
extends SLPlus_BaseClass_Object
in package
Define a territory
Tags
Table of Contents
Properties
- $addon : SLP_Premier
- $myslp : MySLP
- $points : mixed
- $slplus : SLPlus
- $uses_myslp : bool
- $uses_slplus : bool
- $slug : mixed
Methods
- __construct() : mixed
- __get() : SLPlus_BaseClass_Object
- __isset() : bool
- clear_custom_ajax_sql_settings() : mixed
- Clear the custom AJAX execute_location_query settings.
- clear_points() : mixed
- Clear all points.
- delete_private_points() : mixed
- Delete private points.
- extend_sql() : string
- Extend the SQL query options.
- get_instance() : static
- Return an instance of the object which is also registered to the slplus global less the SLP_ part.
- get_points() : array<string|int, mixed>
- Get a simplified list of points that includes only the name, lat, lng.
- load_points_from_current_location() : mixed
- Setup the territory points from the current location.
- modify_having_clause() : string
- Change the having clause to compare distance to the territory radius.
- modify_select_all_with_distance() : string
- Modify the selectall_with_distance SQL clause from SLP.
- remove_distance_param() : mixed
- Remove the distance param when having clause is modified.
- remove_results_not_in_territory() : array<string|int, mixed>
- Remove results that are not in the territory.
- set_boundary_point() : mixed
- Set a boundary point to define the territory polygon. Moves the center to ensure a right-angle box.
- set_custom_ajax_sql_settings() : mixed
- Set the custom AJAX execute_location_query settings.
- set_location_search_queries() : array<string|int, mixed>
- Add the address within territory query to the stack of AJAX load/search queries on locations.
- set_marker_in_territory_property() : array<string|int, mixed>
- Add a marker property to note whether a location services the user's location.
- set_point() : mixed
- Set a boundary point to define the territory polygon by calcualting the hypotenuse creatin an irregular box.
- set_properties() : mixed
- Set our properties.
- set_territory_bounds() : array<string|int, mixed>
- Set new territory bounds based on the incoming data.
- sql_filter_where_territory_is_set() : string
- Add where clause to SQL when selecting locations. Filter out locations without territories.
- initialize() : mixed
- Do these things when this object is invoked. Override in your class.
- add_opposite_corners() : mixed
- Add the opposite corners to the rectangle polygon.
- add_point() : mixed
- Add a new lat/lng point.
- create_point_slug() : string
- Create a valid key slug for the point.
- get_bearing_degrees() : float|int
- Set the bearing in degrees as a float.
- get_bearing_distance() : float|int
- Set the bearing in degrees as a float.
- is_lat_long_in_territory() : bool
- Return true if a given lat/long is inside the current location territory.
- load_points_from_bounds() : mixed
- Setup territory points from a given serialized array of bounds.
Properties
$addon
public
SLP_Premier
$addon
$myslp
public
MySLP
$myslp
$points
public
mixed
$points
$slplus
public
SLPlus
$slplus
$uses_myslp
public
bool
$uses_myslp
Set to true to add a $myslp property pointing to global $myslp
$uses_slplus
public
bool
$uses_slplus
Set to true (default) if the object needs access to the SLPlus plugin object.
$slug
protected
mixed
$slug
Methods
__construct()
public
__construct([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
__get()
public
__get(string $property) : SLPlus_BaseClass_Object
Parameters
- $property : string
Return values
SLPlus_BaseClass_Object__isset()
public
__isset(string $property) : bool
Parameters
- $property : string
Return values
boolclear_custom_ajax_sql_settings()
Clear the custom AJAX execute_location_query settings.
public
clear_custom_ajax_sql_settings(string $query_slug) : mixed
Parameters
- $query_slug : string
clear_points()
Clear all points.
public
clear_points() : mixed
delete_private_points()
Delete private points.
public
delete_private_points(mixed $name) : mixed
Parameters
- $name : mixed
extend_sql()
Extend the SQL query options.
public
extend_sql(string $sql_slug) : string
Parameters
- $sql_slug : string
-
the SQL statement/snippet slug
Return values
string —the formal SQL command
get_instance()
Return an instance of the object which is also registered to the slplus global less the SLP_ part.
public
static get_instance([bool $no_global = false ][, mixed $params = array() ]) : static
Parameters
- $no_global : bool = false
-
set to true to skip assigning object to SLP global as a property.
- $params : mixed = array()
-
object init params
Return values
staticget_points()
Get a simplified list of points that includes only the name, lat, lng.
public
get_points([bool $all = false ]) : array<string|int, mixed>
Parameters
- $all : bool = false
-
if true return all points, even private ones.
Return values
array<string|int, mixed>load_points_from_current_location()
Setup the territory points from the current location.
public
load_points_from_current_location() : mixed
modify_having_clause()
Change the having clause to compare distance to the territory radius.
public
modify_having_clause(array<string|int, string> $having_clause, string $query_slug) : string
Parameters
- $having_clause : array<string|int, string>
-
prior having clause elements
- $query_slug : string
-
the query slug
Return values
stringmodify_select_all_with_distance()
Modify the selectall_with_distance SQL clause from SLP.
public
modify_select_all_with_distance(string $sql) : string
Parameters
- $sql : string
Return values
string —The modified select all statement.
remove_distance_param()
Remove the distance param when having clause is modified.
public
remove_distance_param(mixed $default_query_parameters, mixed $query_slug) : mixed
Parameters
- $default_query_parameters : mixed
- $query_slug : mixed
-
\
remove_results_not_in_territory()
Remove results that are not in the territory.
public
remove_results_not_in_territory(array<string|int, mixed> $results) : array<string|int, mixed>
Parameters
- $results : array<string|int, mixed>
Return values
array<string|int, mixed> —$results
set_boundary_point()
Set a boundary point to define the territory polygon. Moves the center to ensure a right-angle box.
public
set_boundary_point(string $bearing, array<string|int, mixed> $data) : mixed
Parameters
- $bearing : string
-
Either a cardinal direction 'nw', 'ne' , 'se' , 'sw' or a bearing in degrees (0 to 360).
- $data : array<string|int, mixed>
-
The extended data being added.
set_custom_ajax_sql_settings()
Set the custom AJAX execute_location_query settings.
public
set_custom_ajax_sql_settings(string $query_slug) : mixed
Parameters
- $query_slug : string
set_location_search_queries()
Add the address within territory query to the stack of AJAX load/search queries on locations.
public
set_location_search_queries(array<string|int, mixed> $queries) : array<string|int, mixed>
Parameters
- $queries : array<string|int, mixed>
-
the standard query
Return values
array<string|int, mixed> —the standard query PLUS the address within territory query
set_marker_in_territory_property()
Add a marker property to note whether a location services the user's location.
public
set_marker_in_territory_property(array<string|int, mixed> $marker) : array<string|int, mixed>
Parameters
- $marker : array<string|int, mixed>
Return values
array<string|int, mixed> —$marker
set_point()
Set a boundary point to define the territory polygon by calcualting the hypotenuse creatin an irregular box.
public
set_point(string $bearing, array<string|int, mixed> $data, string $starting_lat, string $starting_long, bool $private) : mixed
This ensures the location is in the center of the territory but the polygon prescribed is an AVERAGE distance from the location.
Parameters
- $bearing : string
-
Either a cardinal direction or a bearing in degrees (0 to 360).
- $data : array<string|int, mixed>
-
The extended data being added.
- $starting_lat : string
-
The starting point latitude.
- $starting_long : string
-
The starting point longitude.
- $private : bool
-
Is this a private point?
set_properties()
Set our properties.
public
set_properties([array<string|int, mixed> $options = array() ]) : mixed
Parameters
- $options : array<string|int, mixed> = array()
set_territory_bounds()
Set new territory bounds based on the incoming data.
public
set_territory_bounds(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>
-
The new data to be written.
Return values
array<string|int, mixed> —$data The data with the new territory bounds.
sql_filter_where_territory_is_set()
Add where clause to SQL when selecting locations. Filter out locations without territories.
public
sql_filter_where_territory_is_set(string $where_clause) : string
Parameters
- $where_clause : string
Return values
stringinitialize()
Do these things when this object is invoked. Override in your class.
protected
initialize() : mixed
add_opposite_corners()
Add the opposite corners to the rectangle polygon.
private
add_opposite_corners() : mixed
SW/NE assumed, find NW, SE corners.
add_point()
Add a new lat/lng point.
private
add_point(string $name, string $lat, string $lng[, bool $private = false ]) : mixed
Parameters
- $name : string
-
Name of the point.
- $lat : string
-
Latitude coordinate.
- $lng : string
-
Longitude coordinate.
- $private : bool = false
-
true if a temporary point
create_point_slug()
Create a valid key slug for the point.
private
create_point_slug(string $point_label) : string
Parameters
- $point_label : string
-
The plain text label for the point.
Return values
stringget_bearing_degrees()
Set the bearing in degrees as a float.
private
get_bearing_degrees(string $bearing) : float|int
Parameters
- $bearing : string
-
'ne'|'se'|'sw'|'nw'|string representation of a float/int.
Return values
float|intget_bearing_distance()
Set the bearing in degrees as a float.
private
get_bearing_distance(string $bearing, array<string|int, mixed> $data) : float|int
Parameters
- $bearing : string
-
'ne'|'se'|'sw'|'nw'|string representation of a float/int.
- $data : array<string|int, mixed>
-
The extended data being added.
Return values
float|intis_lat_long_in_territory()
Return true if a given lat/long is inside the current location territory.
private
is_lat_long_in_territory(string $latitude, string $longitude) : bool
Assumes the points array is already setup.
Uses the crossing number algorithm or even-odd-rule algorithm. This is faster than using the circular algorithms such as the winding number algorithm. Circular algorithms use trigonometric functions such as sin, cos, etc. that are computationally expensive.
Parameters
- $latitude : string
- $longitude : string
Tags
Return values
boolload_points_from_bounds()
Setup territory points from a given serialized array of bounds.
private
load_points_from_bounds(string $bounds) : mixed
Parameters
- $bounds : string
-
serialized points (name, lat/lng per $points property here).