PHP Class PodsData, pods

Show file Open project: pods-framework/pods Class Usage Examples

Public Properties

Property Type Description
$aliases array
$api PodsAPI
$data
$detail_page
$display_errors boolean
$field_id string
$field_index string
$field_slug string
$fields array
$filters array
$id integer
$insert_id
$instance PodsData
$join string
$limit integer
$orderby string
$page integer
$page_var string
$pagination boolean
$pod null
$pod_data array | boolean | mixed | null | void
$row
$row_number integer
$search boolean
$search_fields array
$search_mode string
$search_query string
$search_var string
$search_where string
$select null
$sql string Last select() query SQL
$table null
$total
$total_found
$total_found_calculated boolean
$total_sql string Last total sql
$traversal array Holds Traversal information about Pods
$traverse array Holds custom Traversals to be included
$where array
$where_default array

Protected Properties

Property Type Description
$field_types array
$prefix string

Public Methods

Method Description
__construct ( string $pod = null, integer $id, boolean $strict = true ) : PodsData Data Abstraction Class for Pods
build ( array $params ) : boolean | mixed | string Build/Rewrite dynamic SQL and handle search/filter/sort
calculate_totals ( )
delete ( string $table, array $where, array $where_format = null ) : array | boolean | mixed | null | void Delete an item
fetch ( integer $row = null, boolean $explicit_set = true ) : mixed Fetch a new row for the current pod_data
get_column_data ( string $column_name, string $table ) : array Gets column data information from a table
get_sql ( $sql ) Get the complete sql
get_table_columns ( string $table ) : array Gets column information from a table
get_tables ( boolean $wp_core = true, boolean $pods_tables = true ) : array Gets all tables in the WP database, optionally exclude WP core tables, and/or Pods table by settings the parameters to false.
init ( string $pod = null, integer $id, boolean $strict = true ) : PodsData Singleton handling for a basic pods_data() request
insert ( string $table, array $data, array $format = null ) : integer | boolean Insert an item, eventually mapping to WPDB::insert
insert_on_duplicate ( string $table, array $data, array $formats = [] ) : mixed
nth ( integer | string $nth ) : boolean Fetch the nth state
position ( ) : integer Fetch the current position in the loop (starting at 1)
prepare ( string $sql, array $data ) : boolean | null | string Prepare values for the DB
query ( string | array $sql, string $error = 'Database Error', null $results_error = null, null $no_results_error = null ) : array | boolean | mixed | null | void
query_field ( string | integer $field, array | string $q, array $pod = null, object &$params = null ) : string | null Get the string to use in a query for matching, uses WP_Query meta_query arguments
query_fields ( array $fields, array $pod = null, object &$params = null ) : string | null Get the string to use in a query for WHERE/HAVING, uses WP_Query meta_query arguments
reorder ( string $table, string $weight_field, string $id_field, array $ids ) : boolean Reorder Items
reset ( integer $row = null ) : mixed Reset the current data
select ( array $params ) : array | boolean | mixed Select items, eventually building dynamic query
table ( array | string $table, string $object = '' ) Handle tables like they are Pods (for traversal in select/build)
table_alter ( string $table, string $changes ) : array | boolean | mixed | null | void Alter a Table
table_create ( string $table, string $fields, boolean $if_not_exists = false ) : array | boolean | mixed | null | void Create a Table
table_drop ( string $table ) : array | boolean | mixed | null | void Drop a Table
table_truncate ( string $table ) : array | boolean | mixed | null | void Truncate a Table
total ( ) : integer Fetch the total row count returned
total_found ( ) : integer Fetch the total row count total
traverse ( array $fields = null, null $all_fields = null, object $params = null ) : array Recursively join tables based on fields
traverse_build ( array $fields = null, object $params = null ) : array Setup fields for traversal
traverse_recurse ( array $traverse_recurse ) : array Recursively join tables based on fields
update ( string $table, array $data, array $where, array $format = null, array $where_format = null ) : boolean Update an item, eventually mapping to WPDB::update
zebra ( ) : boolean Fetch the zebra state

Private Methods

Method Description
do_hook ( ) Handle filters / actions for the class

Method Details

__construct() public method

Data Abstraction Class for Pods
Since: 2.0
public __construct ( string $pod = null, integer $id, boolean $strict = true ) : PodsData
$pod string Pod name
$id integer Pod Item ID
$strict boolean If true throws an error if a pod is not found.
return PodsData

build() public method

Build/Rewrite dynamic SQL and handle search/filter/sort
Since: 2.0
public build ( array $params ) : boolean | mixed | string
$params array
return boolean | mixed | string

calculate_totals() public method

public calculate_totals ( )

delete() public method

Delete an item
Since: 2.0
public delete ( string $table, array $where, array $where_format = null ) : array | boolean | mixed | null | void
$table string Table name
$where array A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
$where_format array (optional) An array of formats to be mapped to each of the values in $where.
return array | boolean | mixed | null | void

fetch() public method

Fetch a new row for the current pod_data
Since: 2.0
public fetch ( integer $row = null, boolean $explicit_set = true ) : mixed
$row integer Row number to fetch
$explicit_set boolean Whether to set explicitly (use false when in loop)
return mixed

get_column_data() public static method

Gets column data information from a table
Since: 2.0
public static get_column_data ( string $column_name, string $table ) : array
$column_name string Column name
$table string Table name
return array

get_sql() public method

Get the complete sql
Since: 2.0.5
public get_sql ( $sql )

get_table_columns() public static method

Gets column information from a table
Since: 2.0
public static get_table_columns ( string $table ) : array
$table string Table Name
return array

get_tables() public static method

Gets all tables in the WP database, optionally exclude WP core tables, and/or Pods table by settings the parameters to false.
Since: 2.0
public static get_tables ( boolean $wp_core = true, boolean $pods_tables = true ) : array
$wp_core boolean
$pods_tables boolean restrict Pods 2.x tables
return array

init() public static method

Singleton handling for a basic pods_data() request
Since: 2.3.5
public static init ( string $pod = null, integer $id, boolean $strict = true ) : PodsData
$pod string Pod name
$id integer Pod Item ID
$strict boolean If true throws an error if a pod is not found.
return PodsData

insert() public method

Insert an item, eventually mapping to WPDB::insert
Since: 2.0
public insert ( string $table, array $data, array $format = null ) : integer | boolean
$table string Table name
$data array Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
$format array (optional) An array of formats to be mapped to each of the value in $data.
return integer | boolean The ID of the item

insert_on_duplicate() public static method

Since: 2.0
public static insert_on_duplicate ( string $table, array $data, array $formats = [] ) : mixed
$table string Name of the table to update
$data array column => value pairs
$formats array For $wpdb->prepare, uses sprintf formatting
return mixed Sanitized query string

nth() public method

Fetch the nth state
Since: 2.3
public nth ( integer | string $nth ) : boolean
$nth integer | string The $nth to match on the PodsData::row_number
return boolean Whether $nth matches

position() public method

Fetch the current position in the loop (starting at 1)
Since: 2.3
public position ( ) : integer
return integer Current row number (+1)

prepare() public static method

Prepare values for the DB
Since: 2.0
public static prepare ( string $sql, array $data ) : boolean | null | string
$sql string SQL to prepare
$data array Data to add to the sql prepare statement
return boolean | null | string

query() public static method

Since: 2.0
public static query ( string | array $sql, string $error = 'Database Error', null $results_error = null, null $no_results_error = null ) : array | boolean | mixed | null | void
$sql string | array The SQL to execute
$error string Error to throw on problems
$results_error null (optional)
$no_results_error null (optional)
return array | boolean | mixed | null | void Result of the query

query_field() public static method

Get the string to use in a query for matching, uses WP_Query meta_query arguments
See also: PodsData::query_fields
Since: 2.3
public static query_field ( string | integer $field, array | string $q, array $pod = null, object &$params = null ) : string | null
$field string | integer Field name or array index
$q array | string Query array (meta_query) or string for matching
$pod array Related Pod
$params object Parameters passed from select()
return string | null Query field string

query_fields() public static method

Get the string to use in a query for WHERE/HAVING, uses WP_Query meta_query arguments
Since: 2.3
public static query_fields ( array $fields, array $pod = null, object &$params = null ) : string | null
$fields array Array of field matches for querying
$pod array Related Pod
$params object Parameters passed from select()
return string | null Query string for WHERE/HAVING

reorder() public method

Reorder Items
Since: 2.0
public reorder ( string $table, string $weight_field, string $id_field, array $ids ) : boolean
$table string Table name
$weight_field string
$id_field string
$ids array
return boolean

reset() public method

Reset the current data
Since: 2.0
public reset ( integer $row = null ) : mixed
$row integer Row number to reset to
return mixed

select() public method

Select items, eventually building dynamic query
Since: 2.0
public select ( array $params ) : array | boolean | mixed
$params array
return array | boolean | mixed

table() public method

Handle tables like they are Pods (for traversal in select/build)
public table ( array | string $table, string $object = '' )
$table array | string
$object string

table_alter() public static method

Alter a Table
Since: 2.0
public static table_alter ( string $table, string $changes ) : array | boolean | mixed | null | void
$table string Table name
$changes string
return array | boolean | mixed | null | void

table_create() public static method

Create a Table
Since: 2.0
public static table_create ( string $table, string $fields, boolean $if_not_exists = false ) : array | boolean | mixed | null | void
$table string Table name
$fields string
$if_not_exists boolean Check if the table exists.
return array | boolean | mixed | null | void

table_drop() public static method

Drop a Table
Since: 2.0
public static table_drop ( string $table ) : array | boolean | mixed | null | void
$table string Table name
return array | boolean | mixed | null | void

table_truncate() public static method

Truncate a Table
Since: 2.0
public static table_truncate ( string $table ) : array | boolean | mixed | null | void
$table string Table name
return array | boolean | mixed | null | void

total() public method

Fetch the total row count returned
Since: 2.0
public total ( ) : integer
return integer Number of rows returned by select()

total_found() public method

Fetch the total row count total
Since: 2.0
public total_found ( ) : integer
return integer Number of rows found by select()

traverse() public method

Recursively join tables based on fields
public traverse ( array $fields = null, null $all_fields = null, object $params = null ) : array
$fields array Fields to recurse
$all_fields null (optional) If $fields is empty then traverse all fields, argument does not need to be passed
$params object (optional) Parameters from build()
return array Array of joins

traverse_build() public method

Setup fields for traversal
Since: 2.0
public traverse_build ( array $fields = null, object $params = null ) : array
$fields array Associative array of fields data
$params object (optional) Parameters from build()
return array Traverse feed

traverse_recurse() public method

Recursively join tables based on fields
Since: 2.0
public traverse_recurse ( array $traverse_recurse ) : array
$traverse_recurse array Array of traversal options
return array Array of table joins

update() public method

Update an item, eventually mapping to WPDB::update
Since: 2.0
public update ( string $table, array $data, array $where, array $format = null, array $where_format = null ) : boolean
$table string Table name
$data array Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
$where array A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
$format array (optional) An array of formats to be mapped to each of the values in $data.
$where_format array (optional) An array of formats to be mapped to each of the values in $where.
return boolean

zebra() public method

Fetch the zebra state
See also: PodsData::nth
Since: 1.12
public zebra ( ) : boolean
return boolean Zebra state

Property Details

$aliases public property

public array $aliases
return array

$api public property

public PodsAPI $api
return PodsAPI

$data public property

public $data

$detail_page public property

public $detail_page

$display_errors public static property

public static bool $display_errors
return boolean

$field_id public property

public string $field_id
return string

$field_index public property

public string $field_index
return string

$field_slug public property

public string $field_slug
return string

$field_types protected static property

protected static array $field_types
return array

$fields public property

public array $fields
return array

$filters public property

public array $filters
return array

$id public property

public int $id
return integer

$insert_id public property

public $insert_id

$instance static public property

static public PodsData $instance
return PodsData

$join public property

public string $join
return string

$limit public property

public int $limit
return integer

$orderby public property

public string $orderby
return string

$page public property

public int $page
return integer

$page_var public property

public string $page_var
return string

$pagination public property

public bool $pagination
return boolean

$pod public property

public null $pod
return null

$pod_data public property

public array|bool|mixed|null|void $pod_data
return array | boolean | mixed | null | void

$prefix protected static property

protected static string $prefix
return string

$row public property

public $row

$row_number public property

public int $row_number
return integer

$search_fields public property

public array $search_fields
return array

$search_mode public property

public string $search_mode
return string

$search_query public property

public string $search_query
return string

$search_var public property

public string $search_var
return string

$search_where public property

public string $search_where
return string

$select public property

public null $select
return null

$sql public property

Last select() query SQL
public string $sql
return string

$table public property

public null $table
return null

$total public property

public $total

$total_found public property

public $total_found

$total_found_calculated public property

public bool $total_found_calculated
return boolean

$total_sql public property

Last total sql
public string $total_sql
return string

$traversal public property

Holds Traversal information about Pods
public array $traversal
return array

$traverse public property

Holds custom Traversals to be included
public array $traverse
return array

$where public property

public array $where
return array

$where_default public property

public array $where_default
return array