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

Public Member Functions

 Dataface_Table_builder ($name)
 createPrimaryKey ()
keys ()
 save ()
 create ()
 update ()
 alterFieldInDB ($field, $op='modify')
 addFieldToDB ($field)
 removeFieldFromDB ($field)
 writeConfigFiles ($params=array())
 flattenConfigArray ($field, &$arr, $prefix='')
 compareFields ($field1, $field2)
fields ()
addField ($field)
 removeField ($name)
getField ($name)
 getParameter ($fieldname, $paramname)
 setParameter ($fieldname, $paramname, $paramvalue)

Data Fields

 $table
 $name
 $fields = array()

Detailed Description

Handles the building of database tables and their associated configuration files. This version is only support the fields.ini file, but future versions will support relationships and valuelists.

Usage: $builder = new Dataface_Table_builder('mytable'); $builder->addField( array( 'Field'=>'id', 'Type'=>'int(11)', 'Extra'=>'auto_increment', 'Null'=>'' ) ); $builder->addField( array( 'Field'=>'title', 'Type'=>'varchar(64)', ) ); $builder->save(); // saves the table to the database and the config files to disk.

Definition at line 30 of file builder.php.


Member Function Documentation

& addField ( field)

Adds a field to this table.

Parameters:
array$fieldA partial field definition. Must contain at least Field (or name) and Type keys.
string$field,[Field]The name of the field
string$field,[Type]The type of the field (e.g. int(11))
string$field,[Default]The default value
string$field,[Key]'PRI' if this is part of the primary key.
string$field,[Null]Empty if the field is not null.
Returns:
array The finished field definition.

Definition at line 305 of file builder.php.

addFieldToDB ( field)

Adds a field to the table.

Parameters:
array$fieldThe field definition to add.

Definition at line 195 of file builder.php.

alterFieldInDB ( field,
op = 'modify' 
)

Alters a field.

Parameters:
array$fieldThe field definition to be modified.
string$opThe operation to perform. Can take values 'add' or 'modify'.

Definition at line 172 of file builder.php.

compareFields ( field1,
field2 
)

Compares two field definitions to make sure that they are identical.

Parameters:
array$field1Associative array representing a field.
array$field2Associative array representing b field.
Returns:
integer 0 If field1 and field2 are the same. Non-zero otherwise.

Definition at line 276 of file builder.php.

create ( )

Creates a table in the database based on the name and field definitions in the builder. This also sets the table property to a Dataface_Table object for the created table.

Returns:
mixed Returns a PEAR_Error object if the create fails.

Definition at line 99 of file builder.php.

createPrimaryKey ( )

Definition at line 53 of file builder.php.

Definition at line 44 of file builder.php.

& fields ( )

Obtains a reference to the fields array for this table.

Definition at line 288 of file builder.php.

flattenConfigArray ( field,
&$  arr,
prefix = '' 
)

Flattens a configuration array into a normal key-value list so that it is ready to write to a config file.

Parameters:
array$fieldAssociative array of configuration options.
array&$arrOutput parameter . The flattened array that is output.
string$prefixA string prefix for the keys.
Returns:
void

Definition at line 258 of file builder.php.

& getField ( name)

Definition at line 337 of file builder.php.

getParameter ( fieldname,
paramname 
)

Definition at line 342 of file builder.php.

& keys ( )

Returns a reference to the key fields of this table. If the table has

Definition at line 69 of file builder.php.

removeField ( name)

Definition at line 329 of file builder.php.

removeFieldFromDB ( field)

Removes a field from the table.

Parameters:
arrayField definition.

Definition at line 204 of file builder.php.

save ( )

Saves the table to the database and writes the configuration files.

Definition at line 86 of file builder.php.

setParameter ( fieldname,
paramname,
paramvalue 
)

Definition at line 358 of file builder.php.

update ( )

Updates the database table schema and config files to match the state of the table object.

Definition at line 132 of file builder.php.

writeConfigFiles ( params = array())

Writes the configuration files (e.g. fields.ini file) for the table.

Parameters:
array$paramsAssociative array of parameters
array$params,[fields]An optional array of field definitions

Definition at line 219 of file builder.php.


Field Documentation

$fields = array()

Definition at line 42 of file builder.php.

string $name

Definition at line 40 of file builder.php.

$table

Definition at line 35 of file builder.php.


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