![]() |
Xataface 2.0
Xataface Application Framework
|
A class that represents the table of a table in a database. More...
Public Member Functions | |
Internationalization | |
Methods for translation and internationalization | |
& | getTranslations () |
Returns associative array of translations where the key is the 2-digit language code and the value is an array of column names in the translation. | |
& | getTranslation ($name) |
Returns an array of column names that are available in a given language. | |
getTranslationStates () | |
Gets array of translation states available. | |
Tabs | |
Methods for working with tabbed sections of the edit form. | |
getTabs () | |
Returns an array of strings that are the names of the tabs for this table. Fields can be grouped into tabs by specifying a 'tab' attribute in the fields.ini file. This is just a list of the tabs that are specified. | |
& | tabs ($record=null) |
Returns an associative array of tab definitions of the form: [tabname] -> [tab_properties]. | |
& | getTab ($tabname, $record=null) |
Returns specified tab's properties. | |
__join__ (&$record) | |
Returns an array of tables for a particular record that can be treated as join tables. | |
hasJoinTable ($tablename, &$record) | |
Indicates whether or not this table has a join table. | |
Field Groups | |
Methods for working with field groups. | |
& | getFieldgroup ($fieldgroupname) |
Returns an associative array describing a field group. | |
& | getFieldgroups () |
Returns associative array of all of the field group definitions (keys are the fieldgroup names). | |
Imports | |
Methods for working with import filters and importing records. | |
& | getImportFilters () |
Import filters facilitate the importing of data into the table. | |
registerImportFilter (&$filter) | |
getImportTables () | |
Gets the tables from the database that are explicitly for importing data. They are tables of the form Tablename__import__<timestamp> where <timestamp> is the unix timestamp of when the import table was created. | |
createImportTable () | |
Creates an import table for this table. An import table is an empty clone of this table. It serves as an intermediate step towards importing data into the main table. | |
cleanImportTables () | |
Cleans up old import tables. Any import tables older (in seconds) than the garbage collector threshold (as defined in $app->_conf['garbage_collector_threshold']) will be dropped. | |
isImportTable ($tablename) | |
Checks if a given table is an import table as created with createImportTable(). | |
parseImportData ($data, $importFilter=null, $defaultValues=array()) | |
Prepares data to be imported into the table. It takes raw data and produces an array of Dataface_Record objects that can be imported into the table. | |
Field Type Information | |
Methods for checking the type information of fields. | |
getType ($fieldname) | |
Returns the type of a field , eg: int, float, varchar, blob, etc... | |
isDate ($fieldname) | |
Checks a field to see if it is a date type (date, datetime, time, or timestamp). | |
isBlob ($fieldname) | |
Checks a field to see if it is a blob type. | |
isContainer ($fieldname) | |
Indicates if a field is a container field. A container field is a varchar or char field but it contains the path to a file rather than data itself. | |
isPassword ($fieldname) | |
Checks to see if the field is a password field. Any field with widget:type=password is regarded as a password field. | |
isText ($fieldname) | |
Checks to see if the field is a text field (e.g. text, longtext, tinytext, or mediumtext). | |
isXML ($fieldname) | |
Checks to see if the field is stored in XML format. Only the 'table' and 'group' widgets cause the data to be stored as XML. | |
isChar ($fieldname) | |
Checks to see if the field is a character field (i.e. varchar or char). | |
isInt ($fieldname) | |
Checks to see if the field is an INT field. | |
isFloat ($fieldname) | |
Checks to see if the field is a floating point field (i.e. float, double, tinyfloat, etc..) | |
Templates | |
Methods for working with the user interface and templates. | |
displayBlock ($blockName, $params=array()) | |
Displays a block from the delegate class. Blocks are defined in the delegate class by defining methods with names starting with 'block__'. Eg: block__header() | |
getBlockContent ($blockName, $params=array()) | |
Returns the content of a given block as a string. | |
Factory Methods | |
Methods for loading and creating Dataface_Record objects on the current table. | |
newRecord ($vals=null) | |
Returns a new blank Dataface_Record object for this table. | |
& | getRecord ($query=null) |
Gets a record from the database that matches the given query. | |
Actions | |
Methods for dealing with table actions. | |
getActions (&$params, $noreturn=false) | |
Returns the actions for this table. | |
Data Fields | |
$tablename | |
The name of the table that this table represents. string. | |
$db | |
DB connection handle. resource handle. | |
$errors = array() | |
Store errors that occur in methods of this class. | |
Initialization | |
Methods for obtaining Dataface_Table objects. | |
static & | loadTable ($name, $db=null, $getAll=false, $quiet=false) |
Loads the table object for a database table. | |
Fields | |
static & | getTableField ($address, $db='') |
Returns field information given its address. Note: To prevent deadlocks, this method should never be called inside the Dataface_Table constructor. | |
static | fieldExists ($address, $db='') |
Checks if a field exists. Note: To prevent deadlocks, this method should never be called inside the Dataface_Table constructor. | |
static | tableExists ($tablename, $usecache=true) |
Checks if the given table exists. This caches the results so that you won't have to check the existence of the same table twice. | |
static | absoluteFieldName ($field, $tablenames, $db='', $columnList=null) |
Returns the absolute field name of a field as it appears in one of the given tables. This is kind of like a search to find out which of the given tables, the column belongs to. The absolute field name is a string of the form table_name.field_name (ie table name and field name separated by a dot). This method may be called statically. | |
static & | getGlobalFieldsConfig () |
exists ($fieldname, $checkParent=true) | |
Checks if a field exists in this table by the given name. | |
hasField ($fieldname, $checkParent=true) | |
Checks if a field exists in this table by the given name. Alias of hasField() | |
relativeFieldName ($fieldname) | |
Returns the relative field name given either a relative name or an absolute name. | |
guessField ($types, $patterns, $forcePattern=false) | |
Tries to find a field that best matches the criteria we provide. This is useful for finding e.g. description, last modified, and title fields. | |
getDescriptionField () | |
Makes a best guess at which field in this table stores the record description. The record description is displayed in various logical places throughout the UI. | |
getCreatedField () | |
Makes a best guess at which field stores the creation date of the record. | |
getCreatorField () | |
Makes a best guess at which field stores the username of the person who created the record. | |
getLastUpdatedField () | |
Makes a best guess at which field stores the last modified date of the record. | |
getBodyField () | |
Makes a best guess at which field stores the "body" of the record. The body is used in things like the RSS feed to show the "content" of the record. | |
& | getIndexes () |
Returns an associative array of indexes in this table. | |
getFullTextIndexedFields () | |
Returns an array of field names that have full text indexes. | |
getCharFields ($includeGraftedFields=false, $excludeUnsearchable=false) | |
Returns array of names of char, varchar, and text fields. These are the fields that can be searched using full text searches. | |
isSearchable ($field) | |
Checks if a field is searchable. Fields can be made unsearchable by setting the not_searchable directive in the fields.ini file. | |
isMetaField ($fieldname) | |
Indicates if the given field acts as a meta field that describes an aspect of another field. For example, some fields simply contain the mimetype of a blob field. Such a field is a meta field. | |
getMetadataColumns () | |
Returns an array of names of columns in the metadata table for this table. The metadata table contains metadata such as state and translation state for the corresponding records of this table. Fields of this table that are considered to be metadata must begin with two underscores to signify that they are metadata. | |
& | formFields ($byTab=false, $includeTransient=false) |
Returns the fields that should be included in forms for editing. This includes fields from parent tables. | |
& | fields ($byTab=false, $includeGrafted=false, $includeTransient=false) |
Returns reference to the fields array that contains field definitions. | |
& | graftedFields ($includeParent=true) |
Field definitions of fields that have been grafted onto this table. | |
& | transientFields ($includeParent=false) |
Returns the transient fields in this table. Transient fields are fields that do not get saved in the database (i.e. have no corresponding field in the database. They are useful for creating fields on the new/edit forms. | |
& | delegateFields ($includeParent=false) |
Returns calculated fields defined in the delegate class via the field__fieldname() method naming convention. | |
sql () | |
Returns the SQL query used to fetch records of this table, if defined. | |
getProxyView () | |
Returns the name of the VIEW to be used for reading records from the database. This feature is new in version 1.2 and is intended to improve performance by NOT using subqueries to implement support for __sql__ parameters on tables. We'll see if this makes a big difference to mysql. | |
& | keys () |
Returns reference to the keys array that contains field definitions for keys. | |
hasKey ($name) | |
Checks to see if the specified field is part of the primary key. | |
& | mandatoryFields () |
A list of the keys that are NOT auto incremented. | |
getDefaultValue ($fieldname) | |
Returns the default value for a field. | |
titleColumn () | |
A valid SQL select phrase for a single column. This will be used when extracting the titles of each row from the database. | |
& | getField ($fieldname) |
Returns a field structure with the given name. This can also be related field. Simply prepend the relationship name followed by a period. eg: relationship_name.field_name. | |
getFieldProperty ($propertyName, $fieldname, $params=array()) | |
This method returns a property associated with a field, that is defined in the fields.ini file. This method also checks the delegate class to see if an equivalent property method has been defined. Delegate class method names will be of the form <field_name>__<property_name>(). Note that in the case where the property name contains illegal characters (e.g., ':'), the character will be replaced by an underscore ( i.e., '_'). | |
getAutoIncrementField () | |
Returns the name of the field that is auto incrementing (if it exists). | |
Permissions | |
Methods to calculate permissions on records, fields, and relationships of the table. | |
setSecurityFilter ($filter=null) | |
Sets a security filter on the table. A security filter is an array of key/value pairs that are automatically added to any query of this table to limit the results. | |
getSecurityFilter ($filter=array()) | |
Returns the security filter for this table. | |
getRelationshipPermissions ($relationshipName, $params=array()) | |
Gets the permissions for a particular relationship. | |
getPermissions ($params=array()) | |
Obtains the permissions for a particular record or for this table. Parameters are passed in associative array as key value pairs. | |
convertRolesToPermissions ($roles) | |
Resolves the pemissions for a role or list of roles. | |
loadPermissions () | |
Loads the permissions from the permissions.ini files. | |
Table Info | |
Methods to retrieve configuration and status information about the table. | |
static & | getBackupModificationTimes ($refresh=false) |
Neither INNODB tables nor views store the last updated time inside of MySQL. This wreaks havoc on caching, so we create our own backup table called dataface__mtimes as a fallback mechanism to track uptime times of tables. The down side is that it only updates the timestamp when a change is made via Xataface. Outside changes aren't tracked. | |
static & | getTableModificationTimes ($refresh=false) |
Returns an associative array mapping table names to their associated modification as a unix timestamp. | |
getLabel () | |
Gets the label for this table. This is displayed in the navigation menu (table tabs). | |
getSingularLabel () | |
Returns the label for this table as a singular. Often tables are named as plurals of the entities they contain. This will attempt to get the name of the singular entity for use in UI items where referring to the items of the table in singular is more appropriate e.g. New Person. | |
tableInfo () | |
Print information about Table. | |
databaseInfo () | |
& | attributes () |
Returns reference to the attributes array for this table. | |
& | getParent () |
Gets the parent table of this table to help model inheritance. The parent table can be specified by the __isa__ attribute of the fields.ini file. | |
implementsOntology ($ontologyName) | |
Indicates whether this table is declared as implementing the given ontology. | |
& | getStatus () |
Returns the status of this table. Includes things like modification time, etc... | |
getUpdateTime () | |
Returns the update time as an SQL DateTime string for this table. | |
getCreateTime () | |
Returns the creation time of this table as an SQL DateTime string. | |
Valuelists | |
isYesNoValuelist ($valuelist_name, &$yes, &$no) | |
Checks if a valuelist is just a boolean valuelist. It will also return (via output parameters) what the corresponding yes/no values are. | |
clearValuelistCache () | |
Clears the valuelist cache. | |
& | getValuelist ($name) |
Returns a named valuelist in this table. | |
& | valuelists () |
Returns the valuelists in this table. | |
getAvailableValuelistNames () | |
Returns a list of all valuelists that are available to this table. | |
Relationships | |
addRelationship ($name, $relationship) | |
Adds a relationship to the table. | |
& | getParentRelationship () |
Gets the relationship that should be used as the parent relationship. This is useful for representing heirarchical structures. | |
& | getChildrenRelationship () |
Gets the relationship that should be used as the children relationship. This is useful for representing heirarchical structures. | |
getRelationshipRange ($relationshipName) | |
Gets the range of records that should be returned for a given relationship when records are returning their related records. | |
setRelationshipRange ($relationshipName, $lower, $upper) | |
Sets the range of related records that should be returned by records of this table when getting records in the given relationship. | |
getDefaultRelationshipRange () | |
Gets the default relationship range for all relationships. | |
setDefaultRelationshipRange ($lower, $upper) | |
Sets the default relationship range to be used for all relationships. | |
& | getRelationship ($name) |
Gets a relationship by name. | |
hasRelationship ($name) | |
Checks if this table has a relationship with the specified name. | |
getRelationshipsAsActions ($params=array(), $relationshipName=null, $passthru=false) | |
Returns a list of the relationships for this table as actions. | |
& | relationships () |
Returns reference to the relationships array for this table. | |
& | getTableTableForField ($fieldname) |
Returns the Table object that contains a specified field. The fieldname is given as a relationship path (as opposed to an absolute path. This method cannot be called statically. | |
Delegate Classes | |
& | getDelegate () |
Returns a reference to the Table's delegate class. | |
Field Data Manipulation | |
parse_datetime ($value) | |
Parses a value intended to be placed into a date field and converts it to a normalized format. | |
parse_date ($value) | |
Alias of parse_datetype() | |
parse_timestamp ($value) | |
Parses a date, but also recognizes teh CURRENT_TIMESTAMP keyword string to return the current timestamp in normalized format. | |
parse_time ($value) | |
Alias of parse_datetype() | |
normalize ($fieldname, $value) | |
Takes a value a normalizes it to a string representation of the value as encoded for the specified field. This is useful for equality comparisons on values of fields. | |
getValueAsString ($fieldname, $value) | |
Gets the values of this record as strings. Some records like dates and times, are stored as data structures. getValue() returns these datastructures unchanged. This method will perform the necessary conversions to return the values as strings. | |
format ($fieldname, $value) | |
Formats a value for a particular field to prepare it for display. This will delegate to the DelegateClass::field__format() method if it is defined. Otherwise it will use rules defined in the fields.ini file such as date_format , money_format , and display_format . | |
parse ($fieldname, $value, $parseRepeat=true) | |
Parses a value so that it conforms with the value stored in the given field. | |
parse_repeated ($fieldname, $value, $separator="\n") | |
Parses a value for a repeated field. | |
validate ($fieldname, $value, &$params) | |
Validates against a field of this table. This checks if a value is valid for this a field of this table. | |
Utility Methods | |
static | setBasePath ($table, $path) |
static | getBasePath ($table) |
clearCache () | |
Clears the table's cache. This is generally handled automatically but if you want to ensure that values get recalculated then you can clear the cache here. | |
getSerializer () | |
Gets the serializer object that is used to serialize data in this table. |
A class that represents the table of a table in a database.
This models (and loads) all information about a table and its columns (names, types, keys, etc..), but it also augments these definitions by adding relationships, value lists, and widget types to the fields so that the system knows how a user will interact with the fields.
Usage Example:
$table = Dataface_Table::loadTable('Profiles');
__join__ | ( | &$ | record | ) |
Returns an array of tables for a particular record that can be treated as join tables.
Dataface_Record | &$record | The record whose context we're considering. |
array( tableName:String => tableLabel:String )
static absoluteFieldName | ( | $ | field, |
$ | tablenames, | ||
$ | db = '' , |
||
$ | columnList = null |
||
) | [static] |
Returns the absolute field name of a field as it appears in one of the given tables. This is kind of like a search to find out which of the given tables, the column belongs to. The absolute field name is a string of the form table_name.field_name (ie table name and field name separated by a dot). This method may be called statically.
Note: To prevent deadlocks, this method should never be called inside the Dataface_Table constructor.
string | $field | The name of a field. |
array | $tablenames | An array of table names. |
resource | $db | A db resource to query the database. |
array | $columnList | Optional array of column names from which to get the absolute name (in case there is more than one possible). |
PEAR_Error | if none of the specified tables contain a field named $field, or if more than one table contains a field named $field. |
addRelationship | ( | $ | name, |
$ | relationship | ||
) |
& attributes | ( | ) |
cleanImportTables | ( | ) |
clearCache | ( | ) |
convertRolesToPermissions | ( | $ | roles | ) |
Resolves the pemissions for a role or list of roles.
mixed | $roles | Either a string role name or an array of role names. |
createImportTable | ( | ) |
Creates an import table for this table. An import table is an empty clone of this table. It serves as an intermediate step towards importing data into the main table.
databaseInfo | ( | ) |
& delegateFields | ( | $ | includeParent = false | ) |
Returns calculated fields defined in the delegate class via the field__fieldname() method naming convention.
boolean | $includeParent | True to also include fields from the parent table (via the __isa__ directive). |
displayBlock | ( | $ | blockName, |
$ | params = array() |
||
) |
Displays a block from the delegate class. Blocks are defined in the delegate class by defining methods with names starting with 'block__'. Eg: block__header()
string | $blockName | The name of the block. |
array | $params | Associative array of key/value pairs to pass to the block. |
exists | ( | $ | fieldname, |
$ | checkParent = true |
||
) |
Checks if a field exists in this table by the given name.
string | $fieldname | The name of the field to check. |
boolean | $checkParent | Whether to check the parent table also (via the __isa__ relationship). |
static fieldExists | ( | $ | address, |
$ | db = '' |
||
) | [static] |
Checks if a field exists. Note: To prevent deadlocks, this method should never be called inside the Dataface_Table constructor.
string | $address | The absolute path to a field (of the form table_name.field_name). |
resource | $db | A db resource connection. |
& fields | ( | $ | byTab = false , |
$ | includeGrafted = false , |
||
$ | includeTransient = false |
||
) |
Returns reference to the fields array that contains field definitions.
boolean | $byTab | Whether to group fields by tab. |
booelan | $includeGrafted | Whether to include grafted fields as well. |
boolean | $includeTransiet | Whether to include transient fields also. |
format | ( | $ | fieldname, |
$ | value | ||
) |
Formats a value for a particular field to prepare it for display. This will delegate to the DelegateClass::field__format() method if it is defined. Otherwise it will use rules defined in the fields.ini file such as date_format
, money_format
, and display_format
.
This method will be applied to output of the Dataface_Record::display() method unless the DelegateClass::fieldname__display() method is implemented, which would override the behavior completely.
string | $fieldname | The name of the field that is being formatted. |
string | $value | The string field value. |
Exception | if the field does not exist. |
& formFields | ( | $ | byTab = false , |
$ | includeTransient = false |
||
) |
Returns the fields that should be included in forms for editing. This includes fields from parent tables.
boolean | $byTab | Whether to group the fields by the tab that they are in. |
boolean | $includeTransient | True to include transient fields also. |
getActions | ( | &$ | params, |
$ | noreturn = false |
||
) |
Returns the actions for this table.
array | $params | An associative array of options. Possible keys include: record => reference to a Dataface_Record or Dataface_RelatedRecord object relationship => The name of a relationship. category => A name of a category for the actions to be returned. |
getAutoIncrementField | ( | ) |
getAvailableValuelistNames | ( | ) |
static& getBackupModificationTimes | ( | $ | refresh = false | ) | [static] |
Neither INNODB tables nor views store the last updated time inside of MySQL. This wreaks havoc on caching, so we create our own backup table called dataface__mtimes as a fallback mechanism to track uptime times of tables. The down side is that it only updates the timestamp when a change is made via Xataface. Outside changes aren't tracked.
boolean | $refresh | This outputs the value from cache if possible. Setting this parameter to true overrides this to check the database again. |
array( 'table1' => 123456789078668 'table2' => 987654345678967 ... )
getBlockContent | ( | $ | blockName, |
$ | params = array() |
||
) |
getBodyField | ( | ) |
Makes a best guess at which field stores the "body" of the record. The body is used in things like the RSS feed to show the "content" of the record.
getCharFields | ( | $ | includeGraftedFields = false , |
$ | excludeUnsearchable = false |
||
) |
Returns array of names of char, varchar, and text fields. These are the fields that can be searched using full text searches.
boolean | $includeGraftedFields | If true, then this will also return grafted fields. |
boolean | $excludeUnsearchable | If true then this will exclude fields that are marked as unsearchable. |
& getChildrenRelationship | ( | ) |
Gets the relationship that should be used as the children relationship. This is useful for representing heirarchical structures.
getCreatedField | ( | ) |
Makes a best guess at which field stores the creation date of the record.
getCreateTime | ( | ) |
getCreatorField | ( | ) |
Makes a best guess at which field stores the username of the person who created the record.
Force a pattern match for field to be considered
getDefaultRelationshipRange | ( | ) |
Gets the default relationship range for all relationships.
getDefaultValue | ( | $ | fieldname | ) |
& getDelegate | ( | ) |
Returns a reference to the Table's delegate class.
getDescriptionField | ( | ) |
Makes a best guess at which field in this table stores the record description. The record description is displayed in various logical places throughout the UI.
& getField | ( | $ | fieldname | ) |
Returns a field structure with the given name. This can also be related field. Simply prepend the relationship name followed by a period. eg: relationship_name.field_name.
string | $fieldname | The name of the field for which we with to retrieve the construct. |
& getFieldgroup | ( | $ | fieldgroupname | ) |
Returns an associative array describing a field group.
string | $fieldgroupname | The name of the field group to obtain. |
Sample group:
array( "element-display" => "inline", // Elements displayed inline // poss vals: ENUM("inline","block") "element-label-visible" => true, // Show labels for elements "element-description-visible" => true, // Show descriptions for elements "label" => "My Group", // Label for the entire group "description" => "This is a group of elements");
& getFieldgroups | ( | ) |
getFieldProperty | ( | $ | propertyName, |
$ | fieldname, | ||
$ | params = array() |
||
) |
This method returns a property associated with a field, that is defined in the fields.ini file. This method also checks the delegate class to see if an equivalent property method has been defined. Delegate class method names will be of the form <field_name>__<property_name>(). Note that in the case where the property name contains illegal characters (e.g., ':'), the character will be replaced by an underscore ( i.e., '_').
string | $propertyName | The name of the property. (e.g., 'widget:label') |
string | $fieldName | The name of the field |
array | $params | Optional named parameters: record : A reference to a Dataface_Record object that can be used to provide context about which record is being edited. |
getFullTextIndexedFields | ( | ) |
Returns an array of field names that have full text indexes.
A full-text index allows MySQL full-text searches to be performed on the contents of those fields. In MySQL 4+ full text searches may be performed on fields without a fulltext index but this will be slow.
& getImportFilters | ( | ) |
Import filters facilitate the importing of data into the table.
getImportTables | ( | ) |
Gets the tables from the database that are explicitly for importing data. They are tables of the form Tablename__import__<timestamp> where <timestamp> is the unix timestamp of when the import table was created.
& getIndexes | ( | ) |
Returns an associative array of indexes in this table.
array( <IndexName: string> => array( name => <string> // The name of the index unique => <boolean> // whether it is a unique index. type => <string> // The type of index e.g. b-tree, hash, etc... comment => <string> // Any comments added when the index was created columns => array(string) // Array of column names in this index. ) ... )
getLabel | ( | ) |
getLastUpdatedField | ( | ) |
Makes a best guess at which field stores the last modified date of the record.
getMetadataColumns | ( | ) |
Returns an array of names of columns in the metadata table for this table. The metadata table contains metadata such as state and translation state for the corresponding records of this table. Fields of this table that are considered to be metadata must begin with two underscores to signify that they are metadata.
If no metadata table yet exists, it will be created.
& getParent | ( | ) |
Gets the parent table of this table to help model inheritance. The parent table can be specified by the __isa__ attribute of the fields.ini file.
& getParentRelationship | ( | ) |
Gets the relationship that should be used as the parent relationship. This is useful for representing heirarchical structures.
getPermissions | ( | $ | params = array() | ) |
Obtains the permissions for a particular record or for this table. Parameters are passed in associative array as key value pairs.
Dataface_Record | record The context record for which to check permissions (optional). |
string | field The name of the field for which to check permissions (optional). |
string | relationship The name of the relationship for which to check permissions (optional). |
boolean | nobubble If this is true and field or relationship is set, it will only return the permissions applied to the particular field/relationship and not overlay those permissions on the the record permissions. The default behavior is to overlay these on the record. See DelegateClass::fieldname__permissions() for a flowchart of how permissions are evaluated. Setting 'nobubble' to true will circumvent this process to just produce the permissions defined for the particular field or relationship. |
array | recordmask Optional permissions mask to be laid under the record permissions. |
array | relationshipmask Optional permissions mask to lay under the relationship permissions. |
getProxyView | ( | ) |
Returns the name of the VIEW to be used for reading records from the database. This feature is new in version 1.2 and is intended to improve performance by NOT using subqueries to implement support for __sql__ parameters on tables. We'll see if this makes a big difference to mysql.
This method will return the name of the view to be used. If no custom SQL has been defined this will return null. If mysql doesn't support views, this will return null.
& getRecord | ( | $ | query = null | ) |
Gets a record from the database that matches the given query.
array | $query | associative array of key/value search terms. |
& getRelationship | ( | $ | name | ) |
Gets a relationship by name.
string | $name | The name of the relationship to retrieve. |
getRelationshipPermissions | ( | $ | relationshipName, |
$ | params = array() |
||
) |
Gets the permissions for a particular relationship.
This is a wrapper around getPermissions() that automatically specifies the relationship as a parameter. I.e. The following are equivalent:
$table->getRelationshipPermissions('foo')
and
$table->getPermissions(array('relationship'=>'foo'))
string | $relationshipName | The name of the relationship to check. |
array | $params | The other parameters (possible keys include 'field' and 'record'). See getPermissions() for full list of parameters. |
array(
permissionName:String => allowed:int (either 0 or 1)
)
getRelationshipRange | ( | $ | relationshipName | ) |
Gets the range of records that should be returned for a given relationship when records are returning their related records.
string | $relationshipName |
getRelationshipsAsActions | ( | $ | params = array() , |
$ | relationshipName = null , |
||
$ | passthru = false |
||
) |
Returns a list of the relationships for this table as actions.
Relationships can carry any action attributes and indeed can be treated as actions themselves for purposes of displaying menus of the various relationships primarily.
array | $params | Parameters that are passed to Dataface_ActionTool to filter the actions. |
string | $relationshipName | The name of the relationship to retrieve as an action. |
boolean | $passthru | Not used anymore. |
getSecurityFilter | ( | $ | filter = array() | ) |
getSerializer | ( | ) |
Gets the serializer object that is used to serialize data in this table.
getSingularLabel | ( | ) |
Returns the label for this table as a singular. Often tables are named as plurals of the entities they contain. This will attempt to get the name of the singular entity for use in UI items where referring to the items of the table in singular is more appropriate e.g. New Person.
This will use the singular_label directive of the fields.ini file if it is defined. Otherwise it will try to determine the singular of the label on its own.
& getStatus | ( | ) |
& getTab | ( | $ | tabname, |
$ | record = null |
||
) |
Returns specified tab's properties.
string | $tabname | The name of the tab to retrieve. |
Dataface_Record | $record | (Optional) The record that is being edited. |
static& getTableField | ( | $ | address, |
$ | db = '' |
||
) | [static] |
Returns field information given its address. Note: To prevent deadlocks, this method should never be called inside the Dataface_Table constructor.
string | $address | The address to a field. eg: Profile.fname is the address of the fname field in the Profile table. |
resource | $db | A db resource id. |
PEAR_Error | if Address is invalid or the table or field does not exist. |
static& getTableModificationTimes | ( | $ | refresh = false | ) | [static] |
Returns an associative array mapping table names to their associated modification as a unix timestamp.
Note that these values may not be accurate for views and innodb tables. Not sure if this is a MySQL bug or a feature.
boolean | $refresh | Whether to refresh the stats or use cached version. Generally leave this false as it updates once per request anyways. |
& getTableTableForField | ( | $ | fieldname | ) |
Returns the Table object that contains a specified field. The fieldname is given as a relationship path (as opposed to an absolute path. This method cannot be called statically.
string | $fieldname | The name of the field. |
getTabs | ( | ) |
Returns an array of strings that are the names of the tabs for this table. Fields can be grouped into tabs by specifying a 'tab' attribute in the fields.ini file. This is just a list of the tabs that are specified.
& getTranslation | ( | $ | name | ) |
& getTranslations | ( | ) |
getTranslationStates | ( | ) |
getType | ( | $ | fieldname | ) |
getUpdateTime | ( | ) |
getValueAsString | ( | $ | fieldname, |
$ | value | ||
) |
Gets the values of this record as strings. Some records like dates and times, are stored as data structures. getValue() returns these datastructures unchanged. This method will perform the necessary conversions to return the values as strings.
string | $fieldname | The name of the field for which the value is being stringified. |
mixed | $value | The value that is to be stringified. |
& getValuelist | ( | $ | name | ) |
Returns a named valuelist in this table.
string | $name | The name of the valuelist to retrieve. |
& graftedFields | ( | $ | includeParent = true | ) |
Field definitions of fields that have been grafted onto this table.
It is possible to provide an '__sql__' parameter to the fields.ini file that will provide a custom query to be performed. This is really only meant for grafting extra columns onto the table that weren't there before. These columns will appear in list and view mode, but you won't be able to edit them.
boolean | $includeParent | Whether to include grafted fields from the parent table (via the __isa__ directive). |
array( 'Field'=>fieldname, 'Type'=>varchar(32), 'widget'=>array( 'label'=>.., 'description'=>.. ) )
guessField | ( | $ | types, |
$ | patterns, | ||
$ | forcePattern = false |
||
) |
Tries to find a field that best matches the criteria we provide. This is useful for finding e.g. description, last modified, and title fields.
array(string=>int) | $types Associative array of field types (e.g. varchar) and their corresponding value if matched. | |
array(string=>int) | $patterns Associative array of regular expession patters and their corresponding score values. | |
boolean | $forcePattern | If true, then it will only return a value if the pattern matches. Otherwise it will produce the best/closest match. |
Examples:
$this->descriptionField = $this->guessField( array('text'=>10, 'mediumtext'=>10, 'shorttext'=>10, 'longtext'=>2, 'varchar'=>1, 'char'=>1), array('/description|summary|overview/'=>10, '/desc/'=>2) );
hasField | ( | $ | fieldname, |
$ | checkParent = true |
||
) |
Checks if a field exists in this table by the given name. Alias of hasField()
string | $fieldname | The name of the field to check. |
boolean | $checkParent | Whether to check the parent table also (via the __isa__ relationship). |
hasJoinTable | ( | $ | tablename, |
&$ | record | ||
) |
Indicates whether or not this table has a join table.
string | $tablename | The name of the table to check if it is joined. |
Dataface_Record | &$record | The record context. |
hasKey | ( | $ | name | ) |
hasRelationship | ( | $ | name | ) |
Checks if this table has a relationship with the specified name.
string | $name | The name of the relationship to check. |
implementsOntology | ( | $ | ontologyName | ) |
Indicates whether this table is declared as implementing the given ontology.
A table can be specified as implementing an ontology by adding the ontology to the __implements__ section of the fields.ini file for the table.
string | $ontologyName | The name of the ontology. |
isBlob | ( | $ | fieldname | ) |
isChar | ( | $ | fieldname | ) |
isContainer | ( | $ | fieldname | ) |
Indicates if a field is a container field. A container field is a varchar or char field but it contains the path to a file rather than data itself.
string | $fieldname | The name of the field to check. |
isDate | ( | $ | fieldname | ) |
isFloat | ( | $ | fieldname | ) |
isImportTable | ( | $ | tablename | ) |
Checks if a given table is an import table as created with createImportTable().
string | $tablename | The name of the table to check. |
isInt | ( | $ | fieldname | ) |
isMetaField | ( | $ | fieldname | ) |
Indicates if the given field acts as a meta field that describes an aspect of another field. For example, some fields simply contain the mimetype of a blob field. Such a field is a meta field.
string | $fieldname | The name of the field to check. |
isPassword | ( | $ | fieldname | ) |
isSearchable | ( | $ | field | ) |
isText | ( | $ | fieldname | ) |
isXML | ( | $ | fieldname | ) |
isYesNoValuelist | ( | $ | valuelist_name, |
&$ | yes, | ||
&$ | no | ||
) |
Checks if a valuelist is just a boolean valuelist. It will also return (via output parameters) what the corresponding yes/no values are.
string | $valuelist_name | The name of the valuelist to check. |
mixed | &$yes | Output parameter to store the "yes" value of the valuelist. |
mixed | &$no | Output parameter to store the "no" value of the valuelist. |
& keys | ( | ) |
loadPermissions | ( | ) |
static& loadTable | ( | $ | name, |
$ | db = null , |
||
$ | getAll = false , |
||
$ | quiet = false |
||
) | [static] |
Loads the table object for a database table.
This is the prefered way to create a new table. If the table already exists for the specified table, then a reference to that table is returned. If it does not exist, then the table is created, and a reference to it is returned.
string | $name | The name of the table for which the table should be returned. |
resource | $db | A db connection handle. |
boolean | $getAll | If true then this will return an array of all of the tables loaded. |
boolean | $quiet | Whether to show debugging information. |
& mandatoryFields | ( | ) |
newRecord | ( | $ | vals = null | ) |
Returns a new blank Dataface_Record object for this table.
array | $vals | Associative array of values to initialize in this record. |
normalize | ( | $ | fieldname, |
$ | value | ||
) |
Takes a value a normalizes it to a string representation of the value as encoded for the specified field. This is useful for equality comparisons on values of fields.
string | $fieldname | The full path of the field on which we are normalizing. |
mixed | $value | The value which we are normalizing. |
parse | ( | $ | fieldname, |
$ | value, | ||
$ | parseRepeat = true |
||
) |
Parses a value so that it conforms with the value stored in the given field.
string | $fieldname | The name of the field that where the value should be storable. |
mixed | $value | The value we wish to parse. |
boolean | $parseRepeat | If true, this indicates that if this is a repeating field, then all of it's repeats should also be parsed individually. |
parse_date | ( | $ | value | ) |
parse_datetime | ( | $ | value | ) |
Parses a value intended to be placed into a date field and converts it to a normalized format.
mixed | $value | The input value to be normalized. |
array('year'=>2010, 'month'=>10, 'day'=>2, 'hours'=>9, 'minutes'=>23, 'seconds'=>5);
parse_repeated | ( | $ | fieldname, |
$ | value, | ||
$ | separator = "\n" |
||
) |
Parses a value for a repeated field.
string | $fieldname | The name of the field for which the value is being parsed. |
mixed | $value | The value that is to be parsed. |
string | $separator | The separator to be placed between each of the values in this repeated field. |
parse_time | ( | $ | value | ) |
parse_timestamp | ( | $ | value | ) |
Parses a date, but also recognizes teh CURRENT_TIMESTAMP keyword string to return the current timestamp in normalized format.
mixed | $value | The input date in any number of formats including the string 'CURRENT_TIMESTAMP'. |
array('year'=>2010, 'month'=>10, 'day'=>2, 'hours'=>9, 'minutes'=>23, 'seconds'=>5);
parseImportData | ( | $ | data, |
$ | importFilter = null , |
||
$ | defaultValues = array() |
||
) |
Prepares data to be imported into the table. It takes raw data and produces an array of Dataface_Record objects that can be imported into the table.
mixed | $data | Raw data that is to be imported. |
string | $importFilter | The name of the import filter that is used to import the data. If this is null then every import filter is attempted until one is found that works. |
array | $defaultValues | The default values to add to imported records. |
PEAR_Error | if the importing fails for some reason. |
$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. $table =& Dataface_Table::loadTable('ListEntry'); $records = $table->parseImportData( $data, // The raw data to import 'XML_Filter' // The name of the filter to handle the import ); echo get_class($records[0]); // outputs 'Dataface_Record' echo $records[0]->val('name'); //outputs 'John Smith' echo $records[0]->val('number'); // outputs '555-555-5555' echo $records[1]->val('name'); // outputs 'Susan Moore' echo $records[1]->val('number'); // outputs '444-444-4444' // Note that the records in the $records array are NOT persisted in the database.
registerImportFilter | ( | &$ | filter | ) |
Registers | an import filter for this table. | |
Dataface_ImportFilter | $filter | The import filter to register. |
& relationships | ( | ) |
Returns reference to the relationships array for this table.
relativeFieldName | ( | $ | fieldname | ) |
setDefaultRelationshipRange | ( | $ | lower, |
$ | upper | ||
) |
setRelationshipRange | ( | $ | relationshipName, |
$ | lower, | ||
$ | upper | ||
) |
Sets the range of related records that should be returned by records of this table when getting records in the given relationship.
string | $relationshipName | The name of the relationship. |
int | $lower | The lower index to be returned. |
int | $upper | The upper index to be returned |
setSecurityFilter | ( | $ | filter = null | ) |
Sets a security filter on the table. A security filter is an array of key/value pairs that are automatically added to any query of this table to limit the results.
array | $filter | The query that should be used for a filter. This value will overwrite any previous security filter that had been set. |
Example, filtering so that only records with schoolID=10 will be returned.
$table->setSecurityFilter(array('schoolID'=>10)); // Will only show results where schoolID is 10
A good place to set security filters is in the DelegateClass::init() method. e.g.:
sql | ( | ) |
Returns the SQL query used to fetch records of this table, if defined.
This is only applicable the fields.ini contains an __sql__ directive or the delegate class implements the __sql__() method. Will return null otherwise.
static tableExists | ( | $ | tablename, |
$ | usecache = true |
||
) | [static] |
Checks if the given table exists. This caches the results so that you won't have to check the existence of the same table twice.
string | $tablename | The name of the table to check. |
boolean | $usecache | Whether to use the cache or not. |
tableInfo | ( | ) |
& tabs | ( | $ | record = null | ) |
Returns an associative array of tab definitions of the form: [tabname] -> [tab_properties].
This merges together any join tables that haven't been defined as a tab explicitly also.
Dataface_Record | &$record | A record to provide context. This will allow us to return different tabs for different records via the __tabs__ method of the delegate class. |
array( 'tab1'=>array( 'label'=>'The First Tab' 'description' => 'The tab description' 'order' => 4 ... etc... ), 'tab2'=>array( .... ) ... etc... );
titleColumn | ( | ) |
A valid SQL select phrase for a single column. This will be used when extracting the titles of each row from the database.
Example output:
fname
or
CONCAT(fname,' ',lname)
Output can be overridden in the delegate class.
The titleColumn method is used in places where we want to obtain a list of record titles from the database but don't want to have to load each full record into memory. The getTitle() method is used only if we already have the record loaded into memory.
If you override one of these methods, you should override the other also.
If you don't explicitly set this value, Xataface will try to make a best guess at which column should be used as the title based on column type and possibly the column names. It favours varchar columns if it can find one.
& transientFields | ( | $ | includeParent = false | ) |
Returns the transient fields in this table. Transient fields are fields that do not get saved in the database (i.e. have no corresponding field in the database. They are useful for creating fields on the new/edit forms.
boolean | $includeParent | Whether to include fields from the parent record. |
validate | ( | $ | fieldname, |
$ | value, | ||
&$ | params | ||
) |
Validates against a field of this table. This checks if a value is valid for this a field of this table.
string | $fieldname | The name of the field |
mixed | $value | The value to validate for the field. |
array | $params | Array of parameters. This may be used to pass parameters OUT of this function. For example. Setting the 'message' attribute of this array will pass out a message to be displayed to the user along with the error upon failed validation. |
& valuelists | ( | ) |
Returns the valuelists in this table.
$errors = array() |
$tablename |