![]() |
Xataface 2.0
Xataface Application Framework
|
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 |
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.
_init | ( | &$ | rel_values | ) |
Initializes the relationship given an associative array of values that is produced by parsing the relationships.ini file.
$rel_values | Initializing 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.
labels | Out parameter to map field names to labels. |
values | Out parameter to map labels to values. |
sql_data | In 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()
labels | Out param to map field names to labels. |
values | Out param to map labels to values |
root | Reference to a node of the parse tree that we are currently dealing with. |
parser_wrapper | Reference 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.
$tablename | The name of the source table. $relationshipName The name of the relationship |
An | array 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.
boolean | $includeAll | Whether 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. |
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.
Dataface_Record | &$record | The parent record. |
array | $query | A query to filter the possible records. |
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.
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.
string | $table | The 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.
Definition at line 1100 of file Relationship.php.
& getField | ( | $ | fieldname | ) |
Returns the field definition for a field in the relationship.
string | $fieldname | The field name. This can be absolute or relative. (e.g. Absolute would be something like people.firstName, whereas relative would be something like firstName). |
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", ... ), ... );
relationship_name | The name of the relationship |
values | Supplementary values passed as array with keys = absolute field names, values = serialized values. |
sql | If 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. |
PEAR_Error | if 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.
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.
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().
Definition at line 738 of file Relationship.php.
& getSourceTable | ( | ) |
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.
getBlobs | If true then Blob columns will also be returned. Default is false. boolean |
Definition at line 529 of file Relationship.php.
& getTable | ( | $ | field = null | ) |
Returns reference to table that contains the given field.
string | $field | The name of the field. |
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.
string | $fieldname | The name of the field that we are checking. This may be an absolute name or a relative name. |
boolean | $checkAll | If 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
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"
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.
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.
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".
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.
Definition at line 774 of file Relationship.php.
supportsAddNew | ( | ) |
Indicates whether new records can be added to this relationship.
Definition at line 761 of file Relationship.php.
supportsRemove | ( | ) |
Indicates whether records can be removed from this relationship.
Definition at line 813 of file Relationship.php.
$_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.