Abstract Class StoredObject

Description

StoredObject

A base class that contains tools for storing and retrieving objects from a database

  • abstract:
  • access: public

Located in /include/classes/storeable-objects/StoredObject.inc (line 27)


	
			
Direct descendents
Class Description
 class Address (Mailing/Street) Address
 class Couple StoredObject
 class Income StoredObject
 class Organization StoredObject
 class Person StoredObject
 class PS_Comp **************************************************************
Variable Summary
 array $dirty
 array $fields
 string $primeField
 array $tableOrder
 array $tables
Method Summary
 StoredObject StoredObject (DB $db)
 int addTable (string $tableName, string $keyName, string $keyField, array $columnNames, array $fieldNames)
 mixed getGeneralData (string $key)
 mixed getID ()
 string getSelectByIDString (string $tableName, array $table, boolean $multi, int $m)
 mixed insertNew ()
 mixed postToDB ()
 void remove ()
 void removeTable (mixed $table, string $tableName)
 int retrieve (mixed $id)
 mixed searchDB ()
 int setGeneralData (string $key, mixed $value)
 int setID (mixed $id)
 mixed update (mixed $id)
Variables
DB $db (line 69)

Database Abstraction Connection

  • access: private
array $dirty (line 49)

What fields are out of date with the DB

  • access: private
array $fields (line 41)

Storeable member variables

  • access: private
array $fieldsToTables (line 53)

Mapping member variabbles to column(s) in the DB's table(s)

  • access: private
string $primeField (line 34)

Acts as DB primary key

  • access: private
array $tableOrder (line 61)

Order in which tables should be processed

  • access: private
array $tables (line 45)

List of tables in the DB that the subtype uses

  • access: private
array $tablesToFields (line 57)

Inverse mapping of StoredObject::$fieldsToTables

  • access: private
Methods
Constructor StoredObject (line 75)

StoredObject Constructor

StoredObject StoredObject (DB $db)
  • DB $db: the databasse to interact with
addTable (line 657)

Register a table with the Object Relational Mapper.

Normally used in the constructor of a subtype to configure the table->fields mapping.

  • return: 1 on success, 0 on failure
  • access: protected
int addTable (string $tableName, string $keyName, string $keyField, array $columnNames, array $fieldNames)
  • string $tableName: the name of the table to register
  • string $keyName: the primary key column in the database
  • string $keyField: the name of the corresponding field
  • array $columnNames: a list of other columns to include
  • array $fieldNames: a list of fields, index matched against $columnNames
getGeneralData (line 587)

Generic Getter.

Returns the value of the requested member variable.

  • return: the value of $key
  • todo: add check for $key in fields.
  • access: public
mixed getGeneralData (string $key)
  • string $key: member variable name
getID (line 599)

Get Primary Key.

Returns the value of the object's database primary key

  • return: the primary key value, or null if the item hasn't been saved
  • access: public
mixed getID ()
getSelectByIDString (line 102)

Generate a select statement for a given table.

Generates a select statement, selecting all registered columns from a given single table, by the tables's primary key columnm.

  • return: a full SELECT statement
  • todo: why passing $table not using $this->tables[$tableName]?
  • todo: why not default $multi and $m
  • access: private
string getSelectByIDString (string $tableName, array $table, boolean $multi, int $m)
  • string $tableName: the table a SELECT is needed for
  • array $table: information about the table
  • boolean $multi: do we need to subindex the member variables
  • int $m: the subindex to use
insertNew (line 237)

INSERTS the object to the Database.

INSERTS into the database to bring the db upto date with the state of the object. Does NOT do any checking for stale data.

  • return: the primary key of the object
  • access: private
mixed insertNew ()
postToDB (line 213)

Save/Update the object to the Database.

Either INSERTS or UPDATES, as appropriate, into the database to bring the db upto date with the state of the object. Does NOT do any checking for stale data.

Clears the status of all dirty bits to reflect clean status.

  • return: the primary key of the object
  • access: public
mixed postToDB ()

Redefined in descendants as:
remove (line 125)

Remove this stored object from the database.

Completely remove this stored object from the database. This method relies on the the ON DELETE behavoir of the referenced tabes to work. Only the row referenced by the primeField is deleted, directly.

  • todo: add error reporting when ON DELETE RESTRICT?
  • access: public
void remove ()
removeTable (line 703)

De-Register a table with the Object Relational Mapper.

Provided for symmetry -- never used I beleive....

  • access: protected
void removeTable (mixed $table, string $tableName)
  • string $tableName: the name of the table to de-register
retrieve (line 143)

Load the identified records into memory.

Fetch the referenced object from the database. If an $id is passed in use that, if not, attempt to use $this->getID, if neither fail.

  • return: 1 on success, 0 on fail
  • access: public
int retrieve (mixed $id)
  • mixed $id: the primary key of the object to load

Redefined in descendants as:
searchDB (line 513)

Search on non-key data.

Searches for matching record(s) using whatever fields have been set.

  • return: 0 on no match, list of primary keys if found
  • access: public
mixed searchDB ()
setGeneralData (line 614)

Generic Setter.

Updates the referenced member variable to the new value and sets the dirty bit for the member variable.

  • return: 1 on success, 0 otherwise
  • access: public
int setGeneralData (string $key, mixed $value)
  • string $key: member variable name
  • mixed $value: the value to set member variable $key to
setID (line 636)

Prime ID Setter.

Normally only used to set the ID before called retrieve, support is questionable, probably broken for changing an items primary key via this.

  • return: 1 on success
  • access: public
int setID (mixed $id)
  • mixed $id: the prime key to use
update (line 347)

UPDATES the object to the Database.

UPDATES into the database to bring the db upto date with the state of the object. (This can include some INSERTS/DELETES when dealingn with multi-valued variables -- aka lists.

  • return: the primary key of the object
  • access: private
mixed update (mixed $id)

Documentation generated on Tue, 25 Apr 2006 13:11:11 -0400 by phpDocumentor 1.3.0RC3