PHP Class __WPDKDBTable

## Overview This class describe a database table. For default describe the table and gets the primary key name. This primary key is used for operations as delete one or more records.
Deprecation: since 1.5.1 - Use WPDKDBTableModel instead
Author: =undo= ([email protected])
Show file Open project: wpxtreme/wpdk

Public Properties

Property Type Description
$primaryKey string Name of field as primary key
$sqlFilename string The filename of SQL file with the database table structure and init data.
$tableName string The name of the database table with the WordPress prefix

Public Methods

Method Description
__construct ( string $table_name, string $sql_file = '' ) Create an instance of __WPDKDBTable class
_select ( object $query = null, string $order_by = '', string $order = 'ASC' ) : array Return an array key-value with key as primary key of records.
count ( string $distinct = '', array $status = '' ) : integer | array Return the integer count of all rows when $distinct param is emmpty or an array of distinct count for $distinct column.
delete ( integer | array $pks ) : integer | boolean Delete one or more record from table. Return the number of rows affected/selected or false on error.
deleteWherePrimaryKey ( $id )
groupBy ( string $column, boolean $order_by = true, string $order = 'ASC' ) : array Return a column select group by and sorter
map ( object $source_row, object $destination_object ) : object | boolean Map the properties fields of single database row into a destination object model.
primaryKey ( ) : string Return the name of the primary key
select ( integer $id = false, $order_by = '', $order = 'ASC', $where = '' ) : object | array Return a single instance of $object class or an array of $object class. FALSE otherwise.
selectWhereID ( $id, $object, $output = OBJECT )
update ( ) : boolean Do an update the table via WordPress dbDelta() function. Apply a new SQL file on the exists (or do not exists) table. Return TRUE on success
where ( WPDKDBTableRow $query, string $prefix = '' ) : string Return the WHERE condiction string from a object

Method Details

__construct() public method

Create an instance of __WPDKDBTable class
public __construct ( string $table_name, string $sql_file = '' )
$table_name string The name of the database table without WordPress prefix
$sql_file string Optional. The filename of SQL file with the database table structure and init data.

_select() public method

Return an array key-value with key as primary key of records.
public _select ( object $query = null, string $order_by = '', string $order = 'ASC' ) : array
$query object Optional. $query An object used for build the where. Usualy a subclass of WPDKDBTableRow
$order_by string Optional. Order by column name
$order string Optional. Order. Default ASC
return array

count() public method

Return the integer count of all rows when $distinct param is emmpty or an array of distinct count for $distinct column.
public count ( string $distinct = '', array $status = '' ) : integer | array
$distinct string Optional. Name of field to distinct group by
$status array Optional. Key value paier for where condiction on field: key = fields, vallue = value
return integer | array

delete() public method

Use the primaryKey.
public delete ( integer | array $pks ) : integer | boolean
$pks integer | array Any single int or array list of primary keys
return integer | boolean

deleteWherePrimaryKey() public method

Deprecation: Use delete() instead
public deleteWherePrimaryKey ( $id )

groupBy() public method

Return a column select group by and sorter
public groupBy ( string $column, boolean $order_by = true, string $order = 'ASC' ) : array
$column string name of column
$order_by boolean Optional. Order for column. Defaul TRUE
$order string Optional. Type of sorter. Default 'ASC'
return array

map() public method

The $destination_object can implement a method named column_[property] to override map process.
public map ( object $source_row, object $destination_object ) : object | boolean
$source_row object Database record
$destination_object object Object to map
return object | boolean The destination object with new properties or FALSE if error.

primaryKey() public method

Return the name of the primary key
public primaryKey ( ) : string
return string

select() public method

If select more rows as array, the OBJECT_K flag is used. In this way you have the key array equal to id of the country
Deprecation: Use _select() instead
public select ( integer $id = false, $order_by = '', $order = 'ASC', $where = '' ) : object | array
$id integer ID of record or array of id
return object | array

selectWhereID() public method

Deprecation: Use select() instead
public selectWhereID ( $id, $object, $output = OBJECT )

update() public method

Do an update the table via WordPress dbDelta() function. Apply a new SQL file on the exists (or do not exists) table. Return TRUE on success
public update ( ) : boolean
return boolean

where() public method

Return the WHERE condiction string from a object
public where ( WPDKDBTableRow $query, string $prefix = '' ) : string
$query WPDKDBTableRow An instance of WPDKDBTableRow
$prefix string Optional. Table prefix.
return string

Property Details

$primaryKey public property

Name of field as primary key
public string $primaryKey
return string

$sqlFilename public property

The filename of SQL file with the database table structure and init data.
public string $sqlFilename
return string

$tableName public property

The name of the database table with the WordPress prefix
public string $tableName
return string