Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
Public Member Functions | Static Public Member Functions | Data Fields
Dataface_IO Class Reference

Public Member Functions

 Dataface_IO ($tablename, $db=null, $altTablename=null)
 __destruct ()
getParentIO ()
loadRecordById ($recordid)
 recordid2query ($recordid)
 read ($query='', &$record, $tablename=null)
 delete (&$record, $secure=false)
 saveTransients (Dataface_Record $record, $keys=null, $tablename=null, $secure=false)
 write (&$record, $keys=null, $tablename=null, $secure=false)
 getHistoryComments (&$record)
 recordExists (&$record, $keys=null, $tablename=null)
 _update (&$record, $keys=null, $tablename=null, $secure=false)
 _insert (&$record, $tablename=null, $secure=false)
 _writeRelationship ($relname, $record)
 performSQL ($sql)
 addRelatedRecord (&$record, $secure=false)
 addExistingRelatedRecord (&$record, $secure=false)
 removeRelatedRecord (&$related_record, $delete=false, $secure=false)
 copy (&$sourceRecord, &$destParent, $destRelationship=null, $deepCopy=false)
 fireBeforeSave (&$record)
 fireAfterSave (&$record)
 fireBeforeUpdate (&$record)
 fireAfterUpdate (&$record)
 fireBeforeInsert (&$record)
 fireAfterInsert (&$record)
 fireBeforeAddRelatedRecord (&$record)
 fireAfterAddRelatedRecord (&$record)
 fireBeforeAddNewRelatedRecord (&$record)
 fireAfterAddNewRelatedRecord (&$record)
 fireBeforeAddExistingRelatedRecord (&$record)
 fireAfterAddExistingRelatedRecord (&$record)
 fireBeforeDelete (&$record)
 fireAfterDelete (&$record)
 fireEvent ($name, &$record, $bubble=true)
 tablename ($tablename=null)
 importData (&$record, $data, $importFilter=null, $relationshipName=null, $commit=false, $defaultValues=array())

Static Public Member Functions

static touchRecord (Dataface_Record $record=null)
static createRecordMtimes ()
static & getByID ($uri, $filter=null)
static setByID ($uri, $value)
static createModificationTimesTable ()
static touchTable ($table)

Data Fields

 $_table
 $_serializer
 $insertIds = array()
 $lang
 $dbObj
 $parentIO = -1
 $fireTriggers = true
 $lastVersionNumber = null
 $_altTablename = null

Detailed Description

Definition at line 56 of file IO.php.

Constructor & Destructor Documentation

__destruct ( )

Definition at line 86 of file IO.php.

Member Function Documentation

_insert ( $record,
  $tablename = null,
  $secure = false 
)
Parameters
tablenameOptional tablename where record can be inserted. Should have same schema as the main table.

Definition at line 1057 of file IO.php.

_update ( $record,
  $keys = null,
  $tablename = null,
  $secure = false 
)
Parameters
tablenameAn optional tablename to update. This is useful if we are working from an update or delete table.

Definition at line 880 of file IO.php.

_writeRelationship (   $relname,
  $record 
)

Definition at line 1178 of file IO.php.

addExistingRelatedRecord ( $record,
  $secure = false 
)

Adds an existing record to a relationship.

Parameters
$recorda Dataface_RelatedRecord object to be added.

Definition at line 1543 of file IO.php.

addRelatedRecord ( $record,
  $secure = false 
)

Adds a new record to a relationships.

Parameters
$recordA Dataface_RelatedRecord object to be added.

Definition at line 1411 of file IO.php.

copy ( $sourceRecord,
$destParent,
  $destRelationship = null,
  $deepCopy = false 
)

Copies a record from a relationship in one parent record to another. Copies are a little bit difficult to define in a relational database, but, this copy uses a few rules to make it more clear.

Note that this method is not implemented yet.. it will throw and error if called.

  • A deep copy will recursively perform deep copies of records in one-to-many relationships, and maintain links to records in many-to-many relationships.
  • A shallow copy (default behavior) maintains links to records in many-to-many relationships and recursively performs shallow copies of all records in "children" relationships.
Parameters
Dataface_RelatedRecord&$sourceRecordThe record that is being copied.
Dataface_Record&$destParentThe record that will be the parent of the copied record. I.e. this is the destination of the copy.
string$destRelationshipThe name of the relationship into which the record is to be copied. If this parameter is left null, it will automatically use the relationship specified as a "children" relationship. If no "children" relationship can be found, then an error will be thrown.
boolean$deepCopyIf true then a deep copy will be performed. Otherwise the default behavior is to perform a shallow copy.
Returns
mixed Returns a PEAR_Error object if the copy fails.

Definition at line 1903 of file IO.php.

static createModificationTimesTable ( )
static

Definition at line 2549 of file IO.php.

static createRecordMtimes ( )
static

Definition at line 753 of file IO.php.

Dataface_IO (   $tablename,
  $db = null,
  $altTablename = null 
)

Definition at line 77 of file IO.php.

delete ( $record,
  $secure = false 
)

Deletes a record from the database.

Parameters
Dataface_Record$recordDataface_Record object to be deleted.
boolean$secureWhether to check permissions.
Returns
mixed true if successful, or PEAR_Error if failed.

Definition at line 270 of file IO.php.

fireAfterAddExistingRelatedRecord ( $record)

Calls the afterAddExistingRelatedRecord() method in the delegate class.

Parameters
$recordDataface_RelatedRecord object that is being added.

Definition at line 2005 of file IO.php.

fireAfterAddNewRelatedRecord ( $record)

Calls the afterAddNewRelatedRecord() method in the delegate class.

Parameters
$recordDataface_RelatedRecord object that is being added.

Definition at line 1989 of file IO.php.

fireAfterAddRelatedRecord ( $record)

Calls the afterAddRelatedRecord() method in the delegate class.

Parameters
$recordDataface_RelatedRecord object that is being added.

Definition at line 1972 of file IO.php.

fireAfterDelete ( $record)

Calls the afterDelete method in the delegate class.

Parameters
$recordDataface_Record object to be deleted.

Definition at line 2021 of file IO.php.

fireAfterInsert ( $record)

Calls the afterInsert() method in the delegate class.

Parameters
$recordDataface_Record object that is being inserted.

Definition at line 1956 of file IO.php.

fireAfterSave ( $record)

Calls the afterSave() method in the delegate class.

Parameters
$recordDataface_Record object that is being saved.

Definition at line 1923 of file IO.php.

fireAfterUpdate ( $record)

Calls the afterUpdate() method in the delegate class.

Parameters
$recordDataface_Record object that is being updated.

Definition at line 1940 of file IO.php.

fireBeforeAddExistingRelatedRecord ( $record)

Calls the beforeAddExistingRelatedRecord() method in the delegate class.

Parameters
$recordDataface_RelatedRecord object that is being added.

Definition at line 1997 of file IO.php.

fireBeforeAddNewRelatedRecord ( $record)

Calls the beforeAddNewRelatedRecord() method in the delegate class.

Parameters
$recordDataface_RelatedRecord object that is being added.

Definition at line 1981 of file IO.php.

fireBeforeAddRelatedRecord ( $record)

Calls the beforeAddRelatedRecord() method in the delegate class.

Parameters
$recordDataface_RelatedRecord object that is being added.

Definition at line 1964 of file IO.php.

fireBeforeDelete ( $record)

Calls the beforeDelete() method in the delegate class.

Parameters
$recordDataface_Record object to be deleted.

Definition at line 2013 of file IO.php.

fireBeforeInsert ( $record)

Calls the beforeInsert() method in the delegate class.

Parameters
$recordDataface_Record object that is being inserted.

Definition at line 1948 of file IO.php.

fireBeforeSave ( $record)

Calls the beforeSave() method in the delegate class.

Parameters
$recordDataface_Record object that is being saved.

Definition at line 1915 of file IO.php.

fireBeforeUpdate ( $record)

Calls the beforeUpdate() method in the delegate class.

Parameters
$recordDataface_Record object that is being updated.

Definition at line 1931 of file IO.php.

fireEvent (   $name,
$record,
  $bubble = true 
)

Fires an event (a method of the delegate class).

Parameters
$nameThe name of the event (also the name of the method in the delegate class.
$recordEither a Dataface_Record or Dataface_RelatedRecord object depending on context.

Definition at line 2030 of file IO.php.

static& getByID (   $uri,
  $filter = null 
)
static

Returns a record or record value given it's unique URI.

Parameters
string$uriThe URI of the data we wish to retrieve. The URI must be of one of the following forms: tablename?key1=val1&keyn=valn::fieldname tablename?key1=val1&keyn=valn tablename/relationshipname?key1=val1&keyn=valn&relationshipname::relatedkey=relatedval::fieldname tablename/relationshipname?key1=val1&keyn=valn&relationshipname::relatedkey=relatedval

Where url encoding is used as in normal HTTP urls. If a field is specified (after the '#')

Parameters
string$filterThe name of a filter to pass the data through. This is only applicable when a field name is specified. Possible filters include: strval - Returns the string value of the field. (aka stringValue, getValueAsString) display - Returns the display value of the field. (This substitutes valuelist values) htmlValue - Returns the html value of the field. preview - Returns the preview value of the field (usually this limits the length of the output and strips any HTML.
Returns
mixed Either a Dataface_Record object, a Dataface_RelatedRecord object of a value as stored in the object. The output depends on the input. If it receives invalid input, it will return a PEAR_Error object.

Example usage:

// Get record from Users table with UserID=10 $user =& Dataface_IO::getByID('Users?UserID=10'); // Dataface_Record object

// get birthdate of user with UserID=10 $birthdate =& Dataface_IO::getByID('Users?UserID=10#birthdate'); // array('year'=>'1978','month'=>'12','day'=>'27', ...)

// get related record from jobs relationship of user with UserID=10 // where the jobtitle is "cook" $job =& Dataface_IO::getByID('Users?UserID=10&jobs::jobtitle=cook"); // Dataface_RelatedRecord object

// Get the employers name of the cook job $employername = Dataface_IO::getByID('Users?UserID=10&jobs::jobtitle=cook::employername'); // String

// Add filter, so we get the HTML value of the bio field rather than just // the raw value. $bio = Dataface_IO::getByID('Users?UserID=10#bio', 'htmlValue');

Definition at line 2459 of file IO.php.

getHistoryComments ( $record)

Definition at line 761 of file IO.php.

& getParentIO ( )

Definition at line 97 of file IO.php.

importData ( $record,
  $data,
  $importFilter = null,
  $relationshipName = null,
  $commit = false,
  $defaultValues = array() 
)

Imports data into the supplied record's relationship. This makes use of this table's delegate file to handle the importing.

Parameters
$recordA Dataface_Record object whose relationship is to have records added to it. Dataface_Record | null
$dataEither raw data that is to be imported, or the name of an Import table from which data is to be imported. Raw | string
$importFilterThe name of the import filter that should be used. string
$relationshipNameThe name of the relationship where these records should be added. string
$commitA boolean value indicating whether this import should be committed to the database. If this is false, then the records will not actually be imported. They will merely be stored in an import table. This must be explicitly set to true for the import to succeed. boolean
defaultValuesArray of default values of the form [Abs fieldname] -> [field value], where 'Abs fieldname' is the absolute field name (ie: tablename.fieldname). All imported records will attain these default values. array([string] -> [mixed])
Returns
Case 1: The import succeeds. Case 1.1: if commit = false return Import Table name where data is stored. Case 1.2: If commit = true return array of Dataface_Record objects that were inserted. Case 2: The import failed return PEAR_Error object.

Usage:

$data = '<phonelist> <listentry> <name>John Smith</name><number>555-555-5555</number> </listentry> <listentry> <name>Susan Moore</name><number>444-444-4444</number> </listentry> </phonelist>';

// assume that we have an import filter called 'XML_Filter' that can import the above data.

$directory = new Dataface_Record('Directory', array('Name'=>'SFU Directory')); // assume that the Directory table has a relationship called 'phonelist' and we want to // import the above data into this relationship.

$io = new Dataface_IO('Directory'); $importTableName = $io->importData( $directory, // The record that owns the relationship where imported records will be added $data, // The raw data to import 'XML_Filter', // The name of the impot 'phonelist' ); // Since we didn't set the $commit flag, the data has been imported into an import table // whose name is stored now in $importTableName.

// // Now suppose we have confirmed that the import is what we want to do and we are ready to import // the data into the database. $records = $io->importData($directory, $importTableName, null, 'phonelist', true );

echo $records[0]->val('name'); // should output 'John Smith' echo $records[0]->val('number'); // should output '555-555-5555' echo $records[1]->val('name'); // should output 'Susan Moore' echo $records[1]->val('number'); // should output '444-444-4444'

// note that at this point the records in $records are already persisted to the database

Definition at line 2159 of file IO.php.

& loadRecordById (   $recordid)

Loads a record given an ID. The ID resembles a URL that describes a record based on the table, relationship, and keys of the record. E.g.: table/relationship?key1=val1&key2=val2&relationship::key1=val3

Parameters
string$recordidThe record id of the record to load.
mixedA Dataface_Record object if the id refers to a record. A Dataface_RelatedRecord object if the id refers to a related record. Or null if no such record is found.
Since
0.6.1

Definition at line 130 of file IO.php.

performSQL (   $sql)

Takes an array of SQL query strings and performs them sequentially. Will replace special value "__Tablename__auto_increment__" with the insert_id from the table "Tablename" if one of the provided sql queries inserts a record into Tablename.

Parameters
$sqlAn associative array [Table name] -> [SQL Query] of sql statements to be executed.

There is a foreign key constraint that is preventing us from inserting this row. Perhaps we are just adding this row in the wrong order. Let's re-add it to the queue.

Definition at line 1302 of file IO.php.

read (   $query = '',
$record,
  $tablename = null 
)

Reads result of query into the table.

Parameters
mixed$queryEither an array of query parameters or a record id string identifying a record to load.
&$recordThe record object into which to load our results.
string$tablenameAn optional table name from which the record could be read. For example, a record may be read form an import table rather than the real table. (or a deleted table).

Definition at line 176 of file IO.php.

recordExists ( $record,
  $keys = null,
  $tablename = null 
)

Returns true if the record currently represented in the Table already exists in the database.

Parameters
tablenameAlternative table where records may be stored. This is useful if we are reading form import or delete tables.

Definition at line 783 of file IO.php.

recordid2query (   $recordid)

Converts a record id to a query array. A record id is a string of the form tablename/relationshipname?key1=val1&key2=val2&relationshipname::key1=val3&relationshipname::key2=val4

Parameters
string$recordidThe record id to be converted.
Returns
array Associative array of query parameters.
Since
0.6.1

Definition at line 144 of file IO.php.

removeRelatedRecord ( $related_record,
  $delete = false,
  $secure = false 
)

Removes the given related record from its relationship.

Parameters
Dataface_RelatedRecord&$related_recordThe related record to be removed.
boolean$deleteIf true then the record will also be deleted from the database.
Since
0.6.1

Definition at line 1713 of file IO.php.

saveTransients ( Dataface_Record  $record,
  $keys = null,
  $tablename = null,
  $secure = false 
)

Definition at line 367 of file IO.php.

static setByID (   $uri,
  $value 
)
static

Sets a value by ID.

Definition at line 2529 of file IO.php.

tablename (   $tablename = null)

A convenience method that returns the given parameter (if it is not null) or $this->_tablename if the parameter $tablename is null. This is handy when we want to pass an alternate tablename to select(), etc... if it is supplied.

Definition at line 2077 of file IO.php.

static touchRecord ( Dataface_Record  $record = null)
static

Definition at line 739 of file IO.php.

static touchTable (   $table)
static

Definition at line 2558 of file IO.php.

write ( $record,
  $keys = null,
  $tablename = null,
  $secure = false 
)

Writes the values in the table to the database.

Parameters
tablenameAn optional tablename in case this record is not being placed in the standard table. For example, the record could be placed into an import table.
array$keysOptional array of keys to look up record to write to.
string$tablenameThe name of the table to write to, if not this table. This is useful for writing to import tables or other tables with identical schema.
boolean$secureWhether to check permissions or not.

Definition at line 634 of file IO.php.

Field Documentation

$_altTablename = null

An optional alther table that this object can work on. This is handy in case records have to read from and written to delete or import tables.

Definition at line 75 of file IO.php.

$_serializer

Definition at line 58 of file IO.php.

$_table

Definition at line 57 of file IO.php.

$dbObj

Definition at line 61 of file IO.php.

$fireTriggers = true

Definition at line 63 of file IO.php.

$insertIds = array()

Definition at line 59 of file IO.php.

$lang

Definition at line 60 of file IO.php.

$lastVersionNumber = null

Definition at line 68 of file IO.php.

$parentIO = -1

Definition at line 62 of file IO.php.


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