\Dewdrop\Db\SelectTableListing

This class can assist in creating a Select object to provide the data for Listing. It traverses foreign keys, looks at many-to-many relationships and EAV fields, etc. and folds them into the Select to ensure that they conform to naming conventions Dewdrop uses when rendering Listings.

There are a couple known limitations with this tool right now:

Summary

Methods
Properties
Constants
__construct()
setReferenceTitleColumn()
reset()
select()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
generateSelect()
selectFromTable()
selectForeignKeyValues()
selectFieldProviderValues()
getAlias()
findReferenceTitleColumn()
$table
$db
$select
$aliases
$referenceTitleColumns
N/A

Properties

$table

$table : \Dewdrop\Db\Table

The table for which we're generating the listing.

Type

\Dewdrop\Db\Table

$db

$db : \Dewdrop\Db\Adapter

The DB adapter associated with the table.

Type

\Dewdrop\Db\Adapter

$select

$select : \Dewdrop\Db\Select

The Select object that was generated for the listing. If you've manipulated the options or need to regenerate the listing for some other reason, call reset() and then select().

Type

\Dewdrop\Db\Select

$aliases

$aliases : array

Table aliases used so far while building the Select.

Type

array

$referenceTitleColumns

$referenceTitleColumns : 

Any custom reference table title columns. We'll attempt use "name", "title" or whatever the first column in the referenced table happens to be, but you can override that behavior with setReferenceTitleColumn().

Type

Methods

__construct()

__construct(\Dewdrop\Db\Table  $table) 

Provide the table for which we're generated a listing Select.

Parameters

\Dewdrop\Db\Table $table

setReferenceTitleColumn()

setReferenceTitleColumn(string  $foreignKeyColumn, mixed  $titleColumn) : $this

Override the reference title column for a foreign key. The first parameter should be the name of the foreign key column in the primary table. The second parameter is a column name from the referenced table, an Expr object, or a callback that will be passed the generated table alias for the referenced table for use in creating an Expr.

Parameters

string $foreignKeyColumn
mixed $titleColumn

Returns

$this

reset()

reset() : $this

Reset the generated Select and associated table aliases, if you've tweaked options and need to generate the Select again.

Returns

$this

select()

select() : \Dewdrop\Db\Select

Get the generated Select object. Will generated it, if that hasn't occurred yet.

Returns

\Dewdrop\Db\Select

generateSelect()

generateSelect() : \Dewdrop\Db\Select

Generate the Select object for this listing. Will include the columns from the listing's Table, any foreign key references, and also allow all field providers to augment the Select as needed.

Returns

\Dewdrop\Db\Select

selectFromTable()

selectFromTable(\Dewdrop\Db\Select  $select) : \Dewdrop\Db\Select

Get the basic columns contained in the listing table.

Parameters

\Dewdrop\Db\Select $select

Returns

\Dewdrop\Db\Select

selectForeignKeyValues()

selectForeignKeyValues(\Dewdrop\Db\Select  $select) : \Dewdrop\Db\Select

Join against any tables referenced by foreign keys in order to get a reasonable value to display for them. If the foreign key in the listing table is nullable, we'll use a LEFT JOIN so that a missing foreign key value does not exclude the record from the result set.

We follow a naming convention for these values in result sets: the foreign key ends with "_id" and the value in the result set is aliased to that foreign key column name minus "_id". For example, let's say the foreign key column was "favorite_book_id". In the result set for the listing query, we'd include an alias of "favorite_book" that pointed to the "title" column of the referenced "books" table. That way, both the integer favorite_book_id and the title favorite_book are available when we render the listing.

Parameters

\Dewdrop\Db\Select $select

Returns

\Dewdrop\Db\Select

selectFieldProviderValues()

selectFieldProviderValues(\Dewdrop\Db\Select  $select) : \Dewdrop\Db\Select

Allow each field provider on the Table to augment the Select object.

This is how many-to-many and EAV fields get their values folded into a listing query.

Parameters

\Dewdrop\Db\Select $select

Returns

\Dewdrop\Db\Select

getAlias()

getAlias(string  $tableName, null|integer  $instance = null,   $anchorColumn = null) : string

Get an alias for the provided table name.

Parameters

string $tableName
null|integer $instance
$anchorColumn

Returns

string

findReferenceTitleColumn()

findReferenceTitleColumn(  $localColumn, array  $reference, string  $alias) : string|\Dewdrop\Db\Expr

Determine a reasonable value to use as a title for a foreign key reference. We'll look for a name or title in the referenced table. If neither is present, we just grab the first column, which is probably the ID itself.

However, you can call setReferenceTitleColumn() to supply a different column to use or an Expr object.

Parameters

$localColumn
array $reference
string $alias

Returns

string|\Dewdrop\Db\Expr