Class: SMap_Data
Source Location: /SMap.php
Class SMap_Data
Class Overview
|
We need to connect to the DB somehow, all relevant methods are defined here.
I've defined some basic SQL queries as constants, feel free to use them or abuse them as needed. The selects are all prepared statements and should be usable with PEAR's DB. It is my intent to make these statements simple enough to be usable with both SQLite and MySQL while still maintaining functionality. I am aware that people may want more powerful syntax, and they are encouraged to extend this class.
Located in /SMap.php [line 1092]
Author(s):
API Tags:
|
Properties
|
Methods
|
Constant Summary
| TYP_LABEL |
Some enumerations for types of rects |
Property Summary
| object |
$conn |
Database connection |
Method Summary
| void |
connect() |
Create the database connection |
| resource |
prepare() |
Prepare a statement |
Properties
Database connection
The currently defined functions expect this to be an instance of PHP's PDO, but you can override them and use whatever database/schema that you wish. API Tags:
Methods
Create the database connection
Currently, the other functions expect this to create a new instance of PDO and save it at $this->conn. We'll attempt to worry about a lack of table as they are needed (queries fail, exceptions ocour). The connection is automatically generated when you call prepare(), but if the need arises in your code, feel free to call whenever.
API Tags:
void createCachedRectBounds(
)
|
|
CREATEs the cached_rec_bounds table
API Tags:
void deleteCachedRectBefore(
[integer
$oldTime = 0]
)
|
|
DELETE all old cached data
Parameters:
|
integer |
$oldTime: |
Old timestamp |
API Tags:
void insertCachedRectData(
array
$newRects
)
|
|
INSERT new rectangle(s) into the cache
The parameter is an array of new rectangle(s) to insert into the cache. The new array should have keys for: ['map_key'], ['rec_key'], ['maxx'], ['maxy'], ['minx'], ['miny'].
Parameters:
|
array |
$newRects: |
Input data |
API Tags:
Information Tags:
resource prepare(
string
$sql
)
|
|
Prepare a statement
All statements should be prepared before execution. Besides being prepared, we check here to ensure that a DB connection exists, and that the tables exist in the DB.
Parameters:
|
string |
$sql: |
SQL statement to prepare |
API Tags:
mixed selectCachedRectByKey(
string
$mapKey, string
$recKey
)
|
|
SELECT cached rect by its key
Parameters:
|
string |
$mapKey: |
A key that identifies the map the rect is on. |
|
string |
$recKey: |
A key that identifies the specific rectangle. |
API Tags:
| Return: | Array on result or null on no result |
| Access: | public |
array selectCachedRectInBounds(
string
$mapKey, array
$B
)
|
|
SELECT a cached rect by the its intersection with another rect
Parameters:
|
string |
$mapKey: |
A string to identify the map we are looking in. |
|
array |
$B: |
Selection bounds |
API Tags:
Constants
CREATE TABLE cached_rec_bounds SQL
Rectangle bounds data is stored here across sessions. We need a map_id and bound_id to identify the bound that we are interested in, and most of our lookups will be selecting for either map_key and rec_key, or all bounds of a given map_key that fall in a given bounds. The former is preferred for performance reasons, though. For a given set of bounds, there should be a unique map_key, rec_key pair, and for the pair, there should be unique bounds.
CREATE INDEX ON the rect bounds
I think that only one of top-bottom / left-right indices will be useful and all four indices is overkill (and will delay inserts). So I'm going to choose to keep the left-right index under the assumption that most maps will be wider than they are tall (same with monitors).
DELETE session data before a given timestamp
The session results are calculated from the position of objects on the map, and should be recalculated depending on how often the objects change. Parameter: time
INSERT a new bound in the cache
Parameters: map_key, rec_key, top, bottom, left, right, time
SELECT a cached rect by key
Parameters: map_key, rec_key Results: maxx, maxy, minx, miny, time
SELECT a session rect by the a boundry that intersects it
This SQL assumes that up is positive Y and right is positive X (like the latitude/longitude coordinate system). Parameters: map_key, maxx, maxy, minx, miny Results: rec_key, maxx, maxy, minx, miny, data, time
Some enumerations for types of rects
|
|