PhpToolCase
Api Documentation Version 0.9.2
PtcMapper Class Reference

Public Member Functions

 __construct ()
 Retrives the query builder from the connection manager and table column names. More...
 
 reset ()
 Resets previously set values. More...
 
 remove ($key)
 Removes values from fields property. More...
 
 toArray ()
 Returns values as an associative array. More...
 
 toJson ()
 Returns values as a json array. More...
 
 delete ()
 Deletes record in table based on id. More...
 
 save ()
 Inserts a new record in table. More...
 
 __set ($key, $value)
 Sets values. More...
 
 __get ($key)
 Retrieves values. More...
 

Static Public Member Functions

static create ($array)
 Sets values based on associative array. More...
 
static find ($id)
 Retrieves single record from the table based on id. More...
 
static all ()
 Gets all records. More...
 
static getColumns ()
 Retrieves column names from table. More...
 
static observe ($class=null)
 Adds observers to the class to use event listeners with the queries. More...
 
static __callStatic ($method, $args)
 Calls shortcut methods for getting / setting single values, or the QueryBuilder methods directly. More...
 
static lastId ()
 Retrieves last inserted id. More...
 

Protected Member Functions

 _mapFields ()
 Replaces column names with values in the PtcMapper::$_map property. More...
 

Static Protected Member Functions

static _checkColumn ($column)
 Checks if a given column name exists in table. More...
 
static _fireEvent ($event, $data)
 Fires events if methods are present in observers classes. More...
 
static _getQB ()
 Retrieve the query builder object if present. More...
 
static _initialize ()
 Initializes the class, adding columns and table name to the PtcMapper::$_storage property. More...
 

Protected Attributes

 $_fields = array( )
 Array of created values property. More...
 

Static Protected Attributes

static $_table = null
 Database table property. More...
 
static $_uniqueKey = 'id'
 Unique row identifier column name. More...
 
static $_map = array( )
 Maps column names to fields, if "as" is used. More...
 
static $_eventClass = '\PtcEvent'
 Event class name property. More...
 
static $_connectionManager = 'PtcDb'
 Connection Manager class name property. More...
 
static $_connectionName ='default'
 Connection name to be used property. More...
 
static $_events
 Possible observer events array. More...
 
static $_observers = array( )
 Property that holds the observer classes. More...
 
static $_storage = array( )
 Column and table names property. More...
 

Constructor & Destructor Documentation

__construct ( )

Retrives the query builder from the connection manager and table column names.

Definition at line 18 of file PtcMapper.php.

Member Function Documentation

static __callStatic (   $method,
  $args 
)
static

Calls shortcut methods for getting / setting single values, or the QueryBuilder methods directly.

See Updating Single Values , Retrieving Single Values and Using The Query Builder Directly

Parameters
string$methodthe method name
array$argsan array with arguments for the method
Returns
the result of the query

Definition at line 194 of file PtcMapper.php.

__get (   $key)

Retrieves values.

Parameters
string$keythe column name

Definition at line 182 of file PtcMapper.php.

__set (   $key,
  $value 
)

Sets values.

Parameters
string$keythe column name
mixed$valuethe value

Definition at line 173 of file PtcMapper.php.

static _checkColumn (   $column)
staticprotected

Checks if a given column name exists in table.

Parameters
string$columnthe value to check
Returns
true if column exists, false otherwise

Definition at line 272 of file PtcMapper.php.

static _fireEvent (   $event,
  $data 
)
staticprotected

Fires events if methods are present in observers classes.

See Using Observer Events

Parameters
string$eventthe event name stored in the $_observers property
array$datain array with the data to pass to the listeners

Definition at line 289 of file PtcMapper.php.

static _getQB ( )
staticprotected

Retrieve the query builder object if present.

Definition at line 307 of file PtcMapper.php.

static _initialize ( )
staticprotected

Initializes the class, adding columns and table name to the PtcMapper::$_storage property.

See Adding Options On Initialization

Returns
the name of called class as string

Definition at line 317 of file PtcMapper.php.

_mapFields ( )
protected

Replaces column names with values in the PtcMapper::$_map property.

See Mapping Field Names

Definition at line 344 of file PtcMapper.php.

static all ( )
static

Gets all records.

See Retrieve All Records

Returns
an array with multiple instances of this class as rows

Definition at line 119 of file PtcMapper.php.

static create (   $array)
static

Sets values based on associative array.

See Adding Records

Parameters
array$arrayan associative array with values
Returns
the new created record

Definition at line 41 of file PtcMapper.php.

delete ( )

Deletes record in table based on id.

See Deleting Records

Returns
the number of affected rows

Definition at line 52 of file PtcMapper.php.

static find (   $id)
static

Retrieves single record from the table based on id.

See Retrieve Record Based On Id

Parameters
int$idthe record id
Returns
a new instance of this class.

Definition at line 106 of file PtcMapper.php.

static getColumns ( )
static

Retrieves column names from table.

Returns
an associative array with column names as keys

Definition at line 131 of file PtcMapper.php.

static lastId ( )
static

Retrieves last inserted id.

Definition at line 361 of file PtcMapper.php.

static observe (   $class = null)
static

Adds observers to the class to use event listeners with the queries.

See Using Observer Events

Parameters
string$classthe name of the class that will be used as observer

Definition at line 149 of file PtcMapper.php.

remove (   $key)

Removes values from fields property.

Parameters
string$keythe table column name

Definition at line 27 of file PtcMapper.php.

reset ( )

Resets previously set values.

Definition at line 22 of file PtcMapper.php.

save ( )

Inserts a new record in table.

See Adding Records and Updating Records

Returns
the numbr of affected rows

Definition at line 69 of file PtcMapper.php.

toArray ( )

Returns values as an associative array.

See Convert Values To Array

Definition at line 31 of file PtcMapper.php.

toJson ( )

Returns values as a json array.

See Convert Values To Json

Definition at line 35 of file PtcMapper.php.

Field Documentation

$_connectionManager = 'PtcDb'
staticprotected

Connection Manager class name property.

See Specify Connection Manager Class

Definition at line 242 of file PtcMapper.php.

$_connectionName ='default'
staticprotected

Connection name to be used property.

See Specify Connection To Use

Definition at line 246 of file PtcMapper.php.

$_eventClass = '\PtcEvent'
staticprotected

Event class name property.

See Specify Event Class

Definition at line 238 of file PtcMapper.php.

$_events
staticprotected
Initial value:
= array
(
'inserting' , 'inserted' , 'updating' , 'updated' ,
'deleting' , 'deleted' , 'saving' , 'saved'
)

Possible observer events array.

See Using Observer Events

Definition at line 250 of file PtcMapper.php.

$_fields = array( )
protected

Array of created values property.

Definition at line 266 of file PtcMapper.php.

$_map = array( )
staticprotected

Maps column names to fields, if "as" is used.

See Mapping Field Names

Definition at line 234 of file PtcMapper.php.

$_observers = array( )
staticprotected

Property that holds the observer classes.

Definition at line 258 of file PtcMapper.php.

$_storage = array( )
staticprotected

Column and table names property.

Definition at line 262 of file PtcMapper.php.

$_table = null
staticprotected

Database table property.

Definition at line 226 of file PtcMapper.php.

$_uniqueKey = 'id'
staticprotected

Unique row identifier column name.

Definition at line 230 of file PtcMapper.php.


The documentation for this class was generated from the following file: