phpDocumentor SMap
[ class tree: SMap ] [ index: SMap ] [ all elements ]

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:
Abstract:  

Properties

Methods

[ Top ]
Constant Summary
CREATE_CACHED_RECT_BOUNDS   CREATE TABLE cached_rec_bounds SQL
CREATE_CACHED_RECT_INDEX   CREATE INDEX ON the rect bounds
DELETE_CACHED_RECT_BEFORE   DELETE session data before a given timestamp
INSERT_CACHED_RECT_DATA   INSERT a new bound in the cache
SELECT_CACHED_RECT_BY_KEY   SELECT a cached rect by key
SELECT_CACHED_RECT_IN_BOUND   SELECT a session rect by the a boundry that intersects it
TYP_LABEL   Some enumerations for types of rects

[ Top ]
Property Summary
object   $conn   Database connection

[ Top ]
Method Summary
void   connect()   Create the database connection
void   createCachedRectBounds()   CREATEs the cached_rec_bounds table
void   deleteCachedRectBefore()   DELETE all old cached data
void   insertCachedRectData()   INSERT new rectangle(s) into the cache
resource   prepare()   Prepare a statement
mixed   selectCachedRectByKey()   SELECT cached rect by its key
array   selectCachedRectInBounds()   SELECT a cached rect by the its intersection with another rect

[ Top ]
Properties
object   $conn = null [line 1199]

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:
Usedby:  SMap_Data::prepare()
Usedby:  SMap_Data::connect()
Access:  protected


[ Top ]
Methods
connect  [line 1214]

  void connect( )

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:
Usedby:  SMap_Data::prepare()
Access:  protected
Abstract:  
Uses:  SMap_Data::$conn


[ Top ]
createCachedRectBounds  [line 1221]

  void createCachedRectBounds( )

CREATEs the cached_rec_bounds table


API Tags:
Usedby:  SMap_Data::prepare()
Access:  protected
Uses:  SMap_Data_Ex


[ Top ]
deleteCachedRectBefore  [line 1314]

  void deleteCachedRectBefore( [integer $oldTime = 0]  )

DELETE all old cached data

Parameters:
integer   $oldTime:  Old timestamp

API Tags:
Access:  public


[ Top ]
insertCachedRectData  [line 1240]

  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:
Access:  public

Information Tags:
Throws:  SMap_Exception

[ Top ]
prepare  [line 1338]

  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:
Return:  Prepared statement
Access:  protected
Uses:  SMap_Data_Ex
Uses:  SMap_Data::createCachedRectBounds()
Uses:  SMap_Data::connect()
Uses:  SMap_Data::$conn


[ Top ]
selectCachedRectByKey  [line 1267]

  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


[ Top ]
selectCachedRectInBounds  [line 1291]

  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:
Return:  Any rectangles in the selection.
Usedby:  SMap_Object_Area_Label::drawLabels()
Access:  public


[ Top ]
Constants
CREATE_CACHED_RECT_BOUNDS =
'CREATE TABLE cached_rec_bounds (
map_key INTEGER NOT NULL,
rec_key INTEGER NOT NULL,

maxx REAL NOT NULL,
maxy REAL NOT NULL,
minx REAL NOT NULL,
miny REAL NOT NULL,

time INTEGER NOT NULL,
data TEXT NOT NULL,

PRIMARY KEY (map_key, rec_key))'
[line 1105]

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.


[ Top ]
CREATE_CACHED_RECT_INDEX =
'CREATE INDEX bounds ON cached_rec_bounds (map_key, maxx, minx)'
[line 1128]

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).


[ Top ]
DELETE_CACHED_RECT_BEFORE =
'DELETE
FROM cached_rec_bounds
WHERE time < :time'
[line 1180]

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


[ Top ]
INSERT_CACHED_RECT_DATA =
'INSERT IGNORE
INTO cached_rec_bounds (map_key, rec_key, maxx, maxy, minx, miny, data, time)
VALUES (:map_key, :rec_key, :maxx, :maxy, :minx, :miny, :data, :time)'
[line 1136]

INSERT a new bound in the cache

Parameters: map_key, rec_key, top, bottom, left, right, time


[ Top ]
SELECT_CACHED_RECT_BY_KEY =
'SELECT maxx, maxy, minx, miny, data, time
FROM cached_rec_bounds
WHERE map_key=:map_key AND rec_key=:rec_key'
[line 1148]

SELECT a cached rect by key

Parameters: map_key, rec_key

Results: maxx, maxy, minx, miny, time


[ Top ]
SELECT_CACHED_RECT_IN_BOUND =
'SELECT rec_key, maxx, maxy, minx, miny, data, time
FROM cached_rec_bounds
WHERE
map_key = :map_key AND
maxx >= :minx AND minx <= :maxx AND
maxy >= :miny AND miny <= :maxy'
[line 1163]

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


[ Top ]
TYP_LABEL = 1 [line 1188]

Some enumerations for types of rects


[ Top ]

Documentation generated on Mon, 09 Apr 2007 18:56:02 -0500 by phpDocumentor 1.3.0