![]() |
Xataface 2.0
Xataface Application Framework
|
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 & | 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 | |
$_altTablename = null |
_insert | ( | &$ | record, |
$ | tablename = null , |
||
$ | secure = false |
||
) |
_update | ( | &$ | record, |
$ | keys = null , |
||
$ | tablename = null , |
||
$ | secure = false |
||
) |
addExistingRelatedRecord | ( | &$ | record, |
$ | secure = false |
||
) |
Adds an existing record to a relationship.
$record | a Dataface_RelatedRecord object to be added. |
addRelatedRecord | ( | &$ | record, |
$ | secure = false |
||
) |
Adds a new record to a relationships.
$record | A Dataface_RelatedRecord object to be added. |
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.
Dataface_RelatedRecord | &$sourceRecord | The record that is being copied. |
Dataface_Record | &$destParent | The record that will be the parent of the copied record. I.e. this is the destination of the copy. |
string | $destRelationship | The 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 | $deepCopy | If true then a deep copy will be performed. Otherwise the default behavior is to perform a shallow copy. |
Dataface_IO | ( | $ | tablename, |
$ | db = null , |
||
$ | altTablename = null |
||
) |
delete | ( | &$ | record, |
$ | secure = false |
||
) |
Deletes a record from the database.
Dataface_Record | $record | Dataface_Record object to be deleted. |
boolean | $secure | Whether to check permissions. |
fireAfterAddExistingRelatedRecord | ( | &$ | record | ) |
Calls the afterAddExistingRelatedRecord() method in the delegate class.
$record | Dataface_RelatedRecord object that is being added. |
fireAfterAddNewRelatedRecord | ( | &$ | record | ) |
Calls the afterAddNewRelatedRecord() method in the delegate class.
$record | Dataface_RelatedRecord object that is being added. |
fireAfterAddRelatedRecord | ( | &$ | record | ) |
Calls the afterAddRelatedRecord() method in the delegate class.
$record | Dataface_RelatedRecord object that is being added. |
fireAfterDelete | ( | &$ | record | ) |
Calls the afterDelete method in the delegate class.
$record | Dataface_Record object to be deleted. |
fireAfterInsert | ( | &$ | record | ) |
Calls the afterInsert() method in the delegate class.
$record | Dataface_Record object that is being inserted. |
fireAfterSave | ( | &$ | record | ) |
Calls the afterSave() method in the delegate class.
$record | Dataface_Record object that is being saved. |
fireAfterUpdate | ( | &$ | record | ) |
Calls the afterUpdate() method in the delegate class.
$record | Dataface_Record object that is being updated. |
fireBeforeAddExistingRelatedRecord | ( | &$ | record | ) |
Calls the beforeAddExistingRelatedRecord() method in the delegate class.
$record | Dataface_RelatedRecord object that is being added. |
fireBeforeAddNewRelatedRecord | ( | &$ | record | ) |
Calls the beforeAddNewRelatedRecord() method in the delegate class.
$record | Dataface_RelatedRecord object that is being added. |
fireBeforeAddRelatedRecord | ( | &$ | record | ) |
Calls the beforeAddRelatedRecord() method in the delegate class.
$record | Dataface_RelatedRecord object that is being added. |
fireBeforeDelete | ( | &$ | record | ) |
Calls the beforeDelete() method in the delegate class.
$record | Dataface_Record object to be deleted. |
fireBeforeInsert | ( | &$ | record | ) |
Calls the beforeInsert() method in the delegate class.
$record | Dataface_Record object that is being inserted. |
fireBeforeSave | ( | &$ | record | ) |
Calls the beforeSave() method in the delegate class.
$record | Dataface_Record object that is being saved. |
fireBeforeUpdate | ( | &$ | record | ) |
Calls the beforeUpdate() method in the delegate class.
$record | Dataface_Record object that is being updated. |
fireEvent | ( | $ | name, |
&$ | record, | ||
$ | bubble = true |
||
) |
Fires an event (a method of the delegate class).
$name | The name of the event (also the name of the method in the delegate class. |
$record | Either a Dataface_Record or Dataface_RelatedRecord object depending on context. |
static& getByID | ( | $ | uri, |
$ | filter = null |
||
) | [static] |
Returns a record or record value given it's unique URI.
string | $uri | The 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 '#')
string | $filter | The 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. |
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');
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.
$record | A Dataface_Record object whose relationship is to have records added to it. Dataface_Record | null |
$data | Either raw data that is to be imported, or the name of an Import table from which data is to be imported. Raw | string |
$importFilter | The name of the import filter that should be used. string |
$relationshipName | The name of the relationship where these records should be added. string |
$commit | A 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 |
defaultValues | Array 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]) |
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
& 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
string | $recordid | The record id of the record to load. |
mixed | A 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. |
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.
$sql | An 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.
read | ( | $ | query = '' , |
&$ | record, | ||
$ | tablename = null |
||
) |
Reads result of query into the table.
mixed | $query | Either an array of query parameters or a record id string identifying a record to load. |
&$record | The record object into which to load our results. | |
string | $tablename | An 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). |
recordExists | ( | &$ | record, |
$ | keys = null , |
||
$ | tablename = null |
||
) |
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
string | $recordid | The record id to be converted. |
removeRelatedRecord | ( | &$ | related_record, |
$ | delete = false , |
||
$ | secure = false |
||
) |
Removes the given related record from its relationship.
Dataface_RelatedRecord | &$related_record | The related record to be removed. |
boolean | $delete | If true then the record will also be deleted from the database. |
saveTransients | ( | Dataface_Record $ | record, |
$ | keys = null , |
||
$ | tablename = null , |
||
$ | secure = false |
||
) |
static setByID | ( | $ | uri, |
$ | value | ||
) | [static] |
tablename | ( | $ | tablename = null | ) |
write | ( | &$ | record, |
$ | keys = null , |
||
$ | tablename = null , |
||
$ | secure = false |
||
) |
Writes the values in the table to the database.
tablename | An 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 | $keys | Optional array of keys to look up record to write to. |
string | $tablename | The 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 | $secure | Whether to check permissions or not. |
$_altTablename = null |