PHP Class Pods, pods

Inheritance: implements Iterator
Mostra file Open project: pods-framework/pods Class Usage Examples

Public Properties

Property Type Description
$alt_data PodsData
$api PodsAPI
$body_classes
$data PodsData
$datatype
$datatype_id
$deprecated
$detail_page string
$display_errors boolean
$fields array
$filters array
$id integer
$limit integer
$meta
$meta_extra
$meta_properties
$offset integer
$page integer | mixed
$page_template SEO related vars for Pod Pages
$page_var string
$pagination boolean
$params array
$pod string
$pod_data array | boolean | mixed | null | void
$pod_id integer
$row Current pod item array
$row_override Override pod item array
$rows Array of pod item arrays
$search boolean
$search_mode string
$search_var string
$sql Last SQL query used by a find()
$total integer
$total_found integer
$ui array

Public Methods

Method Description
__call ( $name, $args ) : mixed Handle methods that have been deprecated and any aliasing
__construct ( string $pod = null, mixed $id = null ) : Pods Constructor - Pods Framework core
__get ( $name ) : mixed Handle variables that have been deprecated and PodsData vars
add ( array | string $data = null, mixed $value = null ) : integer Add an item to a Pod by giving an array of field data or set a specific field to a specific value if you're just wanting to add a new item but only set one field.
add_to ( string $field, mixed $value, integer $id = null ) : integer Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date field, or add text to a text field
current ( ) : mixed | boolean Get current Iterator row
data ( ) : array | boolean Return an array of all rows returned from a find() call.
delete ( integer $id = null ) : boolean Delete an item
display ( string | array $name, boolean $single = null ) : string | null | false Return the output for a field. If you want the raw value for use in PHP for custom manipulation, you will want to use field() instead. This function will automatically convert arrays into a list of text such as "Rick, John, and Gary"
do_magic_tags ( string $code ) : string Replace magic tags with their values
duplicate ( integer $id = null ) : integer | boolean Duplicate an item
exists ( ) : boolean Whether a Pod item exists or not when using fetch() or construct with an ID or slug
export ( array $fields = null, integer $id = null, $format = null ) : array | boolean Export an item's data
export_data ( array $params = null ) : array Export data from all items
fetch ( integer $id = null, boolean $explicit_set = true ) : array Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find().
field ( string | array $name, boolean $single = null, boolean $raw = false ) : mixed | null Return the value for a field.
fields ( null $field = null, null $option = null ) : boolean | mixed Return field array from a Pod, a field's data, or a field option
filters ( $params = null ) : string Return a filter form for searching a Pod
find ( array $params = null, integer $limit = 15, string $where = null, string $sql = null ) : Pods Find items of a pod, much like WP_Query, but with advanced table handling.
first_id ( array $params_override = null ) : integer Return the first item ID
form ( array $params = null, string $label = null, string $thank_you = null ) : boolean | mixed Embed a form to add / edit a pod item from within your theme. Provide an array of $fields to include and override options where needed. For WP object based Pods, you can pass through the WP object field names too, such as "post_title" or "post_content" for example.
has ( string $field, mixed $value, integer $id = null ) : boolean Check if an item field has a specific value in it
helper ( string $helper, string $value = null, string $name = null ) : mixed Run a helper within a Pod Page or WP Template
id ( ) : integer Return the item ID
import ( mixed $import_data, boolean $numeric_mode = false, string $format = null ) : array Import data / Save multiple rows of data at once
index ( ) : string Return the item name
input ( string | array $field, $input_name = null, mixed $value = '__null' ) : string Return a field input for a specific field
is ( string $field, mixed $value, integer $id = null ) : boolean Check if an item field is a specific value
is_iterator ( ) : boolean Check if in Iterator mode
key ( ) : integer | boolean Get current Iterator key
last_id ( array $params_override = null ) : integer Return the last item ID
next ( ) : void | boolean Move onto the next Iterator row
next_id ( integer $id = null, $params_override = null ) : integer Return the next item ID, loops at the first id to return the last
nth ( integer | string $nth = null ) : boolean Fetch the nth state
pagination ( $params = null ) : string Display the pagination controls, types supported by default are simple, paginate and advanced. The base and format parameters are used only for the paginate view.
position ( ) : integer Fetch the current position in the loop (starting at 1)
prev_id ( integer $id = null, array $params_override = null ) : integer Return the previous item ID, loops at the last id to return the first
raw ( string | array $name, boolean $single = null ) : string | null | false Return the raw output for a field If you want the raw value for use in PHP for custom manipulation, you will want to use field() instead. This function will automatically convert arrays into a list of text such as "Rick, John, and Gary"
remove_from ( string $field, mixed $value = null, integer $id = null ) : integer Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove time to a date field
reset ( integer $row = null ) : Pods (Re)set the MySQL result pointer
reset_pod ( ) : boolean Reset Pod
rewind ( ) : void | boolean Rewind Iterator
row ( ) : array Return row array for an item
save ( array | string $data = null, mixed $value = null, integer $id = null, array $params = null ) : integer Save an item by giving an array of field data or set a specific field to a specific value.
stop_iterator ( ) : void Turn off Iterator mode to off
template ( $template_name, string $code = null, boolean $deprecated = false ) : mixed Display the page template
total ( ) : integer Fetch the total row count returned by the last call to find(), based on the 'limit' parameter set.
total_found ( ) : integer Fetch the total amount of rows found by the last call to find(), regardless of the 'limit' parameter set.
total_pages ( null | integer $limit = null, null | integer $offset = null, null | integer $total = null ) : integer Fetch the total number of pages, based on total rows found and the last find() limit
ui ( mixed $options = null, boolean $amend = false ) : PodsUI | void Generate UI for Data Management
valid ( ) : boolean Whether this Pod object is valid or not
view ( array $fields = null ) : mixed
zebra ( ) : boolean Fetch the zebra switch

Private Methods

Method Description
do_hook ( ) : mixed Handle filters / actions for the class
process_magic_tags ( string $tag ) : string Replace magic tags with their values

Method Details

__call() public method

Handle methods that have been deprecated and any aliasing
Since: 2.0
public __call ( $name, $args ) : mixed
return mixed

__construct() public method

Constructor - Pods Framework core
Since: 1.0.0
public __construct ( string $pod = null, mixed $id = null ) : Pods
$pod string The pod name
$id mixed (optional) The ID or slug, to load a single record; Provide array of $params to run 'find'
return Pods

__get() public method

Handle variables that have been deprecated and PodsData vars
Since: 2.0
public __get ( $name ) : mixed
return mixed

add() public method

You may be looking for save() in most cases where you're setting a specific field.
See also: PodsAPI::save_pod_item
Since: 2.0
public add ( array | string $data = null, mixed $value = null ) : integer
$data array | string Either an associative array of field information or a field name
$value mixed (optional) Value of the field, if $data is a field name
return integer The item ID

add_to() public method

Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date field, or add text to a text field
See also: PodsAPI::save_pod_item
Since: 2.3
public add_to ( string $field, mixed $value, integer $id = null ) : integer
$field string Field name
$value mixed ID(s) to add, int|float to add to number field, string for dates (+1 week), or string for text
$id integer (optional) ID of the pod item to update
return integer The item ID

current() public method

Get current Iterator row
public current ( ) : mixed | boolean
return mixed | boolean

data() public method

Most of the time, you will want to loop through data using fetch() instead of using this function.
Since: 2.0
public data ( ) : array | boolean
return array | boolean An array of all rows returned from a find() call, or false if no items returned

delete() public method

Delete an item
See also: PodsAPI::delete_pod_item
Since: 2.0
public delete ( integer $id = null ) : boolean
$id integer ID of the Pod item to delete
return boolean Whether the item was successfully deleted

display() public method

Return the output for a field. If you want the raw value for use in PHP for custom manipulation, you will want to use field() instead. This function will automatically convert arrays into a list of text such as "Rick, John, and Gary"
Since: 2.0
public display ( string | array $name, boolean $single = null ) : string | null | false
$name string | array The field name, or an associative array of parameters
$single boolean (optional) For tableless fields, to return an array or the first
return string | null | false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields

do_magic_tags() public method

Replace magic tags with their values
Since: 2.0
public do_magic_tags ( string $code ) : string
$code string The content to evaluate
return string Code with Magic Tags evaluated

duplicate() public method

Duplicate an item
See also: PodsAPI::duplicate_pod_item
Since: 2.0
public duplicate ( integer $id = null ) : integer | boolean
$id integer ID of the pod item to duplicate
return integer | boolean ID of the new pod item

exists() public method

Whether a Pod item exists or not when using fetch() or construct with an ID or slug
Since: 2.0
public exists ( ) : boolean
return boolean

export() public method

Export an item's data
See also: PodsAPI::export_pod_item
Since: 2.0
public export ( array $fields = null, integer $id = null, $format = null ) : array | boolean
$fields array (optional) Fields to export
$id integer (optional) ID of the pod item to export
return array | boolean Data array of the exported pod item

export_data() public method

Export data from all items
See also: PodsAPI::export
Since: 2.3
public export_data ( array $params = null ) : array
$params array An associative array of parameters
return array Data arrays of all exported pod items

fetch() public method

You can rewind the list back to the start by using reset(). Providing an $id will fetch a specific item from a Pod, much like a call to pods(), and can handle either an id or slug.
See also: PodsData::fetch
Since: 2.0
public fetch ( integer $id = null, boolean $explicit_set = true ) : array
$id integer ID or slug of the item to fetch
$explicit_set boolean Whether to set explicitly (use false when in loop)
return array An array of fields from the row

field() public method

If you are getting a field for output in a theme, most of the time you will want to use display() instead. This function will return arrays for relationship and file fields.
Since: 2.0
public field ( string | array $name, boolean $single = null, boolean $raw = false ) : mixed | null
$name string | array The field name, or an associative array of parameters
$single boolean (optional) For tableless fields, to return the whole array or the just the first item, or an associative array of parameters
$raw boolean (optional) Whether to return the raw value, or to run through the field type's display method, or an associative array of parameters
return mixed | null Value returned depends on the field type, null if the field doesn't exist, false if no value returned for tableless fields

fields() public method

Return field array from a Pod, a field's data, or a field option
Since: 2.0
public fields ( null $field = null, null $option = null ) : boolean | mixed
$field null
$option null
return boolean | mixed

filters() public method

Return a filter form for searching a Pod
Since: 2.0
public filters ( $params = null ) : string
return string Filters HTML

find() public method

Find items of a pod, much like WP_Query, but with advanced table handling.
Since: 2.0
public find ( array $params = null, integer $limit = 15, string $where = null, string $sql = null ) : Pods
$params array An associative array of parameters
$limit integer (optional) (deprecated) Limit the number of items to find, use -1 to return all items with no limit
$where string (optional) (deprecated) SQL WHERE declaration to use
$sql string (optional) (deprecated) For advanced use, a custom SQL query to run
return Pods The pod object

first_id() public method

Return the first item ID
Since: 2.3
public first_id ( array $params_override = null ) : integer
$params_override array
return integer

form() public method

Embed a form to add / edit a pod item from within your theme. Provide an array of $fields to include and override options where needed. For WP object based Pods, you can pass through the WP object field names too, such as "post_title" or "post_content" for example.
Since: 2.0
public form ( array $params = null, string $label = null, string $thank_you = null ) : boolean | mixed
$params array (optional) Fields to show on the form, defaults to all fields
$label string (optional) Save button label, defaults to "Save Changes"
$thank_you string (optional) Thank you URL to send to upon success
return boolean | mixed

has() public method

Check if an item field has a specific value in it
Since: 2.3.3
public has ( string $field, mixed $value, integer $id = null ) : boolean
$field string Field name
$value mixed Value to check
$id integer (optional) ID of the pod item to check
return boolean Whether the value was found

helper() public method

Run a helper within a Pod Page or WP Template
See also: Pods_Helpers::helper
Since: 2.0
public helper ( string $helper, string $value = null, string $name = null ) : mixed
$helper string Helper name
$value string Value to run the helper on
$name string Field name
return mixed Anything returned by the helper

id() public method

Return the item ID
Since: 2.0
public id ( ) : integer
return integer

import() public method

Import data / Save multiple rows of data at once
See also: PodsAPI::import
Since: 2.3
public import ( mixed $import_data, boolean $numeric_mode = false, string $format = null ) : array
$import_data mixed PHP associative array or CSV input
$numeric_mode boolean Use IDs instead of the name field when matching
$format string Format of import data, options are php or csv
return array IDs of imported items

index() public method

Return the item name
Since: 2.0
public index ( ) : string
return string

input() public method

Return a field input for a specific field
Since: 2.3.10
public input ( string | array $field, $input_name = null, mixed $value = '__null' ) : string
$field string | array Field name or Field data array
$value mixed Current value to use
return string Field Input HTML

is() public method

Check if an item field is a specific value
Since: 2.3.3
public is ( string $field, mixed $value, integer $id = null ) : boolean
$field string Field name
$value mixed Value to check
$id integer (optional) ID of the pod item to check
return boolean Whether the value was found

is_iterator() public method

Check if in Iterator mode
public is_iterator ( ) : boolean
return boolean

key() public method

Get current Iterator key
public key ( ) : integer | boolean
return integer | boolean

last_id() public method

Return the last item ID
Since: 2.3
public last_id ( array $params_override = null ) : integer
$params_override array
return integer

next() public method

Move onto the next Iterator row
public next ( ) : void | boolean
return void | boolean

next_id() public method

Return the next item ID, loops at the first id to return the last
Since: 2.0
public next_id ( integer $id = null, $params_override = null ) : integer
$id integer
return integer

nth() public method

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

pagination() public method

Display the pagination controls, types supported by default are simple, paginate and advanced. The base and format parameters are used only for the paginate view.
Since: 2.0
public pagination ( $params = null ) : string
return string Pagination HTML

position() public method

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

prev_id() public method

Return the previous item ID, loops at the last id to return the first
Since: 2.0
public prev_id ( integer $id = null, array $params_override = null ) : integer
$id integer
$params_override array
return integer

raw() public method

Return the raw output for a field If you want the raw value for use in PHP for custom manipulation, you will want to use field() instead. This function will automatically convert arrays into a list of text such as "Rick, John, and Gary"
Since: 2.0
public raw ( string | array $name, boolean $single = null ) : string | null | false
$name string | array The field name, or an associative array of parameters
$single boolean (optional) For tableless fields, to return an array or the first
return string | null | false The output from the field, null if the field doesn't exist, false if no value returned for tableless fields

remove_from() public method

Remove an item from the values of a relationship field, remove a value from a number field (field-1), remove time to a date field
See also: PodsAPI::save_pod_item
Since: 2.3.3
public remove_from ( string $field, mixed $value = null, integer $id = null ) : integer
$field string Field name
$value mixed ID(s) to add, int|float to add to number field, string for dates (-1 week), or string for text
$id integer (optional) ID of the pod item to update
return integer The item ID

reset() public method

(Re)set the MySQL result pointer
See also: PodsData::reset
Since: 2.0
public reset ( integer $row = null ) : Pods
$row integer ID of the row to reset to
return Pods The pod object

reset_pod() public method

Reset Pod
See also: PodsAPI::reset_pod
Since: 2.1.1
public reset_pod ( ) : boolean
return boolean Whether the Pod was successfully reset

rewind() public method

Rewind Iterator
public rewind ( ) : void | boolean
return void | boolean

row() public method

Return row array for an item
Since: 2.0
public row ( ) : array
return array

save() public method

Though this function has the capacity to add new items, best practice should direct you to use add() for that instead.
See also: PodsAPI::save_pod_item
Since: 2.0
public save ( array | string $data = null, mixed $value = null, integer $id = null, array $params = null ) : integer
$data array | string Either an associative array of field information or a field name
$value mixed (optional) Value of the field, if $data is a field name
$id integer (optional) ID of the pod item to update
$params array (optional) Additional params to send to save_pod_item
return integer The item ID

stop_iterator() public method

Turn off Iterator mode to off
public stop_iterator ( ) : void
return void

template() public method

Display the page template
See also: Pods_Templates::template
Since: 2.0
public template ( $template_name, string $code = null, boolean $deprecated = false ) : mixed
$code string Custom template code to use instead
$deprecated boolean Whether to use deprecated functionality based on old function usage
return mixed Template output

total() public method

This is different than the total number of rows found in the database, which you can get with total_found().
See also: PodsData::total
Since: 2.0
public total ( ) : integer
return integer Number of rows returned by find(), based on the 'limit' parameter set

total_found() public method

This is different than the total number of rows limited by the current call, which you can get with total().
See also: PodsData::total_found
Since: 2.0
public total_found ( ) : integer
return integer Number of rows returned by find(), regardless of the 'limit' parameter

total_pages() public method

Fetch the total number of pages, based on total rows found and the last find() limit
Since: 2.3.10
public total_pages ( null | integer $limit = null, null | integer $offset = null, null | integer $total = null ) : integer
$limit null | integer Rows per page
$offset null | integer Offset of rows
$total null | integer Total rows
return integer Number of pages

ui() public method

Generate UI for Data Management
Since: 2.3.10
public ui ( mixed $options = null, boolean $amend = false ) : PodsUI | void
$options mixed Array or String containing Pod or Options to be used
$amend boolean Whether to amend the default UI options or replace entirely
return PodsUI | void UI object or void if custom UI used

valid() public method

Whether this Pod object is valid or not
Since: 2.0
public valid ( ) : boolean
return boolean

view() public method

Since: 2.3.10
public view ( array $fields = null ) : mixed
$fields array (optional) Fields to show in the view, defaults to all fields
return mixed

zebra() public method

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

Property Details

$alt_data public_oe property

public PodsData $alt_data
return PodsData

$api public_oe property

public PodsAPI $api
return PodsAPI

$body_classes public_oe property

public $body_classes

$data public_oe property

public PodsData $data
return PodsData

$datatype public_oe property

public $datatype

$datatype_id public_oe property

public $datatype_id

$deprecated public_oe property

public $deprecated

$detail_page public_oe property

public string $detail_page
return string

$display_errors public_oe property

public bool $display_errors
return boolean

$fields public_oe property

public array $fields
return array

$filters public_oe property

public array $filters
return array

$id public_oe property

public int $id
return integer

$limit public_oe property

public int $limit
return integer

$meta public_oe property

public $meta

$meta_extra public_oe property

public $meta_extra

$meta_properties public_oe property

public $meta_properties

$offset public_oe property

public int $offset
return integer

$page public_oe property

public int|mixed $page
return integer | mixed

$page_template public_oe property

SEO related vars for Pod Pages
public $page_template

$page_var public_oe property

public string $page_var
return string

$pagination public_oe property

public bool $pagination
return boolean

$params public_oe property

public array $params
return array

$pod public_oe property

public string $pod
return string

$pod_data public_oe property

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

$pod_id public_oe property

public int $pod_id
return integer

$row public_oe property

Current pod item array
public $row

$row_override public_oe property

Override pod item array
public $row_override

$rows public_oe property

Array of pod item arrays
public $rows

$search_mode public_oe property

public string $search_mode
return string

$search_var public_oe property

public string $search_var
return string

$sql public_oe property

Last SQL query used by a find()
public $sql

$total public_oe property

public int $total
return integer

$total_found public_oe property

public int $total_found
return integer

$ui public_oe property

public array $ui
return array