FORMfields


FORMfields.TableSet

Class TableSet

TableSet

public class TableSet

Stores table data, and displays table data formatted by CSS stylesheets. This class allows one to autogenerate HTML tables with just raw data or an SQL query.

Since:
FORMfields v1.0

Field Summary
mixed

$classPostfix

A string that is appended to the class names printed in the HTML to uniquely identify this table's CSS.

mixed

$columnClasses

An array of class CSS class names, where the index corresponds to the column heading, used to format the div tags that wrap a table cell.

mixed

$enableSort

True if click sorting is enabled and the user can click a heading to automatically sort a column.

mixed

$headings

An array of table headings or the top row of table data.

mixed

$hideColumns

An array of boolean values, where the index corresponds to the column heading.

mixed

$name

An optional string prepended to the front of any $_REQUEST variables generated during sorting or pagifying table data that distinguishes this table's parameters from another table on the same page.

mixed

$rowClasses

An array of CSS class names, where the index corresponds to the data row, used to format the div tags that wrap a table cell.

mixed

$rows

An array of rows in the order that each row will be displayed where each row is an array of data.

mixed

$sortTranslations

An array of strings equal to the exact name of a database attribute, where the array index corresponds to the column heading.

mixed

$sortableHeadings

If not empty and enableSort is true, then this TableSet will use the array values in this variable to determine, which headings can be click sorted.

mixed

$tdClasses

An array of class names td tags where the array index corresponds to the column number.

Constructor Summary

TableSet(string name, string classPostfix)

Creates a new TableSet.

__construct(string name, string classPostfix)

Creates a new TableSet.

Method Summary
void

addColumn(array cells, string insertHeading, string colHeading)

Adds a column of data.

void

addRow(array cells)

Appends a row to the end of the data in this table.

void

addRows(array rows)

Appends rows to the endof the data in this table.

array

getAliases(string sql)

A static method that returns an array of all the aliases contained in the specified SQL query.

string

getAssociativeTableTag(array values)

A static method that provides a single line call for generating the HTML to display an associative array

string

getCommaDelimitedData(boolean ignoreHeadings)

Returns this table's data formatted as comma delimited data.

string

getCommaDelimitedRow(array values)

A static method that returns a row of comma delimited data.

string

getCssTag(string className, string content)

Returns the content string wrapped in div tags with the specified class name.

string

getDelimitedData(boolean ignoreHeadings, string delim)

Returns this table's data formatted as delimited data.

string

getDelimitedRow(array values, string delim)

A static method that returns a row of delimited data.

int

getNumColumns()

Returns the number of columns of data

int

getNumRows()

Returns the number of rows of data, not including the heading row.

string

getTabDeliminatedData(boolean ignoreHeadings)

Returns this table's data formatted as tab delimited data.

string

getTabDeliminatedRow(array values)

A static method that returns a row of tab delimited data.

string

getTabDelimitedData(boolean ignoreHeadings)

Returns this table's data formatted as tab delimited data.

string

getTabDelimitedRow(array values)

A static method that returns a row of tab delimited data.

string

getTableTag()

Returns the HTML to display this TableSet's data in an HTML table structure.

string

getTranslation(string heading)

Returns a sortTranslation, if any, for the specified heading.

string

getWrappedTableTag(int cols)

Returns the HTML to display this table as a group of side by side tables to maximize the amount of data that can fit on a single screen.

void

insertIndexes(string columnHeading, string insertHeading)

Inserts a column of indexes (starting at 1).

void

loadAssociativeArray(array values, boolean generateHeading)

Loads data from an associative array.

void

loadAssociativeArrayColumnWise(array values)

Loads data from an associative array.

void

loadQuery(string sql)

Loads the data from an SQL query.

void

loadResultSet(resource rs)

Loads the data from a results set.

void

loadRowsAndColumns(array values, int rows, int cols, array headings)

Loads array data and formats it into the specified number of rows and columns.

void

translateRows(string attrName, string pattern, string className)

Uses pattern to determine whether to set a row's CSS.

Field Detail

classPostfix

public mixed $classPostfix = null

A string that is appended to the class names printed in the HTML to uniquely identify this table's CSS.

Since:
FORMfields v2.0

columnClasses

public mixed $columnClasses = null

An array of class CSS class names, where the index corresponds to the column heading, used to format the div tags that wrap a table cell.

Since:
FORMfields v1.0

enableSort

public mixed $enableSort = false

True if click sorting is enabled and the user can click a heading to automatically sort a column. This should only be used when loading data through the loadQuery method.

Since:
FORMfields v1.0

headings

public mixed $headings = array()

An array of table headings or the top row of table data.

Since:
FORMfields v1.0

hideColumns

public mixed $hideColumns = null

An array of boolean values, where the index corresponds to the column heading. A value of true will hide the column.

Since:
FORMfields v1.0

name

public mixed $name = null

An optional string prepended to the front of any $_REQUEST variables generated during sorting or pagifying table data that distinguishes this table's parameters from another table on the same page. This value is only really needed when you have two or more tables on the same page and want them to be sortable or pagifyable.

Since:
FORMfields v2.0

rowClasses

public mixed $rowClasses = null

An array of CSS class names, where the index corresponds to the data row, used to format the div tags that wrap a table cell.

Since:
FORMfields v1.0

rows

public mixed $rows = null

An array of rows in the order that each row will be displayed where each row is an array of data.

Since:
FORMfields v1.0

sortTranslations

public mixed $sortTranslations = null

An array of strings equal to the exact name of a database attribute, where the array index corresponds to the column heading. This array should be populated for any column that doesn't sort properly. For example, if you SQL query contains CONCAT('',id,'') AS 'ID' then when enabling click sort by default, SQL will sort ID in an unexpected way. To resolve this simply use: sortTranslations["ID"] = "id".

Since:
FORMfields v3.0

sortableHeadings

public mixed $sortableHeadings = array()

If not empty and enableSort is true, then this TableSet will use the array values in this variable to determine, which headings can be click sorted. The array elements in sortableHeadings are any strings found in the headings array.

Since:
FORMfields v3.0

tdClasses

public mixed $tdClasses = array()

An array of class names td tags where the array index corresponds to the column number. This variable is needed to provide CSS customization to a column at the td tag level.

Since:
FORMfields v3.0

Constructor Detail

TableSet

public TableSet(string name, string classPostfix)

Creates a new TableSet.

Parameters:
name - optional string prepended to the front of any $_REQUEST variables generated during sorting or pagifying
classPostfix - string that is appended to the class names printed in the HTML to uniquely identify this table's CSS.
Since:
FORMfields v1.0
Deprecated:
deprecated as this constructor syntax is not expected in PHP 5 - will be removed once PHP 5 becomes a minimum requirement for FORMfields

__construct

public __construct(string name, string classPostfix)

Creates a new TableSet.

Parameters:
name - optional string prepended to the front of any $_REQUEST variables generated during sorting or pagifying
classPostfix - string that is appended to the class names printed in the HTML to uniquely identify this table's CSS.
Since:
FORMfields v1.0

Method Detail

addColumn

public void addColumn(array cells, string insertHeading, string colHeading)

Adds a column of data.

Parameters:
cells - a column of values
insertHeading - where to insert the column. The column will be inserted directly before the insertHeading or at the end of the columns if insertHeading is null
colHeading - the heading to insert for this new column if any
Since:
FORMfields v3.0

addRow

public void addRow(array cells)

Appends a row to the end of the data in this table.

Parameters:
cells - array of new data, where the number of elements in the array should be equal to the number of columns in the table
Since:
FORMfields v1.0

addRows

public void addRows(array rows)

Appends rows to the endof the data in this table.

Parameters:
rows - an array of rows, where each row is an array of cells
Since:
FORMfields v3.0

getAliases

public array getAliases(string sql)

A static method that returns an array of all the aliases contained in the specified SQL query.

Parameters:
sql - any valid SQL query string
Returns:
the aliases in the SQL query
Since:
FORMfields v3.0

getAssociativeTableTag

public string getAssociativeTableTag(array values)

A static method that provides a single line call for generating the HTML to display an associative array

Parameters:
values - associative array
Returns:
the HTML to display the associative array using a TableSet
Since:
FORMfields v3.0

getCommaDelimitedData

public string getCommaDelimitedData(boolean ignoreHeadings)

Returns this table's data formatted as comma delimited data. For example, this method can be used to create tab delimited .csv files that can be imported into MS Excel.

Parameters:
ignoreHeadings - true if headings should not be included in the delimited data, or false or null if headings should be included
Returns:
this table's data formatted as comma delimited data
Since:
FORMfields v3.0

getCommaDelimitedRow

public string getCommaDelimitedRow(array values)

A static method that returns a row of comma delimited data.

Parameters:
values - an array of data
Returns:
returns a row of comma delimited data
Since:
FORMfields v3.0

getCssTag

public string getCssTag(string className, string content)

Returns the content string wrapped in div tags with the specified class name.

Parameters:
className - a CSS class name
content - any string
Returns:
the content string wrapped in div tags with the specified class name
Since:
FORMfields v1.0

getDelimitedData

public string getDelimitedData(boolean ignoreHeadings, string delim)

Returns this table's data formatted as delimited data.

Parameters:
ignoreHeadings - true if headings should not be included in the delimited data, or false or null if headings should be included
delim - the delimiter
Returns:
this table's data formatted as delimited data
Since:
FORMfields v3.0

getDelimitedRow

public string getDelimitedRow(array values, string delim)

A static method that returns a row of delimited data. Note: MS Excel's way of representing double quotes within a field is by repeating the double quotes.

Parameters:
values - an array of data
delim - the delimiter
Returns:
returns a row of delimited data
Since:
FORMfields v3.0

getNumColumns

public int getNumColumns()

Returns the number of columns of data

Returns:
the number of columns of data
Since:
FORMfields v1.0

getNumRows

public int getNumRows()

Returns the number of rows of data, not including the heading row.

Returns:
the number of rows of data, not including the heading row
Since:
FORMfields v1.0

getTabDeliminatedData

public string getTabDeliminatedData(boolean ignoreHeadings)

Returns this table's data formatted as tab delimited data. For example, this method can be used to create tab delimited .txt files that can be imported into MS Excel.

Parameters:
ignoreHeadings - true if headings should not be included in the delimited data, or false or null if headings should be included
Returns:
this table's data formatted as tab delimited data
Since:
FORMfields v2.0
Deprecate:
deliminated should be delimited. Will be removed in the next release of FORMfields.

getTabDeliminatedRow

public string getTabDeliminatedRow(array values)

A static method that returns a row of tab delimited data.

Parameters:
values - an array of data
Returns:
returns a row of tab delimited data
Since:
FORMfields v2.0
Deprecated:
deliminated should be delimited. This method will be removed in the next release of FORMfields.

getTabDelimitedData

public string getTabDelimitedData(boolean ignoreHeadings)

Returns this table's data formatted as tab delimited data. For example, this method can be used to create tab delimited .txt files that can be imported into MS Excel.

Parameters:
ignoreHeadings - true if headings should not be included in the delimited data, or false or null if headings should be included
Returns:
this table's data formatted as tab delimited data
Since:
FORMfields v2.0

getTabDelimitedRow

public string getTabDelimitedRow(array values)

A static method that returns a row of tab delimited data.

Parameters:
values - an array of data
Returns:
returns a row of tab delimited data
Since:
FORMfields v2.0

getTableTag

public string getTableTag()

Returns the HTML to display this TableSet's data in an HTML table structure.

Returns:
the HTML to display this table's data
Since:
FORMfields v1.0

getTranslation

public string getTranslation(string heading)

Returns a sortTranslation, if any, for the specified heading. sortTranslations isa an array of strings equal to the exact name of a database attribute, where the array index corresponds to the column heading. This array should be populated for any column that doesn't sort properly. For example, if you SQL query contains CONCAT('<a href="mypage.php?id=',id,'">',id,'</a>') AS 'ID' then when enabling click sort by default, SQL will sort ID in an unexpected way. To resolve this simply use: sortTranslations["ID"] = "id".

Parameters:
heading - a heading
Returns:
sortTranslation or null if there isn't one
a sortTranslation, if any, for the specified heading
Since:
FORMfields v3.0

getWrappedTableTag

public string getWrappedTableTag(int cols)

Returns the HTML to display this table as a group of side by side tables to maximize the amount of data that can fit on a single screen.

Parameters:
cols - the number of columns into which to break the table
Returns:
the HTML to display this table as a group of side by side tables
Since:
FORMfields v3.0

insertIndexes

public void insertIndexes(string columnHeading, string insertHeading)

Inserts a column of indexes (starting at 1).

Parameters:
columnHeading - the heading of the new column or null for "#"
insertHeading - null or the heading after where the indexes should be inserted
Since:
FORMfields v3.0

loadAssociativeArray

public void loadAssociativeArray(array values, boolean generateHeading)

Loads data from an associative array. This method loads data into a 2 by n table matrix. This method can load data in the forms: $GLOBALS["VALUES1"] =
array(
"x" => 0.20,
"y" => 0.10,
"z" => 0.05
);
or
$GLOBALS["VALUES2"] =
array(
"x" => array(0.20, 0.1, 0.11),
"y" => array(0.10, 0.2, 0.22),
"z" => array(0.05, 0.3, 0.33)
);

Parameters:
values - associative array
generateHeading - true if the headings "Key" and "Value" should be generated
Since:
FORMfields v3.0

loadAssociativeArrayColumnWise

public void loadAssociativeArrayColumnWise(array values)

Loads data from an associative array. This method loads data into a n by 2 table matrix. This method can load data in the forms: $GLOBALS["VALUES1"] =
array(
"x" => 0.20,
"y" => 0.10,
"z" => 0.05
);
or
$GLOBALS["VALUES2"] =
array(
"x" => array(0.20, 0.1, 0.11),
"y" => array(0.10, 0.2, 0.22),
"z" => array(0.05, 0.3, 0.33)
);

Parameters:
values - associative array
Since:
FORMfields v3.0

loadQuery

public void loadQuery(string sql)

Loads the data from an SQL query. This method intelligently modifies the SQL according to any click sorting that has occured.

Parameters:
sql - any valid SQL query string
Since:
FORMfields v1.0

loadResultSet

public void loadResultSet(resource rs)

Loads the data from a results set.

Parameters:
rs - an SQL result set
Since:
FORMfields v1.0

loadRowsAndColumns

public void loadRowsAndColumns(array values, int rows, int cols, array headings)

Loads array data and formats it into the specified number of rows and columns. This method loads values in row major order.

Parameters:
values - single dimensional array of values
rows - the number of rows to format the data into or null if the number of rows will be determined by the number of columns
cols - the number of columns to format the data into or null if the number of columns will be determined by the number of rows
headings - an array of headings or null
Since:
FORMfields v3.0

translateRows

public void translateRows(string attrName, string pattern, string className)

Uses pattern to determine whether to set a row's CSS. This method iterates through the list of rows and if the row element at index attrName is exactly equal to pattern then sets the rowClass to className for this row.

Parameters:
attrName - a heading or row index
pattern - value of the cell to search for
className - a CSS class name for the found rows
Since:
FORMfields v1.0

FORMfields