Xataface 2.0
Xataface Application Framework
Public Member Functions | Data Fields
Dataface_Relationship Class Reference

Public Member Functions

 Dataface_Relationship ($tablename, $relationshipName, &$values)
fields ($includeAll=false, $includeTransient=false)
 hasField ($fieldname, $checkAll=false, $includeTransient=false)
 _init (&$rel_values)
 _normalizeColumns ()
 getName ()
 getSQL ($getBlobs=false, $where=0, $sort=0)
 getLabel ()
 Returns the label of this relationship. If the action:label directive is set for the relationship in the relationships.ini file, then it will use this. otherwise it will use the name of the relationship as a basis for determining the label.
 getSingularLabel ()
 Returns the label of this relationship as a singular term. This uses the action:singular_label directive from the relationships.ini file if available. Otherwise it will attempt to singularize the label as recieved from getLabel().
 supportsAddNew ()
 supportsAddExisting ()
 supportsRemove ()
 showTabsForAddNew ()
getSourceTable ()
keys ()
getDestinationTables ()
getTable ($field=null)
 getTableAlias ($tableName)
getField ($fieldname)
 getDomainSQL ()
 getDomainTable ()
 getForeignKeyValues ($values=null, $sql=null, $record=null)
 isNullForeignKey (&$val)
 getDistance ($table)
 getAddExistingFilters ()
 getAddableValues (&$record, $filter=array())
 _makeEquivalenceLabels (&$labels, &$values, &$sql_data)
 _makeEquivalenceLabels_rec (&$labels, &$values, &$root, &$parser_wrapper)
 getOrderColumn ()
 Returns the name of the column on which this relationship is ordered.
 isParentRelationship ()
 isChildrenRelationship ()
 isOneToMany ()
 isManyToMany ()

Data Fields

 $_name
 $_sourceTable
 $_destinationTables
 $_fieldTableLookup
 $_schema
 $_keys
 $_sql_generated = array()
 $_permissions = array()
 $app
 $_cache = array()
 $addNew
 $addExisting

Detailed Description

File: Dataface/Relationship.php Author: Steve Hannah <shannah@sfu.ca> Created: October 2005

Description: ------------- Encapsulates a relationship between two tables.

Definition at line 38 of file Relationship.php.


Member Function Documentation

_init ( &$  rel_values)

Initializes the relationship given an associative array of values that is produced by parsing the relationships.ini file.

Parameters:
$rel_valuesInitializing parameters for relationship. Possible keys include: __sql__ : An sql query to define the relationship.

Definition at line 202 of file Relationship.php.

_makeEquivalenceLabels ( &$  labels,
&$  values,
&$  sql_data 
)

Creates labels fields involved in an sql query that such that fields that have the same value have the same labels. This works by taking 2 references to arrays as parameters. The first parameter, $labels, will map Column names to label names, and the second parameter, $values, maps label names to values.

Parameters:
labelsOut parameter to map field names to labels.
valuesOut parameter to map labels to values.
sql_dataIn parameter - the sql data structure as returned by SQL_Parser::parse()

Definition at line 1374 of file Relationship.php.

_makeEquivalenceLabels_rec ( &$  labels,
&$  values,
&$  root,
&$  parser_wrapper 
)

The recursive part of the algorithm to make equivalence labels. See Table::_makeEquivalenceLabels()

Parameters:
labelsOut param to map field names to labels.
valuesOut param to map labels to values
rootReference to a node of the parse tree that we are currently dealing with.
parser_wrapperReference to the parser wrapper that can be used to operate on and query the parsed sql data structure (as returned by SQL_Parser::parse()

Definition at line 1405 of file Relationship.php.

_normalizeColumns ( )

Scans the columns of a relationship and resolves wildcards and unqualified column names into fully qualified column names.

Definition at line 393 of file Relationship.php.

Dataface_Relationship ( tablename,
relationshipName,
&$  values 
)

Constructor for the relationship.

Parameters:
$tablenameThe name of the source table. $relationshipName The name of the relationship
Anarray of initializing values. Usually produced by parsing the relationships.ini file.

Definition at line 104 of file Relationship.php.

& fields ( includeAll = false,
includeTransient = false 
)

Returns an array of names of fields in this relationship.

Parameters:
boolean$includeAllWhether to include all table fields involved. By default, only the specified columns are returned. If this flag is set to true, then all fields from all destination tables will be returned - including grafted fields.
Returns:
array

Definition at line 131 of file Relationship.php.

getAddableValues ( &$  record,
filter = array() 
)

Returns a valuelist of the records that can be added to this relationship.

Parameters:
Dataface_Record&$recordThe parent record.
array$queryA query to filter the possible records.
Returns:
array Associative array where the keys are of the form key1=value1&key2=value2 and the values are the title of the record.

Definition at line 1314 of file Relationship.php.

getAddExistingFilters ( )

Definition at line 1291 of file Relationship.php.

& getDestinationTables ( )

Returns array of references to all of the destination tables in this relationship.

Returns:
array(Dataface_Table)

Definition at line 854 of file Relationship.php.

getDistance ( table)

Returns the distance of a specified table from the current table in a relationship. Tables that are directly joined to the current table have a distance of 1. Tables in the relationship but not directly joined to the current table have a distance of 2 (for simplicity sake), and tables not found in the relationship have a distance of 999.

Parameters:
string$tableThe name of a table to check.

Definition at line 1281 of file Relationship.php.

getDomainSQL ( )

Returns an SQL query that will obtain the domain of this relationship. The Domain is slightly different than the actual relationship, in that it returns all eligible rows that can be added to the relationship (and rows already in the relationship).

Definition at line 974 of file Relationship.php.

getDomainTable ( )

Returns the name of the "domain table" for this relationship. The domain table is the main table that comprises the data of a related record. I.e., it is the destination table that is not a join table. The join tables serve to join the source table to the domain table.

Returns:
string Name of the domain table.

Definition at line 1100 of file Relationship.php.

& getField ( fieldname)

Returns the field definition for a field in the relationship.

Parameters:
string$fieldnameThe field name. This can be absolute or relative. (e.g. Absolute would be something like people.firstName, whereas relative would be something like firstName).
Returns:
array or null if field doesn't exist.

Definition at line 934 of file Relationship.php.

getForeignKeyValues ( values = null,
sql = null,
record = null 
)

Gets the values of the foreign keys of a particular relationship. This returns an associative array with the following structure: Array( "table1" => Array( "field1"=>"value1", "field2"=>"value2", ... ), "table2" => Array( "field1"=>"value1", "field2"=>"value2", ... ), ... );

Parameters:
relationship_nameThe name of the relationship
valuesSupplementary values passed as array with keys = absolute field names, values = serialized values.
sqlIf provided, this will be used as the select statement that we dissect. If true we parse out variables. If false, we simply return the variables to be parsed later.
Exceptions:
PEAR_Errorif there is insufficient values supplied for the foreign key to work.

Definition at line 1127 of file Relationship.php.

getLabel ( )

Returns the label of this relationship. If the action:label directive is set for the relationship in the relationships.ini file, then it will use this. otherwise it will use the name of the relationship as a basis for determining the label.

Returns:
string
See also:
getSingularLabel()

Definition at line 724 of file Relationship.php.

getName ( )

Definition at line 512 of file Relationship.php.

getOrderColumn ( )

Returns the name of the column on which this relationship is ordered.

This depends on the metafields:order directive of the relationships.ini file to set the column upon which the relationship should be ordered. If this is not set, then this method will return a PEAR_Error object.

Returns:
string The name of the column on which to sort this relationship by default. Note that if the metafields:order directive is not set in the relationships.ini file this will return a PEAR_Error object.
Since:
0.8
See also:
http://xataface.com/documentation/tutorial/getting_started/relationships
http://www.xataface.com/wiki/relationships.ini_file
Dataface_Record::moveUp()
Dataface_Record::moveDown()
Dataface_Record::sortRelationship()

Definition at line 1504 of file Relationship.php.

getSingularLabel ( )

Returns the label of this relationship as a singular term. This uses the action:singular_label directive from the relationships.ini file if available. Otherwise it will attempt to singularize the label as recieved from getLabel().

Returns:
string
See also:
df_singularize()

Definition at line 738 of file Relationship.php.

& getSourceTable ( )
Returns:
Dataface_Table

Definition at line 828 of file Relationship.php.

getSQL ( getBlobs = false,
where = 0,
sort = 0 
)

Returns the SQL query that can be used to obtain the related records of this relationship. Note that the value returned from this method cannot be passed directly to mysql_query(). It may still have unresolved wildcards and must be passed through Dataface_Record::parseString() to replace all wildcards.

Parameters:
getBlobsIf true then Blob columns will also be returned. Default is false. boolean
Returns:
SQL Query string

Definition at line 529 of file Relationship.php.

& getTable ( field = null)

Returns reference to table that contains the given field.

Parameters:
string$fieldThe name of the field.
Returns:
Dataface_Table

Definition at line 889 of file Relationship.php.

getTableAlias ( tableName)

Returns the alias for the given table according to the SQL used to define the relationship - or null.

Definition at line 916 of file Relationship.php.

hasField ( fieldname,
checkAll = false,
includeTransient = false 
)

Checks to see if the relationship has a field named $fieldname.

Parameters:
string$fieldnameThe name of the field that we are checking. This may be an absolute name or a relative name.
boolean$checkAllIf this is true then the method will return true if the field exists in the destination tables (even if the field is grafted). Otherwise it will only return true if the field is explicitly part of the relationship. e.g. __sql__ = "select personID, firstName from people where groupID='$groupID'"

In this relationship the lastName field may be part of the people table, but it is not explicitly selected in the relationship. So if we issue: $relationship->hasField('people.lastName'); // false $relationship->hasField('people.lastName', true); //true

Returns:
boolean

Definition at line 178 of file Relationship.php.

isChildrenRelationship ( )

indicates whether this relationship is a "children" relationship.

A children relationship generall implies that related records are children of the current record in the heirarchical structure. This is useful for data models where records have an inherent heirarchical structure (like a file system).

A relationship cann be declared to be a "children" relationship in the relationships.ini file by adding "meta:class = children"

Returns:
boolean True if the relationship is a children relationship.

Definition at line 1539 of file Relationship.php.

isManyToMany ( )

Indicates if this is a many-to-many relationship. A relationship must be either one-to-many or many-to-many. Many-to-many relationships are more flexible when it comes to copying records because their records can live in multiple relationships concurrently by simply adding a record to the join table.

Returns:
boolean True if the relationship is many-to-many.
Since:
0.6.1

Definition at line 1570 of file Relationship.php.

isNullForeignKey ( &$  val)

Definition at line 1268 of file Relationship.php.

isOneToMany ( )

Indicates if this is a one-to-many relationship. A one-to-many relationship must be handled differently when it comes to adding/deleting/cutting/pasting because it can't simply by linked to additional parent records. Adding a new parent record implies removing the old parent record. This has permission implications because it would actually involve changing a field in the related record just to add or remove it from a relationship.

Returns:
boolean True if the relationship is one-to-many.
Since:
0.6.1

Definition at line 1555 of file Relationship.php.

isParentRelationship ( )

Indicates whether this relationship is a parent relationship.

A parent relationship generally implies that first record found in the relationship is the parent of the current record in the heirarchical structure.

A relationship can be declared to be a parent relationship in the relationships.ini file by adding "meta:class = parent".

Returns:
boolean True if the relationship is a parent relationship.

Definition at line 1524 of file Relationship.php.

& keys ( )

Returns array of references to key fields in relationship.

Definition at line 835 of file Relationship.php.

showTabsForAddNew ( )

Definition at line 819 of file Relationship.php.

supportsAddExisting ( )

Indicates whether existing records can be added to this relationship.

Returns:
false if, in the relationships.ini file the actions:addexisting directive is false or 0. Otherwise returns true.

Definition at line 774 of file Relationship.php.

supportsAddNew ( )

Indicates whether new records can be added to this relationship.

Returns:
false if, in the relationships.ini file the actions:addnew directive is false or 0 Otherwise this returns true.

Definition at line 761 of file Relationship.php.

supportsRemove ( )

Indicates whether records can be removed from this relationship.

Returns:
false if, in the relationships.ini file, the actions:remove directive is false or 0 Otherwise returns true.

Definition at line 813 of file Relationship.php.


Field Documentation

$_cache = array()

Definition at line 87 of file Relationship.php.

$_destinationTables

Definition at line 53 of file Relationship.php.

$_fieldTableLookup

Definition at line 58 of file Relationship.php.

$_keys

Definition at line 68 of file Relationship.php.

$_name

Definition at line 43 of file Relationship.php.

$_permissions = array()

Definition at line 79 of file Relationship.php.

$_schema

Definition at line 63 of file Relationship.php.

$_sourceTable

Definition at line 48 of file Relationship.php.

$_sql_generated = array()

Flag to indicate whether or not the sql has been generated. (Used in particular by the getSQL() method.

boolean

Definition at line 77 of file Relationship.php.

$addExisting

Definition at line 90 of file Relationship.php.

$addNew

Definition at line 89 of file Relationship.php.

$app

Definition at line 81 of file Relationship.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations